diff --git a/test/test_browser.py b/test/test_browser.py index 6be85cc3133de..322615db7fbac 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4209,9 +4209,10 @@ def test_async_compile(self, opts, returncode): # Test that implementing Module.instantiateWasm() callback works. @also_with_asan def test_manual_wasm_instantiate(self): - self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js']) + self.set_setting('EXIT_RUNTIME') + self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js'], reporting=Reporting.JS_ONLY) shutil.copy(test_file('test_manual_wasm_instantiate.html'), '.') - self.run_browser('test_manual_wasm_instantiate.html', '/report_result?1') + self.run_browser('test_manual_wasm_instantiate.html', '/report_result?exit:0') def test_wasm_locate_file(self): # Test that it is possible to define "Module.locateFile(foo)" function to locate where worker.js will be loaded from. diff --git a/test/test_manual_wasm_instantiate.c b/test/test_manual_wasm_instantiate.c index f4ac673998245..ccb8239743cd7 100644 --- a/test/test_manual_wasm_instantiate.c +++ b/test/test_manual_wasm_instantiate.c @@ -3,14 +3,13 @@ // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. +#include #include -#include +#include -int main() -{ - printf("OK\n"); -#ifdef REPORT_RESULT - int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;}); - REPORT_RESULT(result); -#endif +int main() { + printf("in main\n"); + int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;}); + assert(result); + return 0; } diff --git a/test/test_other.py b/test/test_other.py index 24638364920ff..a2698620b9284 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15542,3 +15542,18 @@ def test_invalid_export_name(self): create_file('test.c', '__attribute__((export_name("my.func"))) void myfunc() {}') err = self.expect_fail([EMCC, 'test.c']) self.assertContained('emcc: error: invalid export name: my.func', err) + + def test_instantiate_wasm(self): + create_file('pre.js', ''' + Module['instantiateWasm'] = (imports, successCallback) => { + var wasmFile = findWasmBinary(); + getWasmBinary(wasmFile).then((bytes) => { + WebAssembly.instantiate(bytes, imports).then((res) => { + out('wasm instantiation succeeded'); + Module['testWasmInstantiationSucceeded'] = 1; + successCallback(res.instance, res.module); + }); + }); + return {}; // Compiling asynchronously, no exports. + }''') + self.do_runf('test_manual_wasm_instantiate.c', emcc_args=['--pre-js=pre.js'])