Skip to content

Commit 0070d12

Browse files
authored
Make 'instantiateWasm' callback resolve the result return from 'recei… (#23781)
In js output content. When ASYNCIFY enabled, wasmExports modified by **Asyncify.instrumentWasmExports**. [source](https://github.com/emscripten-core/emscripten/blob/4b7653130284439898345419f2990c1e14fa60a1/src/preamble.js#L871) But when **Module['instantiateWasm']** used. The **createWasm** function will always resolve the original wasmExports. [source](https://github.com/emscripten-core/emscripten/blob/4b7653130284439898345419f2990c1e14fa60a1/src/preamble.js#L994). It will case crash when async C++ function rewind. So I make **instantiateWasm** callback resolve the result return from **receiveInstance**.
1 parent c2d94c8 commit 0070d12

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/preamble.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,7 @@ function getWasmImports() {
996996
try {
997997
#endif
998998
Module['instantiateWasm'](info, (mod, inst) => {
999-
receiveInstance(mod, inst);
1000-
resolve(mod.exports);
999+
resolve(receiveInstance(mod, inst));
10011000
});
10021001
#if ASSERTIONS
10031002
} catch(e) {

test/test_manual_wasm_instantiate.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44
// found in the LICENSE file.
55

66
#include <assert.h>
7-
#include <stdio.h>
7+
#include <emscripten.h>
88
#include <emscripten/em_asm.h>
9+
#include <stdio.h>
10+
11+
EM_ASYNC_JS(int, getResult, (), {
12+
return Module.testWasmInstantiationSucceeded;
13+
});
914

1015
int main() {
1116
printf("in main\n");
17+
#ifdef ASYNCIFY_ENABLED
18+
int result = getResult();
19+
#else
1220
int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;});
21+
#endif
1322
assert(result);
1423
return 0;
1524
}

test/test_other.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15826,7 +15826,8 @@ def test_instantiate_wasm(self):
1582615826
});
1582715827
return {}; // Compiling asynchronously, no exports.
1582815828
}''')
15829-
self.do_runf('test_manual_wasm_instantiate.c', emcc_args=['--pre-js=pre.js'])
15829+
# Test with ASYNCIFY here to ensure that that wasmExports gets set to the wrapped version of the wasm exports.
15830+
self.do_runf(test_file('test_manual_wasm_instantiate.c'),emcc_args=['--pre-js=pre.js','-sASYNCIFY','-DASYNCIFY_ENABLED'])
1583015831

1583115832
def test_late_module_api_assignment(self):
1583215833
# When sync instantiation is used (or when async/await is used in MODULARIZE mode) certain

0 commit comments

Comments
 (0)