@@ -29,6 +29,13 @@ const MAX_PTR = Number((2n ** 64n) - 1n);
29
29
#else
30
30
const MAX_PTR = ( 2 ** 32 ) - 1
31
31
#endif
32
+
33
+ #if WASM_ESM_INTEGRATION
34
+ const pthreadWorkerScript = TARGET_BASENAME + '.pthread.mjs' ;
35
+ #else
36
+ const pthreadWorkerScript = TARGET_JS_NAME ;
37
+ #endif
38
+
32
39
// Use a macro to avoid duplicating pthread worker options.
33
40
// We cannot use a normal JS variable since the vite bundler requires that worker
34
41
// options be inline.
@@ -282,6 +289,7 @@ var LibraryPThread = {
282
289
message = `Pthread ${ ptrToString ( worker . pthread_ptr ) } sent an error!` ;
283
290
}
284
291
#endif
292
+ console . error ( e . stack ) ;
285
293
err ( `${ message } ${ e . filename } :${ e . lineno } : ${ e . message } ` ) ;
286
294
throw e ;
287
295
} ;
@@ -295,7 +303,9 @@ var LibraryPThread = {
295
303
296
304
#if ASSERTIONS
297
305
assert ( wasmMemory instanceof WebAssembly . Memory , 'WebAssembly memory should have been loaded by now!' ) ;
306
+ #if ! WASM_ESM_INTEGRATION
298
307
assert ( wasmModule instanceof WebAssembly . Module , 'WebAssembly Module should have been loaded by now!' ) ;
308
+ #endif
299
309
#endif
300
310
301
311
// When running on a pthread, none of the incoming parameters on the module
@@ -333,7 +343,9 @@ var LibraryPThread = {
333
343
#else // WASM2JS
334
344
wasmMemory,
335
345
#endif // WASM2JS
346
+ #if ! WASM_ESM_INTEGRATION
336
347
wasmModule,
348
+ #endif
337
349
#if LOAD_SOURCE_MAP
338
350
wasmSourceMap,
339
351
#endif
@@ -391,25 +403,25 @@ var LibraryPThread = {
391
403
#if TRUSTED_TYPES
392
404
// Use Trusted Types compatible wrappers.
393
405
if ( typeof trustedTypes != 'undefined' && trustedTypes . createPolicy ) {
394
- var p = trustedTypes . createPolicy ( 'emscripten#workerPolicy1' , { createScriptURL : ( ignored ) => import . meta. url } ) ;
406
+ var p = trustedTypes . createPolicy ( 'emscripten#workerPolicy1' , { createScriptURL : ( ignored ) => new URL ( '{{{ pthreadWorkerScript }}}' , import . meta. url ) ) ;
395
407
worker = new Worker ( p . createScriptURL ( 'ignored' ) , { { { pthreadWorkerOptions } } } ) ;
396
408
} else
397
409
#endif
398
410
#if expectToReceiveOnModule ( 'mainScriptUrlOrBlob' )
399
- if ( Module [ 'mainScriptUrlOrBlob' ] ) {
400
- var pthreadMainJs = Module [ 'mainScriptUrlOrBlob' ] ;
401
- if ( typeof pthreadMainJs != 'string' ) {
402
- pthreadMainJs = URL . createObjectURL ( pthreadMainJs ) ;
403
- }
404
- worker = new Worker ( pthreadMainJs , { { { pthreadWorkerOptions } } } ) ;
405
- } else
411
+ if ( Module [ 'mainScriptUrlOrBlob' ] ) {
412
+ var pthreadMainJs = Module [ 'mainScriptUrlOrBlob' ] ;
413
+ if ( typeof pthreadMainJs != 'string' ) {
414
+ pthreadMainJs = URL . createObjectURL ( pthreadMainJs ) ;
415
+ }
416
+ worker = new Worker ( pthreadMainJs , { { { pthreadWorkerOptions } } } ) ;
417
+ } else
406
418
#endif
407
419
// We need to generate the URL with import.meta.url as the base URL of the JS file
408
420
// instead of just using new URL(import.meta.url) because bundler's only recognize
409
421
// the first case in their bundling step. The latter ends up producing an invalid
410
422
// URL to import from the server (e.g., for webpack the file:// path).
411
423
// See https://github.com/webpack/webpack/issues/12638
412
- worker = new Worker ( new URL ( '{{{ TARGET_JS_NAME }}}' , import . meta. url ) , { { { pthreadWorkerOptions } } } ) ;
424
+ worker = new Worker ( new URL ( '{{{ pthreadWorkerScript }}}' , import . meta. url ) , { { { pthreadWorkerOptions } } } ) ;
413
425
#else // EXPORT_ES6
414
426
var pthreadMainJs = _scriptName ;
415
427
#if expectToReceiveOnModule ( 'mainScriptUrlOrBlob' )
@@ -601,10 +613,10 @@ var LibraryPThread = {
601
613
602
614
worker . pthread_ptr = threadParams . pthread_ptr ;
603
615
var msg = {
604
- cmd : 'run' ,
605
- start_routine : threadParams . startRoutine ,
606
- arg : threadParams . arg ,
607
- pthread_ptr : threadParams . pthread_ptr ,
616
+ cmd : 'run' ,
617
+ start_routine : threadParams . startRoutine ,
618
+ arg : threadParams . arg ,
619
+ pthread_ptr : threadParams . pthread_ptr ,
608
620
} ;
609
621
#if OFFSCREENCANVAS_SUPPORT
610
622
// Note that we do not need to quote these names because they are only used
0 commit comments