From feabf264e04a85e579a11fa3991423895e074d78 Mon Sep 17 00:00:00 2001 From: gogogoghost Date: Thu, 27 Feb 2025 16:35:08 +0800 Subject: [PATCH 1/9] Make 'instantiateWasm' callback resolve the result return from 'receiveInstance'. --- src/preamble.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 4d516dab9d9a1..82e1388cd08cd 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -990,8 +990,7 @@ function getWasmImports() { try { #endif Module['instantiateWasm'](info, (mod, inst) => { - receiveInstance(mod, inst); - resolve(mod.exports); + resolve(receiveInstance(mod, inst)); }); #if ASSERTIONS } catch(e) { From 532dff315452c50fe3d339c1b7af59cb7dd2889c Mon Sep 17 00:00:00 2001 From: gogogoghost Date: Fri, 28 Feb 2025 12:09:38 +0800 Subject: [PATCH 2/9] Update 'test_instantiate_wasm' to cover when ASYNCIFY and EXPORT_ES6 enabled --- test/test_manual_wasm_instantiate.c | 11 ++++++++--- test/test_other.py | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/test_manual_wasm_instantiate.c b/test/test_manual_wasm_instantiate.c index ccb8239743cd7..a2d7f5c870776 100644 --- a/test/test_manual_wasm_instantiate.c +++ b/test/test_manual_wasm_instantiate.c @@ -6,10 +6,15 @@ #include #include #include +#include + +EM_ASYNC_JS(int, getResult, (), { + return Module.testWasmInstantiationSucceeded; +}); int main() { - printf("in main\n"); - int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;}); - assert(result); + printf("main: before getResult\n"); + int result = getResult(); + printf("testWasmInstantiationSucceeded: %d\n",result); return 0; } diff --git a/test/test_other.py b/test/test_other.py index 4aaa0b964e5fd..a0baf7e1d0320 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15679,7 +15679,12 @@ def test_instantiate_wasm(self): }); return {}; // Compiling asynchronously, no exports. }''') - self.do_runf('test_manual_wasm_instantiate.c', emcc_args=['--pre-js=pre.js']) + self.run_process([EMCC, test_file('test_manual_wasm_instantiate.c'), '--pre-js=pre.js','-sASYNCIFY','-sEXPORT_ES6=1','-o','manual_init_module.mjs']) + create_file('manual_init.mjs', ''' + import {default as moduleLoader} from "./manual_init_module.mjs"; + await moduleLoader(); + ''') + self.assertContained('testWasmInstantiationSucceeded: 1', self.run_js('manual_init.mjs')) def test_late_module_api_assignment(self): # When sync instantiation is used (or when async/await is used in MODULARIZE mode) certain From 4ddca57fc6d930df8dfdf7568acfa822ea2b77a8 Mon Sep 17 00:00:00 2001 From: Jax Yang Date: Sat, 1 Mar 2025 15:26:30 +0800 Subject: [PATCH 3/9] Remove '-sEXPORT_ES6' from 'test_instantiate_wasm' and add a comment --- test/test_other.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index f1e3930025f89..a2d2aaaf159e5 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15688,12 +15688,9 @@ def test_instantiate_wasm(self): }); return {}; // Compiling asynchronously, no exports. }''') - self.run_process([EMCC, test_file('test_manual_wasm_instantiate.c'), '--pre-js=pre.js','-sASYNCIFY','-sEXPORT_ES6=1','-o','manual_init_module.mjs']) - create_file('manual_init.mjs', ''' - import {default as moduleLoader} from "./manual_init_module.mjs"; - await moduleLoader(); - ''') - self.assertContained('testWasmInstantiationSucceeded: 1', self.run_js('manual_init.mjs')) + # Test with ASYNCIFY here to ensure that that wasmExports gets set to the wrapped version of the wasm exports. + self.run_process([EMCC, test_file('test_manual_wasm_instantiate.c'), '--pre-js=pre.js','--extern-post-js', test_file('modularize_post_js.js'),'-sASYNCIFY','-o','manual_init_module.mjs']) + self.assertContained('testWasmInstantiationSucceeded: 1', self.run_js('manual_init_module.mjs')) def test_late_module_api_assignment(self): # When sync instantiation is used (or when async/await is used in MODULARIZE mode) certain From fe1b7910f58e0186b2042b9ded606fcdb482e07f Mon Sep 17 00:00:00 2001 From: Jax Yang Date: Sun, 2 Mar 2025 19:52:17 +0800 Subject: [PATCH 4/9] Remove unnecessary parameters and calls --- test/test_other.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index a2d2aaaf159e5..4b59f0c2647e0 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15689,8 +15689,7 @@ def test_instantiate_wasm(self): return {}; // Compiling asynchronously, no exports. }''') # Test with ASYNCIFY here to ensure that that wasmExports gets set to the wrapped version of the wasm exports. - self.run_process([EMCC, test_file('test_manual_wasm_instantiate.c'), '--pre-js=pre.js','--extern-post-js', test_file('modularize_post_js.js'),'-sASYNCIFY','-o','manual_init_module.mjs']) - self.assertContained('testWasmInstantiationSucceeded: 1', self.run_js('manual_init_module.mjs')) + self.do_runf(test_file('test_manual_wasm_instantiate.c'),'testWasmInstantiationSucceeded: 1',emcc_args=['--pre-js=pre.js','-sASYNCIFY']) def test_late_module_api_assignment(self): # When sync instantiation is used (or when async/await is used in MODULARIZE mode) certain From a73404f774e3fd361feb33c4c35ee42e2c679031 Mon Sep 17 00:00:00 2001 From: Jax Yang Date: Sun, 2 Mar 2025 19:57:34 +0800 Subject: [PATCH 5/9] Remove unnecessary output check --- test/test_manual_wasm_instantiate.c | 8 ++++---- test/test_other.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_manual_wasm_instantiate.c b/test/test_manual_wasm_instantiate.c index a2d7f5c870776..bb0c687e90b47 100644 --- a/test/test_manual_wasm_instantiate.c +++ b/test/test_manual_wasm_instantiate.c @@ -4,17 +4,17 @@ // found in the LICENSE file. #include -#include -#include #include +#include +#include EM_ASYNC_JS(int, getResult, (), { return Module.testWasmInstantiationSucceeded; }); int main() { - printf("main: before getResult\n"); + printf("in main\n"); int result = getResult(); - printf("testWasmInstantiationSucceeded: %d\n",result); + assert(result); return 0; } diff --git a/test/test_other.py b/test/test_other.py index 4b59f0c2647e0..a8255c003262c 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15689,7 +15689,7 @@ def test_instantiate_wasm(self): return {}; // Compiling asynchronously, no exports. }''') # 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'),'testWasmInstantiationSucceeded: 1',emcc_args=['--pre-js=pre.js','-sASYNCIFY']) + self.do_runf(test_file('test_manual_wasm_instantiate.c'),emcc_args=['--pre-js=pre.js','-sASYNCIFY']) def test_late_module_api_assignment(self): # When sync instantiation is used (or when async/await is used in MODULARIZE mode) certain From c76d9340daacfb92a1deb09bb74c60b4d56defd7 Mon Sep 17 00:00:00 2001 From: gogogoghost Date: Tue, 8 Apr 2025 11:00:34 +0800 Subject: [PATCH 6/9] Fix test browser.test_manual_wasm_instantiate --- test/test_browser.py | 4 ++-- test/test_manual_wasm_instantiate.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_browser.py b/test/test_browser.py index 1b599c92e942b..c16da47d47b50 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4227,9 +4227,9 @@ def test_async_compile(self, opts, returncode): @also_with_asan def test_manual_wasm_instantiate(self): self.set_setting('EXIT_RUNTIME') - self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js'], reporting=Reporting.JS_ONLY) + self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js','-sASYNCIFY'], reporting=Reporting.FULL) shutil.copy(test_file('test_manual_wasm_instantiate.html'), '.') - self.run_browser('test_manual_wasm_instantiate.html', '/report_result?exit:0') + self.run_browser('test_manual_wasm_instantiate.html', '/report_result?1') 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 bb0c687e90b47..b5249946c4c40 100644 --- a/test/test_manual_wasm_instantiate.c +++ b/test/test_manual_wasm_instantiate.c @@ -15,6 +15,10 @@ EM_ASYNC_JS(int, getResult, (), { int main() { printf("in main\n"); int result = getResult(); +#ifdef REPORT_RESULT + REPORT_RESULT(result); +#else assert(result); +#endif return 0; } From 698f5acd1a242735ee6c22291a8336638ed26ed0 Mon Sep 17 00:00:00 2001 From: gogogoghost Date: Tue, 8 Apr 2025 11:04:15 +0800 Subject: [PATCH 7/9] Remove useless parameter --- test/test_browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_browser.py b/test/test_browser.py index c16da47d47b50..cfc3651fb2d8f 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4227,7 +4227,7 @@ def test_async_compile(self, opts, returncode): @also_with_asan def test_manual_wasm_instantiate(self): self.set_setting('EXIT_RUNTIME') - self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js','-sASYNCIFY'], reporting=Reporting.FULL) + self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js','-sASYNCIFY']) shutil.copy(test_file('test_manual_wasm_instantiate.html'), '.') self.run_browser('test_manual_wasm_instantiate.html', '/report_result?1') From 3c56f4fc512c588e48633629ad9f0fd7de9e6f49 Mon Sep 17 00:00:00 2001 From: gogogoghost Date: Thu, 10 Apr 2025 11:30:00 +0800 Subject: [PATCH 8/9] Restore test browser.test_manual_wasm_instantiate and allow test_manual_wasm_instantiate.c to distinguish whether in ASYNCIFY --- test/test_browser.py | 4 ++-- test/test_manual_wasm_instantiate.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_browser.py b/test/test_browser.py index cfc3651fb2d8f..1b599c92e942b 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4227,9 +4227,9 @@ def test_async_compile(self, opts, returncode): @also_with_asan def test_manual_wasm_instantiate(self): self.set_setting('EXIT_RUNTIME') - self.compile_btest('test_manual_wasm_instantiate.c', ['-o', 'manual_wasm_instantiate.js','-sASYNCIFY']) + 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 b5249946c4c40..fe661d7e6277e 100644 --- a/test/test_manual_wasm_instantiate.c +++ b/test/test_manual_wasm_instantiate.c @@ -14,11 +14,11 @@ EM_ASYNC_JS(int, getResult, (), { int main() { printf("in main\n"); +#ifdef ASYNCIFY int result = getResult(); -#ifdef REPORT_RESULT - REPORT_RESULT(result); #else - assert(result); + int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;}); #endif + assert(result); return 0; } From e12cf37918bd658f340d87f2002721f3368c3bd4 Mon Sep 17 00:00:00 2001 From: gogogoghost Date: Thu, 10 Apr 2025 11:41:23 +0800 Subject: [PATCH 9/9] Add -DASYNCIFY_ENABLED to distinguish ASYNCIFY --- test/test_manual_wasm_instantiate.c | 2 +- test/test_other.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_manual_wasm_instantiate.c b/test/test_manual_wasm_instantiate.c index fe661d7e6277e..7bd10f8670ef1 100644 --- a/test/test_manual_wasm_instantiate.c +++ b/test/test_manual_wasm_instantiate.c @@ -14,7 +14,7 @@ EM_ASYNC_JS(int, getResult, (), { int main() { printf("in main\n"); -#ifdef ASYNCIFY +#ifdef ASYNCIFY_ENABLED int result = getResult(); #else int result = EM_ASM_INT({return Module.testWasmInstantiationSucceeded;}); diff --git a/test/test_other.py b/test/test_other.py index b702e8d9982fc..91829259f0642 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15827,7 +15827,7 @@ def test_instantiate_wasm(self): return {}; // Compiling asynchronously, no exports. }''') # 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']) + 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