From 467de0ce891256c076aacfb672d2e8619f7188c4 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Tue, 11 Mar 2025 09:38:53 -0700 Subject: [PATCH] Support blob URLs on ES6 with USE_ES6_IMPORT_META enabled Per the discussion in #23769, implement this policy: - If mainScriptUrlOrBlob is set, create the worker as in the old non-use-import-meta case - Otherwise, use import.meta.url --- src/lib/libpthread.js | 16 ++++++++++------ test/third_party/googletest | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/libpthread.js b/src/lib/libpthread.js index badc551048420..9457ff807d29a 100644 --- a/src/lib/libpthread.js +++ b/src/lib/libpthread.js @@ -424,12 +424,16 @@ var LibraryPThread = { worker = new Worker(p.createScriptURL('ignored'), {{{ 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 - // the first case in their bundling step. The latter ends up producing an invalid - // URL to import from the server (e.g., for webpack the file:// path). - // See https://github.com/webpack/webpack/issues/12638 - worker = new Worker(new URL('{{{ TARGET_JS_NAME }}}', import.meta.url), {{{ pthreadWorkerOptions }}}); +#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 + worker = new Worker(import.meta.url, {{{ pthreadWorkerOptions }}}); #else // EXPORT_ES6 var pthreadMainJs = _scriptName; #if expectToReceiveOnModule('mainScriptUrlOrBlob') 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