Skip to content

Make 'instantiateWasm' callback resolve the result return from 'recei… #23781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,7 @@ function getWasmImports() {
try {
#endif
Module['instantiateWasm'](info, (mod, inst) => {
receiveInstance(mod, inst);
resolve(mod.exports);
resolve(receiveInstance(mod, inst));
});
#if ASSERTIONS
} catch(e) {
Expand Down
11 changes: 10 additions & 1 deletion test/test_manual_wasm_instantiate.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
// found in the LICENSE file.

#include <assert.h>
#include <stdio.h>
#include <emscripten.h>
#include <emscripten/em_asm.h>
#include <stdio.h>

EM_ASYNC_JS(int, getResult, (), {
return Module.testWasmInstantiationSucceeded;
});

int main() {
printf("in main\n");
#ifdef ASYNCIFY_ENABLED
int result = getResult();
#else
int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;});
#endif
assert(result);
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes in this file necessary? It looks like you could revert this file probably.

}
3 changes: 2 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -15826,7 +15826,8 @@ def test_instantiate_wasm(self):
});
return {}; // Compiling asynchronously, no exports.
}''')
self.do_runf('test_manual_wasm_instantiate.c', emcc_args=['--pre-js=pre.js'])
# Test with ASYNCIFY here to ensure that that wasmExports gets set to the wrapped version of the wasm exports.
self.do_runf(test_file('test_manual_wasm_instantiate.c'),emcc_args=['--pre-js=pre.js','-sASYNCIFY','-DASYNCIFY_ENABLED'])

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