@@ -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,49 @@ 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+ // This is the way that we signal to the node worker that it is hosting
437+ // a pthread. On the web we append `?pthread=1` to the URL instead.
438+ 'workerData' : 'pthread' ,
439+ #endif
440+ } ;
443441#if MINIMAL_RUNTIME
444442 var pthreadMainJs = Module [ 'worker' ] ;
445443#else
446444#if EXPORT_ES6 && USE_ES6_IMPORT_META
447445 // If we're using module output and there's no explicit override, use bundler-friendly pattern.
448446 if ( ! Module [ 'locateFile' ] ) {
449447#if PTHREADS_DEBUG
450- dbg ( 'Allocating a new web worker from ' + new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) ) ;
448+ dbg ( 'Allocating a new web worker from ' + import . meta. url ) ;
451449#endif
452450#if TRUSTED_TYPES
453451 // Use Trusted Types compatible wrappers.
454452 if ( typeof trustedTypes != 'undefined' && trustedTypes . createPolicy ) {
455453 var p = trustedTypes . createPolicy (
456454 'emscripten#workerPolicy1' ,
457455 {
458- createScriptURL : ( ignored ) => new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) ;
456+ createScriptURL : ( ignored ) => new URL ( import . meta. url ) ;
459457 }
460458 ) ;
461- worker = new Worker ( p . createScriptURL ( 'ignored' ) , { type : 'module' } ) ;
459+ worker = new Worker ( p . createScriptURL ( 'ignored' ) , workerOptions ) ;
462460 } else
463461#endif
464- worker = new Worker ( new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) , { type : 'module' } ) ;
462+ worker = new Worker ( new URL ( import . meta. url ) , workerOptions ) ;
465463 } else {
466464#endif
467465 // Allow HTML module to configure the location where the 'worker.js' file will be loaded from,
468466 // via Module.locateFile() function. If not specified, then the default URL 'worker.js' relative
469467 // to the main html file is loaded.
470- var pthreadMainJs = locateFile ( '{{{ PTHREAD_WORKER_FILE }}}' ) ;
468+ var pthreadMainJs = locateFile ( '{{{ TARGET_JS_NAME }}}' ) ;
469+ #if ENVIRONMENT_MAY_BE_WEB
470+ // On the web we use a URL parameter to determine if we are running a
471+ // pthread or not.
472+ if ( ENVIRONMENT_IS_WEB ) {
473+ pthreadMainJs += '?pthread = 1 ';
474+ }
475+ #endif
471476#endif
472477#if PTHREADS_DEBUG
473478 dbg ( `Allocating a new web worker from ${ pthreadMainJs } ` ) ;
@@ -476,10 +481,10 @@ var LibraryPThread = {
476481 // Use Trusted Types compatible wrappers.
477482 if ( typeof trustedTypes != 'undefined' && trustedTypes . createPolicy ) {
478483 var p = trustedTypes . createPolicy ( 'emscripten#workerPolicy2' , { createScriptURL : ( ignored ) => pthreadMainJs } ) ;
479- worker = new Worker ( p . createScriptURL ( 'ignored' ) { { { EXPORT_ES6 ? ", {type: 'module'}" : '' } } } ) ;
484+ worker = new Worker ( p . createScriptURL ( 'ignored' ) , workerOptions ) ;
480485 } else
481486#endif
482- worker = new Worker ( pthreadMainJs { { { EXPORT_ES6 ? ", {type: 'module'}" : '' } } } ) ;
487+ worker = new Worker ( pthreadMainJs , workerOptions ) ;
483488#if EXPORT_ES6 && USE_ES6_IMPORT_META
484489 }
485490#endif
0 commit comments