Skip to content

Commit a1cf520

Browse files
committed
Allow capturing the Wasm Module for pthreads also when manually instantiating the Wasm Module.
1 parent 54860f6 commit a1cf520

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/preamble.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -2275,11 +2275,15 @@ function integrateWasmJS() {
22752275
info['env'] = env;
22762276
// handle a generated wasm instance, receiving its exports and
22772277
// performing other necessary setup
2278-
function receiveInstance(instance) {
2278+
function receiveInstance(instance, module) {
22792279
exports = instance.exports;
22802280
if (exports.memory) mergeMemory(exports.memory);
22812281
Module['asm'] = exports;
22822282
Module["usingWasm"] = true;
2283+
#if USE_PTHREADS
2284+
// Keep a reference to the compiled module so we can post it to the workers.
2285+
Module['wasmModule'] = module;
2286+
#endif
22832287
removeRunDependency('wasm-instantiate');
22842288
}
22852289

@@ -2314,11 +2318,7 @@ function integrateWasmJS() {
23142318
assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
23152319
trueModule = null;
23162320
#endif
2317-
#if USE_PTHREADS
2318-
// Keeep a reference to the compiled module so we can post it to the workers.
2319-
Module['wasmModule'] = output['module'];
2320-
#endif
2321-
receiveInstance(output['instance']);
2321+
receiveInstance(output['instance'], output['module']);
23222322
}
23232323
function instantiateArrayBuffer(receiver) {
23242324
getBinaryPromise().then(function(binary) {
@@ -2345,16 +2345,18 @@ function integrateWasmJS() {
23452345
return {}; // no exports yet; we'll fill them in later
23462346
#else
23472347
var instance;
2348+
var module;
23482349
try {
2349-
instance = new WebAssembly.Instance(new WebAssembly.Module(getBinary()), info)
2350+
module = new WebAssembly.Module(getBinary());
2351+
instance = new WebAssembly.Instance(module, info)
23502352
} catch (e) {
23512353
Module['printErr']('failed to compile wasm module: ' + e);
23522354
if (e.toString().indexOf('imported Memory with incompatible size') >= 0) {
23532355
Module['printErr']('Memory size incompatibility issues may be due to changing TOTAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set TOTAL_MEMORY at runtime to something smaller than it was at compile time).');
23542356
}
23552357
return false;
23562358
}
2357-
receiveInstance(instance);
2359+
receiveInstance(instance, module);
23582360
return exports;
23592361
#endif
23602362
}

0 commit comments

Comments
 (0)