Skip to content

Commit 2c26aa5

Browse files
authored
remove the unnecessary legacy Module parameter to integrateWasmJS. this made debugging some startup issues harder (as the outside Module could be erroneously replaced, but not the one captured as the parameter. also add a specific check in ASSERTIONS mode for such erroneous replacing of Module (#5595)
1 parent c722782 commit 2c26aa5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/preamble.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ var cyberDWARFFile = '{{{ BUNDLED_CD_DEBUG_FILE }}}';
20882088
#endif
20892089

20902090
#if BINARYEN
2091-
function integrateWasmJS(Module) {
2091+
function integrateWasmJS() {
20922092
// wasm.js has several methods for creating the compiled code module here:
20932093
// * 'native-wasm' : use native WebAssembly support in the browser
20942094
// * 'interpret-s-expr': load s-expression code from a .wast and interpret
@@ -2310,11 +2310,21 @@ function integrateWasmJS(Module) {
23102310
#if BINARYEN_ASYNC_COMPILATION
23112311
#if RUNTIME_LOGGING
23122312
Module['printErr']('asynchronously preparing wasm');
2313+
#endif
2314+
#if ASSERTIONS
2315+
// Async compilation can be confusing when an error on the page overwrites Module
2316+
// (for example, if the order of elements is wrong, and the one defining Module is
2317+
// later), so we save Module and check it later.
2318+
var trueModule = Module;
23132319
#endif
23142320
getBinaryPromise().then(function(binary) {
23152321
return WebAssembly.instantiate(binary, info)
23162322
}).then(function(output) {
23172323
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
2324+
#if ASSERTIONS
2325+
assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
2326+
trueModule = null;
2327+
#endif
23182328
receiveInstance(output['instance']);
23192329
}).catch(function(reason) {
23202330
Module['printErr']('failed to asynchronously prepare wasm: ' + reason);
@@ -2527,7 +2537,7 @@ function integrateWasmJS(Module) {
25272537
var methodHandler = Module['asm']; // note our method handler, as we may modify Module['asm'] later
25282538
}
25292539

2530-
integrateWasmJS(Module);
2540+
integrateWasmJS();
25312541
#endif
25322542

25332543
// === Body ===

0 commit comments

Comments
 (0)