@@ -75,7 +75,7 @@ var LibraryPThread = {
7575 ) {
7676 t = _pthread_self ( ) ;
7777 }
78- return 'w:' + ( Module [ ' workerID' ] || 0 ) + ',t:' + ptrToString ( t ) + ': ' ;
78+ return 'w:' + ( workerID || 0 ) + ',t:' + ptrToString ( t ) + ': ' ;
7979 }
8080
8181 // Prefix all err()/dbg() messages with the calling thread ID.
@@ -127,16 +127,6 @@ var LibraryPThread = {
127127 } ,
128128
129129 initWorker ( ) {
130- #if MAYBE_CLOSURE_COMPILER
131- // worker.js is not compiled together with us, and must access certain
132- // things.
133- PThread [ 'receiveObjectTransfer' ] = PThread . receiveObjectTransfer ;
134- PThread [ 'threadInitTLS' ] = PThread . threadInitTLS ;
135- #if ! MINIMAL_RUNTIME
136- PThread [ 'setExitStatus' ] = PThread . setExitStatus ;
137- #endif
138- #endif
139-
140130#if isSymbolNeeded ( '$noExitRuntime' )
141131 // The default behaviour for pthreads is always to exit once they return
142132 // from their entry point (or call pthread_exit). If we set noExitRuntime
@@ -440,34 +430,47 @@ var LibraryPThread = {
440430 // Creates a new web Worker and places it in the unused worker pool to wait for its use.
441431 allocateUnusedWorker ( ) {
442432 var worker ;
433+ var workerOptions = {
434+ { { { EXPORT_ES6 ? "type: 'module'," : "" } } }
435+ #if ENVIRONMENT_MAY_BE_NODE
436+ 'workerData' : 'pthread' ,
437+ #endif
438+ } ;
443439#if MINIMAL_RUNTIME
444440 var pthreadMainJs = Module [ 'worker' ] ;
445441#else
446442#if EXPORT_ES6 && USE_ES6_IMPORT_META
447443 // If we're using module output and there's no explicit override, use bundler-friendly pattern.
448444 if ( ! Module [ 'locateFile' ] ) {
449445#if PTHREADS_DEBUG
450- dbg ( 'Allocating a new web worker from ' + new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) ) ;
446+ dbg ( 'Allocating a new web worker from ' + import . meta. url ) ;
451447#endif
452448#if TRUSTED_TYPES
453449 // Use Trusted Types compatible wrappers.
454450 if ( typeof trustedTypes != 'undefined' && trustedTypes . createPolicy ) {
455451 var p = trustedTypes . createPolicy (
456452 'emscripten#workerPolicy1' ,
457453 {
458- createScriptURL : ( ignored ) => new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) ;
454+ createScriptURL : ( ignored ) => new URL ( import . meta. url ) ;
459455 }
460456 ) ;
461- worker = new Worker ( p . createScriptURL ( 'ignored' ) , { type : 'module' } ) ;
457+ worker = new Worker ( p . createScriptURL ( 'ignored' ) , workerOptions ) ;
462458 } else
463459#endif
464- worker = new Worker ( new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) , { type : 'module' } ) ;
460+ worker = new Worker ( new URL ( import . meta. url ) , workerOptions ) ;
465461 } else {
466462#endif
467463 // Allow HTML module to configure the location where the 'worker.js' file will be loaded from,
468464 // via Module.locateFile() function. If not specified, then the default URL 'worker.js' relative
469465 // to the main html file is loaded.
470- var pthreadMainJs = locateFile ( '{{{ PTHREAD_WORKER_FILE }}}' ) ;
466+ var pthreadMainJs = locateFile ( '{{{ TARGET_JS_NAME }}}' ) ;
467+ #if ENVIRONMENT_MAY_BE_WEB
468+ // On the web we use a URL parameter to determine if we are running a
469+ // pthread or not.
470+ if ( ENVIRONMENT_IS_WEB ) {
471+ pthreadMainJs += '?pthread=1' ;
472+ }
473+ #endif
471474#endif
472475#if PTHREADS_DEBUG
473476 dbg ( `Allocating a new web worker from ${pthreadMainJs } `) ;
@@ -476,10 +479,10 @@ var LibraryPThread = {
476479 // Use Trusted Types compatible wrappers.
477480 if ( typeof trustedTypes != 'undefined ' && trustedTypes . createPolicy ) {
478481 var p = trustedTypes . createPolicy ( 'emscripten#workerPolicy2' , { createScriptURL : ( ignored ) => pthreadMainJs } ) ;
479- worker = new Worker ( p . createScriptURL ( 'ignored' ) { { { EXPORT_ES6 ? ", {type: 'module'}" : '' } } } ) ;
482+ worker = new Worker ( p . createScriptURL ( 'ignored' ) , workerOptions ) ;
480483 } else
481484#endif
482- worker = new Worker ( pthreadMainJs { { { EXPORT_ES6 ? ", {type: 'module'}" : '' } } } ) ;
485+ worker = new Worker ( pthreadMainJs , workerOptions ) ;
483486#if EXPORT_ES6 && USE_ES6_IMPORT_META
484487 }
485488#endif
@@ -606,6 +609,9 @@ var LibraryPThread = {
606609
607610#if MAIN_MODULE
608611 $registerTLSInit : ( tlsInitFunc , moduleExports , metadata ) => {
612+ #if ASSERTIONS
613+ assert ( tlsInitFunc ) ;
614+ #endif
609615#if DYLINK_DEBUG
610616 dbg ( "registerTLSInit: " + tlsInitFunc ) ;
611617#endif
0 commit comments