facebookarchive / prepack

A JavaScript bundle optimizer.
http://prepack.io
Other
14.22k stars 424 forks source link

Havocing of frozen objects is broken #2073

Open NTillmann opened 6 years ago

NTillmann commented 6 years ago

In the havoc implementation, frozen objects are currently excluded: https://github.com/facebook/prepack/blob/679b7d092e2adcef615004628820c78fa7be728c/src/utils/havoc.js#L172

This is not working as intended, as frozen objects might not be fully rehydrated by the serialized code. The following failing test case illustrates this.

function f(c, g) {
    var o = {};
    o.foo = 42;
    if (c) {
        Object.freeze(o);
        return g(function() { return o.foo; });
    } else {
        o.foo = Date.now();
        Object.freeze(o);
    }
}

Other things to consider:

sebmarkbage commented 6 years ago

One thing to consider here is that React elements should not be considered frozen objects. They are a different category of objects that are considered “frozenish”. They should never emit Object.freeze calls but we still know that they’re immutable.

I think that’s the source of confusion here.