Open hershi opened 7 years ago
I assume this is meant to address https://github.com/facebook/prepack/blob/master/src/serializer/modules.js#L90-L100?
Look out for #690
in the code to find the place where this needs to get addressed. #798 might be the key to make this safe, which is what should ultimately happen --- not just issuing a warning.
When initializing dependencies, we evaluate each module in isolation, and if the module evaluation fails, we roll back its changes and continue with the next module in line. This can cause a change of behavior when running the prepacked code compared to the standard code, in case of badly behaved modules that have implicit dependency via global state:
A
writes some dataD
to global stateB
readsD
from the global stateB
does not import moduleA
. The dependency is implicit in readingD
A
is initialized prior to moduleB
in the codeA
will fail due to the fact it writes to global state, hence it will be initialized only when the code is runB
succeeds during prepacking, but becauseA
was not initialized, it might get different contents forD
than it would have ifA
was initializedA
is initialized and writes toD
correctly, but sinceB
was already initialized it is oblivious to that valueTo help detect such cases, we should emit a warning when a module fails to be prepacked because it writes to global state. Note that this won't guarantee that we catch all cases where a module initialization may affect global state (and hence can theoretically affect downstream modules), bit it should cover at least some of these cases.