-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In MODULARIZE mode avoid modifying the incoming moduleArg. NFC
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.
- Loading branch information
Showing
9 changed files
with
72 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// In MODULARIZE mode we wrap the generated code in a factory function | ||
// and return either the Module itself, or a promise of the module. | ||
// | ||
// We assign to the `moduleRtn` global here and configure closure to see | ||
// this as and extern so it won't get minified. | ||
|
||
#if WASM_ASYNC_COMPILATION | ||
|
||
#if USE_READY_PROMISE | ||
moduleRtn = readyPromise; | ||
#else | ||
moduleRtn = {}; | ||
#endif | ||
|
||
#else // WASM_ASYNC_COMPILATION | ||
|
||
moduleRtn = Module; | ||
|
||
#endif // WASM_ASYNC_COMPILATION | ||
|
||
#if ASSERTIONS | ||
// Assertion for attempting to use access modulue properties on the incoming | ||
// moduleArg. In the past we used this object as the prototype of the module | ||
// and assigned properties to it, but now we return a distinct object. This | ||
// keeps the instance private until it is ready (i.e the promise has been | ||
// resolved). | ||
for (const prop of Object.keys(Module)) { | ||
if (!(prop in moduleArg)) { | ||
Object.defineProperty(moduleArg, prop, { | ||
configurable: true, | ||
get() { | ||
#if WASM_ASYNC_COMPILATION | ||
abort(`Access to module property ('${prop}') is no longer possible via the incoming module contructor argument; Instead, use the result of the module promise.`) | ||
#else | ||
abort(`Access to module property ('${prop}') is no longer possible via the module input argument; Instead, use the module constructor return value.`) | ||
#endif | ||
} | ||
}); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
55580 | ||
55579 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
31465 | ||
31464 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
54468 | ||
54467 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters