Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Invariant: cannot mutate a havoced object #1931

Closed
gaearon opened this issue May 10, 2018 · 0 comments
Closed

Invariant: cannot mutate a havoced object #1931

gaearon opened this issue May 10, 2018 · 0 comments

Comments

@gaearon
Copy link
Contributor

gaearon commented May 10, 2018

Test:

(function() {
  var someAbstract = global.__abstract ? __abstract("function", '(function() {})') : () => {};
  var evaluatePureFunction = global.__evaluatePureFunction || (f => f());
  
  var result;
  evaluatePureFunction(() => {
    function calculate(y) {
      var z = {c: 3, e: 1};
      if (global.__makePartial) __makePartial(z);
      if (global.__makeSimple) __makeSimple(z);  
      someAbstract(z);

      var x = {a: 1, b: 1, c: 1};
      return Object.assign(x, y, z);
    }
    result = calculate({b: 2, d: 1});
  });
  
  global.inspect = function() {
    return JSON.stringify(result);
  };
})();

Invariant:

cannot mutate a havoced object

This is likely a bug in Prepack, not your code. Feel free to open an issue on GitHub.
    at invariant (/Users/gaearon/p/prepack/src/invariant.js:16:15)
    at ObjectValue.set (/Users/gaearon/p/prepack/src/values/ObjectValue.js:153:21)
    at ObjectValue.makeNotPartial (/Users/gaearon/p/prepack/src/values/ObjectValue.js:357:5)
    at NativeFunctionValue.func.defineNativeMethod [as callback] (/Users/gaearon/p/prepack/src/intrinsics/ecma262/Object.js:100:15)
    at NativeFunctionValue.callCallback (/Users/gaearon/p/prepack/src/values/NativeFunctionValue.js:120:12)
    at OrdinaryCallEvaluateBody (/Users/gaearon/p/prepack/src/methods/call.js:299:16)
    at InternalCall (/Users/gaearon/p/prepack/src/methods/function.js:115:39)
    at FunctionImplementation.$Call (/Users/gaearon/p/prepack/src/methods/function.js:857:12)
    at NativeFunctionValue.$Call (/Users/gaearon/p/prepack/src/values/NativeFunctionValue.js:52:24)
    at Call (/Users/gaearon/p/prepack/src/methods/call.js:572:12)

It fails because of this trick which won't work if the object is havoced. But it seems like this is weird code regardless. If $OwnPropertyKeys needs to work on a partial in this case, it would make more sense to me if we disabled this contextually in $OwnPropertyKeys itself instead of temporarily changing the object's status.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant