Skip to content

Commit 1e1251a

Browse files
committed
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
1 parent acb0442 commit 1e1251a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/lib/libpthread.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,16 @@ var LibraryPThread = {
424424
worker = new Worker(p.createScriptURL('ignored'), {{{ pthreadWorkerOptions }}});
425425
} else
426426
#endif
427-
// We need to generate the URL with import.meta.url as the base URL of the JS file
428-
// instead of just using new URL(import.meta.url) because bundler's only recognize
429-
// the first case in their bundling step. The latter ends up producing an invalid
430-
// URL to import from the server (e.g., for webpack the file:// path).
431-
// See https://github.com/webpack/webpack/issues/12638
432-
worker = new Worker(new URL('{{{ TARGET_JS_NAME }}}', import.meta.url), {{{ pthreadWorkerOptions }}});
427+
#if expectToReceiveOnModule('mainScriptUrlOrBlob')
428+
if (Module['mainScriptUrlOrBlob']) {
429+
var pthreadMainJs = Module['mainScriptUrlOrBlob'];
430+
if (typeof pthreadMainJs != 'string') {
431+
pthreadMainJs = URL.createObjectURL(pthreadMainJs);
432+
}
433+
worker = new Worker(new URL(pthreadMainJs), {{{ pthreadWorkerOptions }}});
434+
} else
435+
#endif
436+
worker = new Worker(import.meta.url, {{{ pthreadWorkerOptions }}});
433437
#else // EXPORT_ES6
434438
var pthreadMainJs = _scriptName;
435439
#if expectToReceiveOnModule('mainScriptUrlOrBlob')

0 commit comments

Comments
 (0)