Skip to content

Avoid using WasmOffsetConverter when Module.instantiateWasm #13425

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 4 commits into from
Feb 8, 2021
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
18 changes: 18 additions & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,24 @@ function createWasm() {
var exports = Module['instantiateWasm'](info, receiveInstance);
#if ASYNCIFY
exports = Asyncify.instrumentWasmExports(exports);
#endif
#if USE_OFFSET_CONVERTER
{{{
runOnMainThread(`
// We have no way to create an OffsetConverter in this code path since
// we have no access to the wasm binary (only the user does). Instead,
// create a fake one that reports we cannot identify functions from
// their binary offsets.
// Note that we only do this on the main thread, as the workers
// receive the OffsetConverter data from there.
wasmOffsetConverter = {
getName: function() {
return 'unknown-due-to-instantiateWasm';
}
};
removeRunDependency('offset-converter');
`)
}}}
#endif
return exports;
} catch(e) {
Expand Down
8 changes: 6 additions & 2 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4155,8 +4155,12 @@ def test_binaryen_async(self):
self.btest_exit('binaryen_async.c', expected=1, args=common_args)

# Test that implementing Module.instantiateWasm() callback works.
def test_manual_wasm_instantiate(self):
self.compile_btest([path_from_root('tests/manual_wasm_instantiate.cpp'), '-o', 'manual_wasm_instantiate.js', '-s', 'BINARYEN'])
@parameterized({
'': ([],),
'asan': (['-fsanitize=address', '-s', 'INITIAL_MEMORY=128MB'],)
})
def test_manual_wasm_instantiate(self, args=[]):
self.compile_btest([path_from_root('tests/manual_wasm_instantiate.cpp'), '-o', 'manual_wasm_instantiate.js'] + args)
shutil.copyfile(path_from_root('tests', 'manual_wasm_instantiate.html'), 'manual_wasm_instantiate.html')
self.run_browser('manual_wasm_instantiate.html', 'wasm instantiation succeeded', '/report_result?1')

Expand Down