Skip to content

Commit d6a1e01

Browse files
authored
Simplify worker creation for TRUSTED_TYPES + ESM. NFC (#23816)
The trustedTypes.createPolicy call there is now subject to the same limitation as the `new Worker` call below. Its can simply use `import.meta.url` directly I believe.
1 parent efec622 commit d6a1e01

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/lib/libpthread.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,19 +422,15 @@ var LibraryPThread = {
422422
#if TRUSTED_TYPES
423423
// Use Trusted Types compatible wrappers.
424424
if (typeof trustedTypes != 'undefined' && trustedTypes.createPolicy) {
425-
var p = trustedTypes.createPolicy(
426-
'emscripten#workerPolicy1',
427-
{
428-
createScriptURL: (ignored) => new URL("{{{ TARGET_JS_NAME }}}", import.meta.url)
429-
}
430-
);
425+
var p = trustedTypes.createPolicy('emscripten#workerPolicy1', { createScriptURL: (ignored) => import.meta.url });
431426
worker = new Worker(p.createScriptURL('ignored'), {{{ pthreadWorkerOptions }}});
432427
} else
433428
#endif
434429
// We need to generate the URL with import.meta.url as the base URL of the JS file
435430
// instead of just using new URL(import.meta.url) because bundler's only recognize
436431
// the first case in their bundling step. The latter ends up producing an invalid
437432
// URL to import from the server (e.g., for webpack the file:// path).
433+
// See https://github.com/webpack/webpack/issues/12638
438434
worker = new Worker(new URL('{{{ TARGET_JS_NAME }}}', import.meta.url), {{{ pthreadWorkerOptions }}});
439435
#else // EXPORT_ES6
440436
var pthreadMainJs = _scriptName;

0 commit comments

Comments
 (0)