You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In MODULARIZE mode avoid modifying the incoming moduleArg. NFC (#21775)
This avoids leaking of the partially constructed module and means
that only way to get access the module instance is via waiting on the
promise.
Previously we were attaching all our module properties to the incoming
object, but not, as far as I can tell for any good reason.
In case anybody was actually depending on this, inject thunks into the
moduleArg that abort on access with an actionable error.
// In MODULARIZE mode we wrap the generated code in a factory function
2
+
// and return either the Module itself, or a promise of the module.
3
+
//
4
+
// We assign to the `moduleRtn` global here and configure closure to see
5
+
// this as and extern so it won't get minified.
6
+
7
+
#if WASM_ASYNC_COMPILATION
8
+
9
+
#if USE_READY_PROMISE
10
+
moduleRtn=readyPromise;
11
+
#else
12
+
moduleRtn={};
13
+
#endif
14
+
15
+
#else // WASM_ASYNC_COMPILATION
16
+
17
+
moduleRtn=Module;
18
+
19
+
#endif // WASM_ASYNC_COMPILATION
20
+
21
+
#if ASSERTIONS
22
+
// Assertion for attempting to access module properties on the incoming
23
+
// moduleArg. In the past we used this object as the prototype of the module
24
+
// and assigned properties to it, but now we return a distinct object. This
25
+
// keeps the instance private until it is ready (i.e the promise has been
26
+
// resolved).
27
+
for(constpropofObject.keys(Module)){
28
+
if(!(propinmoduleArg)){
29
+
Object.defineProperty(moduleArg,prop,{
30
+
configurable: true,
31
+
get(){
32
+
#if WASM_ASYNC_COMPILATION
33
+
abort(`Access to module property ('${prop}') is no longer possible via the incoming module contructor argument; Instead, use the result of the module promise.`)
34
+
#else
35
+
abort(`Access to module property ('${prop}') is no longer possible via the module input argument; Instead, use the module constructor return value.`)
expected = "Aborted(Access to module property ('_foo') is no longer possible via the incoming module contructor argument; Instead, use the result of the module promise"
0 commit comments