From 8365bcbc1512cb56f60d5d0b4defdd5c0f8f7ad2 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Tue, 11 Mar 2025 10:35:54 -0700 Subject: [PATCH 01/19] Use mainScriptUrlOrBlob if present under EXPORT_ES6 --- src/lib/libpthread.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/libpthread.js b/src/lib/libpthread.js index badc551048420..f6971848d348b 100644 --- a/src/lib/libpthread.js +++ b/src/lib/libpthread.js @@ -423,6 +423,15 @@ var LibraryPThread = { var p = trustedTypes.createPolicy('emscripten#workerPolicy1', { createScriptURL: (ignored) => import.meta.url }); worker = new Worker(p.createScriptURL('ignored'), {{{ pthreadWorkerOptions }}}); } else +#endif +#if expectToReceiveOnModule('mainScriptUrlOrBlob') + if (Module['mainScriptUrlOrBlob']) { + var pthreadMainJs = Module['mainScriptUrlOrBlob']; + if (typeof pthreadMainJs != 'string') { + pthreadMainJs = URL.createObjectURL(pthreadMainJs); + } + worker = new Worker(new URL(pthreadMainJs, import.meta.url), {{{ pthreadWorkerOptions }}}); + } else #endif // We need to generate the URL with import.meta.url as the base URL of the JS file // instead of just using new URL(import.meta.url) because bundler's only recognize From fad235aa5300c1eb1466ca27acae9f66baffb44e Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 09:47:34 -0700 Subject: [PATCH 02/19] Add tests for permutations of mainScriptUrlOrBlob Also fix an overly-complex Worker initialization. --- src/lib/libpthread.js | 2 +- test/pthread/main_js_as_blob_loader_es6.html | 164 +++++++++++++++++++ test/test_browser.py | 17 +- 3 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 test/pthread/main_js_as_blob_loader_es6.html diff --git a/src/lib/libpthread.js b/src/lib/libpthread.js index f6971848d348b..765c052a2f575 100644 --- a/src/lib/libpthread.js +++ b/src/lib/libpthread.js @@ -430,7 +430,7 @@ var LibraryPThread = { if (typeof pthreadMainJs != 'string') { pthreadMainJs = URL.createObjectURL(pthreadMainJs); } - worker = new Worker(new URL(pthreadMainJs, import.meta.url), {{{ pthreadWorkerOptions }}}); + worker = new Worker(pthreadMainJs, {{{ pthreadWorkerOptions }}}); } else #endif // We need to generate the URL with import.meta.url as the base URL of the JS file diff --git a/test/pthread/main_js_as_blob_loader_es6.html b/test/pthread/main_js_as_blob_loader_es6.html new file mode 100644 index 0000000000000..ddf970a5afcb1 --- /dev/null +++ b/test/pthread/main_js_as_blob_loader_es6.html @@ -0,0 +1,164 @@ + + + + + + Emscripten-Generated Code + + + +
+
emscripten
+
Downloading...
+
+ +
+
+ +
+
+
+ Resize canvas + Lock/hide mouse pointer +     + +
+ +
+ +
+ + + + + diff --git a/test/test_browser.py b/test/test_browser.py index 8dbfe4e5221ca..e66f3b77f9643 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4758,15 +4758,26 @@ def test_pthread_reltime(self): # Tests that it is possible to load the main .js file of the application manually via a Blob URL, # and still use pthreads. - def test_load_js_from_blob_with_pthreads(self): + @parameterized({ + 'blob': ('main_js_as_blob_loader.html',False), + 'url': ('main_js_as_url_loader.html',False), + 'blob_es6': ('main_js_as_blob_loader_es6.html',True), + 'url_es6': ('main_js_as_url_loader_es6.html',True), + }) + def test_load_js_from_blob_with_pthreads(self, which_html, es6): # TODO: enable this with wasm, currently pthreads/atomics have limitations self.set_setting('EXIT_RUNTIME') + js_name = 'hello_thread_with_blob_url.js' + if es6: + self.emcc_args += ['-sEXPORT_ES6'] + js_name = 'hello_thread_with_blob_url.mjs' self.compile_btest('pthread/hello_thread.c', ['-pthread', '-o', 'out.js'], reporting=Reporting.JS_ONLY) # Now run the test with the JS file renamed and with its content # stored in Module['mainScriptUrlOrBlob']. - shutil.move('out.js', 'hello_thread_with_blob_url.js') - shutil.copy(test_file('pthread/main_js_as_blob_loader.html'), 'hello_thread_with_blob_url.html') + + shutil.move('out.js', js_name) + shutil.copy(test_file('pthread/%s' % which_html), 'hello_thread_with_blob_url.html') self.run_browser('hello_thread_with_blob_url.html', '/report_result?exit:0') # Tests that SINGLE_FILE works as intended in generated HTML (with and without Worker) From e223b2e4ab20e6fabe6292d77f68769167a779d7 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 09:55:19 -0700 Subject: [PATCH 03/19] add missing files, whitespace fixes --- test/common.py | 2 +- test/pthread/main_js_as_url_loader.html | 160 ++++++++++++++++++++ test/pthread/main_js_as_url_loader_es6.html | 158 +++++++++++++++++++ test/test_browser.py | 27 +++- test/third_party/googletest | 2 +- 5 files changed, 342 insertions(+), 7 deletions(-) create mode 100644 test/pthread/main_js_as_url_loader.html create mode 100644 test/pthread/main_js_as_url_loader_es6.html diff --git a/test/common.py b/test/common.py index a7f20983ae950..2e3ba7554def2 100644 --- a/test/common.py +++ b/test/common.py @@ -2301,7 +2301,7 @@ def is_browser_test(self): def assert_out_queue_empty(self, who): if not self.harness_out_queue.empty(): while not self.harness_out_queue.empty(): - self.harness_out_queue.get() + print(self.harness_out_queue.get()) raise Exception('excessive responses from %s' % who) # @param extra_tries: how many more times to try this test, if it fails. browser tests have diff --git a/test/pthread/main_js_as_url_loader.html b/test/pthread/main_js_as_url_loader.html new file mode 100644 index 0000000000000..61ec3873cccc5 --- /dev/null +++ b/test/pthread/main_js_as_url_loader.html @@ -0,0 +1,160 @@ + + + + + + Emscripten-Generated Code + + + +
+
emscripten
+
Downloading...
+
+ +
+
+ +
+
+
+ Resize canvas + Lock/hide mouse pointer +     + +
+ +
+ +
+ + + + + diff --git a/test/pthread/main_js_as_url_loader_es6.html b/test/pthread/main_js_as_url_loader_es6.html new file mode 100644 index 0000000000000..127f32a8af26b --- /dev/null +++ b/test/pthread/main_js_as_url_loader_es6.html @@ -0,0 +1,158 @@ + + + + + + Emscripten-Generated Code + + + +
+
emscripten
+
Downloading...
+
+ +
+
+ +
+
+
+ Resize canvas + Lock/hide mouse pointer +     + +
+ +
+ +
+ + + + + diff --git a/test/test_browser.py b/test/test_browser.py index e66f3b77f9643..a11e8cf0c079c 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4775,7 +4775,7 @@ def test_load_js_from_blob_with_pthreads(self, which_html, es6): # Now run the test with the JS file renamed and with its content # stored in Module['mainScriptUrlOrBlob']. - + shutil.move('out.js', js_name) shutil.copy(test_file('pthread/%s' % which_html), 'hello_thread_with_blob_url.html') self.run_browser('hello_thread_with_blob_url.html', '/report_result?exit:0') @@ -5547,19 +5547,30 @@ def test_error_reporting(self): @also_with_threads @parameterized({ - '': (False,), - 'es6': (True,), + '': (False,False), + 'blob': (False,True), + 'es6': (True,False), + 'es6_blob': (True,True) }) - def test_webpack(self, es6): - if es6: + def test_webpack(self, es6, useblob): + if es6 and useblob: + copytree(test_file('webpack_es6_with_blob'), '.') + self.emcc_args += ['-sEXPORT_ES6', '-pthread', '-sPTHREAD_POOL_SIZE=1'] + outfile = 'src/hello.mjs' + elif es6: copytree(test_file('webpack_es6'), '.') self.emcc_args += ['-sEXPORT_ES6', '-pthread', '-sPTHREAD_POOL_SIZE=1'] outfile = 'src/hello.mjs' + elif useblob: + copytree(test_file('webpack_with_blob'), '.') + self.emcc_args += ['-pthread', '-sPTHREAD_POOL_SIZE=1'] + outfile = 'src/hello.js' else: copytree(test_file('webpack'), '.') outfile = 'src/hello.js' self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web,worker', '-o', outfile]) self.run_process(shared.get_npm_cmd('webpack') + ['--mode=development', '--no-devtool']) + shutil.copy(outfile, 'dist/') shutil.copy('src/hello.wasm', 'dist/') self.run_browser('dist/index.html', '/report_result?exit:0') @@ -5570,6 +5581,12 @@ def test_vite(self): self.run_process(shared.get_npm_cmd('vite') + ['build']) self.run_browser('dist/index.html', '/report_result?exit:0') + def test_vite_with_blob(self): + copytree(test_file('vite_with_blob'), '.') + self.compile_btest('hello_world.c', ['-sEXPORT_ES6', '-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web,worker', '-sPTHREAD_POOL_SIZE=1', '-pthread', '-sPROXY_TO_PTHREAD', '-o', 'public/hello.mjs']) + self.run_process(shared.get_npm_cmd('vite') + ['build']) + self.run_browser('dist/index.html', '/report_result?exit=0') + @also_with_threads def test_rollup(self): copytree(test_file('rollup'), '.') diff --git a/test/third_party/googletest b/test/third_party/googletest index b514bdc898e29..4fb7039fda3f6 160000 --- a/test/third_party/googletest +++ b/test/third_party/googletest @@ -1 +1 @@ -Subproject commit b514bdc898e2951020cbdca1304b75f5950d1f59 +Subproject commit 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a From 5787e9d7abe4002136332e5b933f44b51c8cffc9 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 10:21:32 -0700 Subject: [PATCH 04/19] Remove mistakenly committed changes --- test/test_browser.py | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/test/test_browser.py b/test/test_browser.py index a11e8cf0c079c..9b69680091341 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5547,30 +5547,19 @@ def test_error_reporting(self): @also_with_threads @parameterized({ - '': (False,False), - 'blob': (False,True), - 'es6': (True,False), - 'es6_blob': (True,True) - }) - def test_webpack(self, es6, useblob): - if es6 and useblob: - copytree(test_file('webpack_es6_with_blob'), '.') - self.emcc_args += ['-sEXPORT_ES6', '-pthread', '-sPTHREAD_POOL_SIZE=1'] - outfile = 'src/hello.mjs' - elif es6: + '': (False,), + 'es6': (True) + }) + def test_webpack(self, es6): + if es6: copytree(test_file('webpack_es6'), '.') self.emcc_args += ['-sEXPORT_ES6', '-pthread', '-sPTHREAD_POOL_SIZE=1'] outfile = 'src/hello.mjs' - elif useblob: - copytree(test_file('webpack_with_blob'), '.') - self.emcc_args += ['-pthread', '-sPTHREAD_POOL_SIZE=1'] - outfile = 'src/hello.js' else: copytree(test_file('webpack'), '.') outfile = 'src/hello.js' self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web,worker', '-o', outfile]) self.run_process(shared.get_npm_cmd('webpack') + ['--mode=development', '--no-devtool']) - shutil.copy(outfile, 'dist/') shutil.copy('src/hello.wasm', 'dist/') self.run_browser('dist/index.html', '/report_result?exit:0') @@ -5581,12 +5570,6 @@ def test_vite(self): self.run_process(shared.get_npm_cmd('vite') + ['build']) self.run_browser('dist/index.html', '/report_result?exit:0') - def test_vite_with_blob(self): - copytree(test_file('vite_with_blob'), '.') - self.compile_btest('hello_world.c', ['-sEXPORT_ES6', '-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web,worker', '-sPTHREAD_POOL_SIZE=1', '-pthread', '-sPROXY_TO_PTHREAD', '-o', 'public/hello.mjs']) - self.run_process(shared.get_npm_cmd('vite') + ['build']) - self.run_browser('dist/index.html', '/report_result?exit=0') - @also_with_threads def test_rollup(self): copytree(test_file('rollup'), '.') From d6f08108b369dc2b3f715fa93330826c8356f0ff Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 10:22:29 -0700 Subject: [PATCH 05/19] And another stray change --- test/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common.py b/test/common.py index 2e3ba7554def2..a7f20983ae950 100644 --- a/test/common.py +++ b/test/common.py @@ -2301,7 +2301,7 @@ def is_browser_test(self): def assert_out_queue_empty(self, who): if not self.harness_out_queue.empty(): while not self.harness_out_queue.empty(): - print(self.harness_out_queue.get()) + self.harness_out_queue.get() raise Exception('excessive responses from %s' % who) # @param extra_tries: how many more times to try this test, if it fails. browser tests have From d9233e5a7e52255b1ea74c66e5002d753e891137 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 10:23:08 -0700 Subject: [PATCH 06/19] missing commas --- 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 9b69680091341..ddbe4d2d4c936 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5548,7 +5548,7 @@ def test_error_reporting(self): @also_with_threads @parameterized({ '': (False,), - 'es6': (True) + 'es6': (True,), }) def test_webpack(self, es6): if es6: From 784bab573e3ee596011a95185cfbafdf374009f2 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 10:24:17 -0700 Subject: [PATCH 07/19] wind googletest dep back too --- test/third_party/googletest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/third_party/googletest b/test/third_party/googletest index 4fb7039fda3f6..b514bdc898e29 160000 --- a/test/third_party/googletest +++ b/test/third_party/googletest @@ -1 +1 @@ -Subproject commit 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a +Subproject commit b514bdc898e2951020cbdca1304b75f5950d1f59 From 7eeaba35844c87777321f6d08b37c78931ad33d7 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 12:33:41 -0700 Subject: [PATCH 08/19] Inline parameterized tests in test definition --- test/pthread/main_js_as_blob_loader.html | 174 ------------------ test/pthread/main_js_as_blob_loader_es6.html | 164 ----------------- test/pthread/main_js_as_url_loader_es6.html | 158 ---------------- ...l_loader.html => main_js_with_loader.html} | 12 +- test/test_browser.py | 54 ++++-- 5 files changed, 46 insertions(+), 516 deletions(-) delete mode 100644 test/pthread/main_js_as_blob_loader.html delete mode 100644 test/pthread/main_js_as_blob_loader_es6.html delete mode 100644 test/pthread/main_js_as_url_loader_es6.html rename test/pthread/{main_js_as_url_loader.html => main_js_with_loader.html} (95%) diff --git a/test/pthread/main_js_as_blob_loader.html b/test/pthread/main_js_as_blob_loader.html deleted file mode 100644 index 2ec93f75ec0ff..0000000000000 --- a/test/pthread/main_js_as_blob_loader.html +++ /dev/null @@ -1,174 +0,0 @@ - - - - - - Emscripten-Generated Code - - - -
-
emscripten
-
Downloading...
-
- -
-
- -
-
-
- Resize canvas - Lock/hide mouse pointer -     - -
- -
- -
- - - - - diff --git a/test/pthread/main_js_as_blob_loader_es6.html b/test/pthread/main_js_as_blob_loader_es6.html deleted file mode 100644 index ddf970a5afcb1..0000000000000 --- a/test/pthread/main_js_as_blob_loader_es6.html +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - Emscripten-Generated Code - - - -
-
emscripten
-
Downloading...
-
- -
-
- -
-
-
- Resize canvas - Lock/hide mouse pointer -     - -
- -
- -
- - - - - diff --git a/test/pthread/main_js_as_url_loader_es6.html b/test/pthread/main_js_as_url_loader_es6.html deleted file mode 100644 index 127f32a8af26b..0000000000000 --- a/test/pthread/main_js_as_url_loader_es6.html +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - Emscripten-Generated Code - - - -
-
emscripten
-
Downloading...
-
- -
-
- -
-
-
- Resize canvas - Lock/hide mouse pointer -     - -
- -
- -
- - - - - diff --git a/test/pthread/main_js_as_url_loader.html b/test/pthread/main_js_with_loader.html similarity index 95% rename from test/pthread/main_js_as_url_loader.html rename to test/pthread/main_js_with_loader.html index 61ec3873cccc5..8b84831ba6b00 100644 --- a/test/pthread/main_js_as_url_loader.html +++ b/test/pthread/main_js_with_loader.html @@ -147,14 +147,8 @@ }; - + + + diff --git a/test/test_browser.py b/test/test_browser.py index ddbe4d2d4c936..3100524197f12 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4756,29 +4756,61 @@ def test_pthread_growth(self, emcc_args): def test_pthread_reltime(self): self.btest_exit('pthread/test_pthread_reltime.cpp', emcc_args=['-pthread', '-sPTHREAD_POOL_SIZE']) - # Tests that it is possible to load the main .js file of the application manually via a Blob URL, + # Tests that it is possible to load the main .js file of the application manually via mainScriptUrlOrBlob, # and still use pthreads. @parameterized({ - 'blob': ('main_js_as_blob_loader.html',False), - 'url': ('main_js_as_url_loader.html',False), - 'blob_es6': ('main_js_as_blob_loader_es6.html',True), - 'url_es6': ('main_js_as_url_loader_es6.html',True), + 'blob': (False, True), + 'url': (False, False), + 'blob_es6': (True, True), + 'url_es6': (True, False), }) - def test_load_js_from_blob_with_pthreads(self, which_html, es6): + def test_pthreads_mainScriptUrlOrBlob(self, es6, use_blob): # TODO: enable this with wasm, currently pthreads/atomics have limitations self.set_setting('EXIT_RUNTIME') - js_name = 'hello_thread_with_blob_url.js' + js_name = 'hello_thread_with_loader.js' + ext = '.js' if es6: + ext = '.mjs' self.emcc_args += ['-sEXPORT_ES6'] - js_name = 'hello_thread_with_blob_url.mjs' + js_name = 'hello_thread_with_loader.mjs' + if es6 and use_blob: + create_file('loader.mjs', ''' + Module['locateFile'] = (path,_prefix) => path; + fetch('hello_thread_with_loader.mjs').then((rsp) => rsp.blob().then((blob) => { + Module['mainScriptUrlOrBlob'] = blob; + import(URL.createObjectURL(blob)).then((fac) => fac.default(Module)) + })); + ''') + elif use_blob: + create_file('loader.js', ''' + Module['locateFile'] = (path,_prefix) => path; + fetch('hello_thread_with_loader.js').then((rsp) => rsp.blob().then((blob) => { + Module['mainScriptUrlOrBlob'] = blob; + var script = document.createElement('script'); + script.src = URL.createObjectURL(blob); + document.body.appendChild(script); + })); + ''') + elif es6: + create_file('loader.mjs', ''' + Module['mainScriptUrlOrBlob'] = 'hello_thread_with_loader.mjs'; + import('./'+Module['mainScriptUrlOrBlob']).then((fac) => fac.default(Module)) + ''') + else: + create_file('loader.js', ''' + var script = document.createElement('script'); + Module['mainScriptUrlOrBlob'] = 'hello_thread_with_loader.js'; + script.src = Module['mainScriptUrlOrBlob']; + document.body.appendChild(script); + ''') + self.compile_btest('pthread/hello_thread.c', ['-pthread', '-o', 'out.js'], reporting=Reporting.JS_ONLY) # Now run the test with the JS file renamed and with its content # stored in Module['mainScriptUrlOrBlob']. - shutil.move('out.js', js_name) - shutil.copy(test_file('pthread/%s' % which_html), 'hello_thread_with_blob_url.html') - self.run_browser('hello_thread_with_blob_url.html', '/report_result?exit:0') + shutil.copy(test_file('pthread/main_js_with_loader.html'), 'hello_thread_with_loader.html') + self.run_browser('hello_thread_with_loader.html', '/report_result?exit:0') # Tests that SINGLE_FILE works as intended in generated HTML (with and without Worker) @also_with_proxying From cff89f7757997739c9a4d9d165a6844ee0410aef Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 12:34:47 -0700 Subject: [PATCH 09/19] rename test --- 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 3100524197f12..e59bbfb3ca9fb 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4764,7 +4764,7 @@ def test_pthread_reltime(self): 'blob_es6': (True, True), 'url_es6': (True, False), }) - def test_pthreads_mainScriptUrlOrBlob(self, es6, use_blob): + def test_mainScriptUrlOrBlob(self, es6, use_blob): # TODO: enable this with wasm, currently pthreads/atomics have limitations self.set_setting('EXIT_RUNTIME') js_name = 'hello_thread_with_loader.js' From ba4ac7048802914976da9a1385b41393deae7926 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 14:45:04 -0700 Subject: [PATCH 10/19] Extend test_other.test_mainScriptUrlOrBlob and refactor tests --- test/pthread/main_js_with_loader.html | 2 -- test/test_browser.py | 22 ++++++---------- test/test_other.py | 38 +++++++++++++++++++-------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/test/pthread/main_js_with_loader.html b/test/pthread/main_js_with_loader.html index 8b84831ba6b00..0112c5e356902 100644 --- a/test/pthread/main_js_with_loader.html +++ b/test/pthread/main_js_with_loader.html @@ -147,8 +147,6 @@ }; - - diff --git a/test/test_browser.py b/test/test_browser.py index e59bbfb3ca9fb..f37fe694cc87c 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4767,37 +4767,31 @@ def test_pthread_reltime(self): def test_mainScriptUrlOrBlob(self, es6, use_blob): # TODO: enable this with wasm, currently pthreads/atomics have limitations self.set_setting('EXIT_RUNTIME') - js_name = 'hello_thread_with_loader.js' - ext = '.js' + js_name = 'hello_thread_with_loader.%s' % ('mjs' if es6 else 'js') if es6: - ext = '.mjs' self.emcc_args += ['-sEXPORT_ES6'] - js_name = 'hello_thread_with_loader.mjs' if es6 and use_blob: create_file('loader.mjs', ''' Module['locateFile'] = (path,_prefix) => path; - fetch('hello_thread_with_loader.mjs').then((rsp) => rsp.blob().then((blob) => { - Module['mainScriptUrlOrBlob'] = blob; - import(URL.createObjectURL(blob)).then((fac) => fac.default(Module)) - })); + let blob = await (await fetch('hello_thread_with_loader.mjs')).blob(); + Module['mainScriptUrlOrBlob'] = blob; + (await import(URL.createObjectURL(blob))).default(Module); ''') elif use_blob: - create_file('loader.js', ''' - Module['locateFile'] = (path,_prefix) => path; - fetch('hello_thread_with_loader.js').then((rsp) => rsp.blob().then((blob) => { + create_file('loader.mjs', ''' + let blob = await (await fetch('hello_thread_with_loader.js')).blob(); Module['mainScriptUrlOrBlob'] = blob; var script = document.createElement('script'); script.src = URL.createObjectURL(blob); document.body.appendChild(script); - })); ''') elif es6: create_file('loader.mjs', ''' Module['mainScriptUrlOrBlob'] = 'hello_thread_with_loader.mjs'; - import('./'+Module['mainScriptUrlOrBlob']).then((fac) => fac.default(Module)) + (await import('./hello_thread_with_loader.mjs')).default(Module); ''') else: - create_file('loader.js', ''' + create_file('loader.mjs', ''' var script = document.createElement('script'); Module['mainScriptUrlOrBlob'] = 'hello_thread_with_loader.js'; script.src = Module['mainScriptUrlOrBlob']; diff --git a/test/test_other.py b/test/test_other.py index 798c1bbadd605..8c5872cd9baca 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15865,15 +15865,31 @@ def test_rollup(self): def test_rlimit(self): self.do_other_test('test_rlimit.c', emcc_args=['-O1']) - def test_mainScriptUrlOrBlob(self): + @parameterized({ + '': (False, False), + 'es6': (True, False), + }) + def test_mainScriptUrlOrBlob(self, es6, use_blob): # Use `foo.js` instead of the current script name when creating new threads - create_file('pre.js', 'Module = { mainScriptUrlOrBlob: "./foo.js" }') - self.run_process([EMCC, test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '--pre-js=pre.js']) - - # First run without foo.js present to verify that the pthread creation fails - err = self.run_js('a.out.js', assert_returncode=NON_ZERO) - self.assertContained('Cannot find module.*foo.js', err, regex=True) - - # Now create foo.js and the program should run as expected. - shutil.copy('a.out.js', 'foo.js') - self.assertContained('hello, world', self.run_js('a.out.js')) + if es6: + self.emcc_args += ['-sEXPORT_ES6'] + create_file('pre.js', '') + create_file('run.mjs', 'import("./foo.mjs").then((fac) => fac.default({mainScriptUrlOrBlob:"./foo.mjs"}))') + binfile = 'a.out.mjs' + real_binfile = 'foo.mjs' + runfile = 'run.mjs' + else: + create_file('pre.js', 'Module = { mainScriptUrlOrBlob: "./foo.js" }') + binfile = 'a.out.js' + real_binfile = 'foo.js' + runfile = binfile + + self.run_process([EMCC, test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '--pre-js=pre.js', '-o', binfile]) + + # First run without foo.{mjs,js} present to verify that the pthread creation fails + err = self.run_js(runfile, assert_returncode=NON_ZERO) + self.assertContained('Cannot find module.*foo', err, regex=True) + + # Now create foo.{mjs,js} and the program should run as expected. + shutil.copy(binfile, real_binfile) + self.assertContained('hello, world', self.run_js(runfile)) From a150871b982ab2819207a088facd491ae8b92f83 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 14:46:22 -0700 Subject: [PATCH 11/19] Remove unnecessary parameterization --- test/test_other.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 8c5872cd9baca..0b1fd11022657 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15866,10 +15866,10 @@ def test_rlimit(self): self.do_other_test('test_rlimit.c', emcc_args=['-O1']) @parameterized({ - '': (False, False), - 'es6': (True, False), + '': (False,), + 'es6': (True,), }) - def test_mainScriptUrlOrBlob(self, es6, use_blob): + def test_mainScriptUrlOrBlob(self, es6): # Use `foo.js` instead of the current script name when creating new threads if es6: self.emcc_args += ['-sEXPORT_ES6'] From 61276435259064a98a2b25f35adb62469264645f Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 14:47:24 -0700 Subject: [PATCH 12/19] Use await in test_other.test_mainScriptUrlOrBlob --- test/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_other.py b/test/test_other.py index 0b1fd11022657..9d326c28bfddb 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15874,7 +15874,7 @@ def test_mainScriptUrlOrBlob(self, es6): if es6: self.emcc_args += ['-sEXPORT_ES6'] create_file('pre.js', '') - create_file('run.mjs', 'import("./foo.mjs").then((fac) => fac.default({mainScriptUrlOrBlob:"./foo.mjs"}))') + create_file('run.mjs', '(await import("./foo.mjs")).default({mainScriptUrlOrBlob:"./foo.mjs"});') binfile = 'a.out.mjs' real_binfile = 'foo.mjs' runfile = 'run.mjs' From f5fa3284af04c303c25fb30af81da949001a9c67 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 14:49:16 -0700 Subject: [PATCH 13/19] whitespace --- test/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_other.py b/test/test_other.py index 9d326c28bfddb..d578aebca1c53 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15889,7 +15889,7 @@ def test_mainScriptUrlOrBlob(self, es6): # First run without foo.{mjs,js} present to verify that the pthread creation fails err = self.run_js(runfile, assert_returncode=NON_ZERO) self.assertContained('Cannot find module.*foo', err, regex=True) - + # Now create foo.{mjs,js} and the program should run as expected. shutil.copy(binfile, real_binfile) self.assertContained('hello, world', self.run_js(runfile)) From b988c128847e6370a7bfa9afaf68a917053ee21c Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 15:55:25 -0700 Subject: [PATCH 14/19] tidy other.test_mainScriptUrlOrBlob Per @sbc100 review, reduce differences across conditions --- test/test_other.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index d578aebca1c53..6bb4791b8eaf7 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15872,24 +15872,16 @@ def test_rlimit(self): def test_mainScriptUrlOrBlob(self, es6): # Use `foo.js` instead of the current script name when creating new threads if es6: - self.emcc_args += ['-sEXPORT_ES6'] - create_file('pre.js', '') - create_file('run.mjs', '(await import("./foo.mjs")).default({mainScriptUrlOrBlob:"./foo.mjs"});') - binfile = 'a.out.mjs' - real_binfile = 'foo.mjs' - runfile = 'run.mjs' - else: - create_file('pre.js', 'Module = { mainScriptUrlOrBlob: "./foo.js" }') - binfile = 'a.out.js' - real_binfile = 'foo.js' - runfile = binfile + self.emcc_args += ['-sEXPORT_ES6', '--extern-post-js', test_file('modularize_post_js.js')] + + create_file('pre.js', 'Module = { mainScriptUrlOrBlob: "./foo.js" }') - self.run_process([EMCC, test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '--pre-js=pre.js', '-o', binfile]) + self.run_process([EMCC, test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '--pre-js=pre.js', '-o', 'a.out.js']) - # First run without foo.{mjs,js} present to verify that the pthread creation fails - err = self.run_js(runfile, assert_returncode=NON_ZERO) + # First run without foo.js present to verify that the pthread creation fails + err = self.run_js('a.out.js', assert_returncode=NON_ZERO) self.assertContained('Cannot find module.*foo', err, regex=True) # Now create foo.{mjs,js} and the program should run as expected. - shutil.copy(binfile, real_binfile) - self.assertContained('hello, world', self.run_js(runfile)) + shutil.copy('a.out.js', 'foo.js') + self.assertContained('hello, world', self.run_js('a.out.js')) From 5e53b888b023e6945ab1575cfc2d8f4e0e6b3b60 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 12 Mar 2025 15:57:22 -0700 Subject: [PATCH 15/19] Make comment, regex better match revised test --- test/test_other.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 6bb4791b8eaf7..3314c23aded3b 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15880,8 +15880,8 @@ def test_mainScriptUrlOrBlob(self, es6): # First run without foo.js present to verify that the pthread creation fails err = self.run_js('a.out.js', assert_returncode=NON_ZERO) - self.assertContained('Cannot find module.*foo', err, regex=True) + self.assertContained('Cannot find module.*foo.js', err, regex=True) - # Now create foo.{mjs,js} and the program should run as expected. + # Now create foo.js and the program should run as expected. shutil.copy('a.out.js', 'foo.js') self.assertContained('hello, world', self.run_js('a.out.js')) From 472313db5fcc79f88d230365e48294bf3cc428fe Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Thu, 13 Mar 2025 12:39:33 -0700 Subject: [PATCH 16/19] Parameterize other.test_mainScriptUrlOrBlob on args instead of bool --- test/test_other.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 3314c23aded3b..9e2b4eca880e3 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15866,17 +15866,14 @@ def test_rlimit(self): self.do_other_test('test_rlimit.c', emcc_args=['-O1']) @parameterized({ - '': (False,), - 'es6': (True,), + '': ([],), + 'es6': (['-sEXPORT_ES6', '--extern-post-js', test_file('modularize_post_js.js')],), }) - def test_mainScriptUrlOrBlob(self, es6): + def test_mainScriptUrlOrBlob(self, args): # Use `foo.js` instead of the current script name when creating new threads - if es6: - self.emcc_args += ['-sEXPORT_ES6', '--extern-post-js', test_file('modularize_post_js.js')] - create_file('pre.js', 'Module = { mainScriptUrlOrBlob: "./foo.js" }') - self.run_process([EMCC, test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '--pre-js=pre.js', '-o', 'a.out.js']) + self.run_process([EMCC, test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '--pre-js=pre.js', '-o', 'a.out.js'] + args) # First run without foo.js present to verify that the pthread creation fails err = self.run_js('a.out.js', assert_returncode=NON_ZERO) From 0d32f1b5912f4c39829fb1dd55043c828bfdca00 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Fri, 14 Mar 2025 12:25:24 -0700 Subject: [PATCH 17/19] Use mjs suffix in test under es6 condition --- test/test_other.py | 28 +++++++++++++++++----------- test/third_party/googletest | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 9e2b4eca880e3..3e85777521d86 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15866,19 +15866,25 @@ def test_rlimit(self): self.do_other_test('test_rlimit.c', emcc_args=['-O1']) @parameterized({ - '': ([],), - 'es6': (['-sEXPORT_ES6', '--extern-post-js', test_file('modularize_post_js.js')],), + '': (False,), + 'es6': (True,), }) - def test_mainScriptUrlOrBlob(self, args): + def test_mainScriptUrlOrBlob(self, es6): + ext = "js" + args = [] + if es6: + ext = "mjs" + args = ['-sEXPORT_ES6', '--extern-post-js', test_file('modularize_post_js.js')] + outfile = ('a.out.%s' % ext) # Use `foo.js` instead of the current script name when creating new threads - create_file('pre.js', 'Module = { mainScriptUrlOrBlob: "./foo.js" }') + create_file('pre.js', 'Module = { mainScriptUrlOrBlob: "./foo.%s" }' % ext) - self.run_process([EMCC, test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '--pre-js=pre.js', '-o', 'a.out.js'] + args) + self.run_process([EMCC, test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '--pre-js=pre.js', '-o', outfile] + args) - # First run without foo.js present to verify that the pthread creation fails - err = self.run_js('a.out.js', assert_returncode=NON_ZERO) - self.assertContained('Cannot find module.*foo.js', err, regex=True) + # First run without foo.[m]js present to verify that the pthread creation fails + err = self.run_js(outfile, assert_returncode=NON_ZERO) + self.assertContained('Cannot find module.*foo\.', err, regex=True) - # Now create foo.js and the program should run as expected. - shutil.copy('a.out.js', 'foo.js') - self.assertContained('hello, world', self.run_js('a.out.js')) + # Now create foo.[m]js and the program should run as expected. + shutil.copy(outfile, ('foo.%s' % ext)) + self.assertContained('hello, world', self.run_js(outfile)) diff --git a/test/third_party/googletest b/test/third_party/googletest index b514bdc898e29..4fb7039fda3f6 160000 --- a/test/third_party/googletest +++ b/test/third_party/googletest @@ -1 +1 @@ -Subproject commit b514bdc898e2951020cbdca1304b75f5950d1f59 +Subproject commit 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a From c68e3069db98f562cb28e5156e85e83df7032765 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Fri, 14 Mar 2025 12:28:05 -0700 Subject: [PATCH 18/19] properly escape dot --- test/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_other.py b/test/test_other.py index 3e85777521d86..1bb2d711738be 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15883,7 +15883,7 @@ def test_mainScriptUrlOrBlob(self, es6): # First run without foo.[m]js present to verify that the pthread creation fails err = self.run_js(outfile, assert_returncode=NON_ZERO) - self.assertContained('Cannot find module.*foo\.', err, regex=True) + self.assertContained('Cannot find module.*foo\\.', err, regex=True) # Now create foo.[m]js and the program should run as expected. shutil.copy(outfile, ('foo.%s' % ext)) From 6b963c8b9ac1d37b5c875b9491a045090f3f37cd Mon Sep 17 00:00:00 2001 From: Joe Osborn Date: Sat, 15 Mar 2025 06:19:44 -0700 Subject: [PATCH 19/19] revert googletest version change --- test/third_party/googletest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/third_party/googletest b/test/third_party/googletest index 4fb7039fda3f6..b514bdc898e29 160000 --- a/test/third_party/googletest +++ b/test/third_party/googletest @@ -1 +1 @@ -Subproject commit 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a +Subproject commit b514bdc898e2951020cbdca1304b75f5950d1f59