4
4
* SPDX-License-Identifier: MIT
5
5
*/
6
6
7
- #if WASM_WORKERS == 2
8
- // Helpers for _wasmWorkerBlobUrl used in WASM_WORKERS == 2 mode
9
- { { {
10
- const captureModuleArg = ( ) => MODULARIZE ? '' : 'self.Module=d;' ;
11
- const instantiateModule = ( ) => MODULARIZE ? `${ EXPORT_NAME } (d);` : '' ;
12
- const instantiateWasm = ( ) => MINIMAL_RUNTIME ? '' : 'd[`instantiateWasm`]=(i,r)=>{var n=new WebAssembly.Instance(d[`wasm`],i);return r(n,d[`wasm`]);};' ;
13
- } } }
14
- #endif
15
-
16
7
#if WASM_WORKERS
17
8
18
9
#if ! SHARED_MEMORY
34
25
{ { {
35
26
const workerSupportsFutexWait = ( ) => AUDIO_WORKLET ? "typeof AudioWorkletGlobalScope === 'undefined'" : '1' ;
36
27
const wasmWorkerJs = `
37
- #if WASM_WORKERS == 2
38
- _wasmWorkerBlobUrl
39
- #elif MINIMAL_RUNTIME
28
+ #if MINIMAL_RUNTIME
40
29
Module['$wb']
41
30
#else
42
- locateFile('${ WASM_WORKER_FILE } ')
31
+ locateFile('${ TARGET_JS_NAME } ')
43
32
#endif
44
33
` ;
34
+ const wasmWorkerOptions = `{
35
+ #if ENVIRONMENT_MAY_BE_NODE
36
+ // This is the way that we signal to the node worker that it is hosting
37
+ // a wasm worker.
38
+ 'workerData': 'em-ww',
39
+ #endif
40
+ }` ;
45
41
} } }
46
42
47
43
#endif // ~WASM_WORKERS
@@ -83,7 +79,7 @@ addToLibrary({
83
79
#endif
84
80
] ,
85
81
$_wasmWorkerInitializeRuntime : ( ) => {
86
- let m = Module ;
82
+ let m = wasmWorkerArgs ;
87
83
#if ASSERTIONS
88
84
assert ( m [ 'sb' ] % 16 == 0 ) ;
89
85
assert ( m [ 'sz' ] % 16 == 0 ) ;
@@ -142,20 +138,9 @@ addToLibrary({
142
138
#endif
143
139
} ,
144
140
145
- #if WASM_WORKERS == 2
146
- // In WASM_WORKERS == 2 build mode, we create the Wasm Worker global scope
147
- // script from a string bundled in the main application JS file. This
148
- // simplifies the number of deployed JS files with the app, but has a downside
149
- // that the generated build output will no longer be csp-eval compliant.
150
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_eval_expressions
151
- $_wasmWorkerBlobUrl : "URL.createObjectURL(new Blob(['onmessage=function(d){onmessage=null;d=d.data;{{{ captureModuleArg() }}}{{{ instantiateWasm() }}}importScripts(d.js);{{{ instantiateModule() }}}d.wasm=d.mem=d.js=0;}'],{type:'application/javascript'}))" ,
152
- #endif
153
141
_emscripten_create_wasm_worker__deps : [
154
142
'$_wasmWorkers' , '$_wasmWorkersID' ,
155
143
'$_wasmWorkerAppendToQueue' , '$_wasmWorkerRunPostMessage' ,
156
- #if WASM_WORKERS == 2
157
- '$_wasmWorkerBlobUrl' ,
158
- #endif
159
144
#if ASSERTIONS
160
145
'emscripten_has_threading_support' ,
161
146
#endif
@@ -167,7 +152,7 @@ if (ENVIRONMENT_IS_WASM_WORKER
167
152
&& !ENVIRONMENT_IS_AUDIO_WORKLET
168
153
#endif
169
154
) {
170
- _wasmWorkers[0] = this ;
155
+ _wasmWorkers[0] = globalThis ;
171
156
addEventListener("message", _wasmWorkerAppendToQueue);
172
157
}` ,
173
158
_emscripten_create_wasm_worker : ( stackLowestAddress , stackSize ) => {
@@ -184,10 +169,10 @@ if (ENVIRONMENT_IS_WASM_WORKER
184
169
var p = trustedTypes . createPolicy (
185
170
'emscripten#workerPolicy1' , { createScriptURL : ( ignored ) => { { { wasmWorkerJs } } } }
186
171
) ;
187
- worker = _wasmWorkers [ _wasmWorkersID ] = new Worker ( p . createScriptURL ( 'ignored' ) ) ;
172
+ worker = _wasmWorkers [ _wasmWorkersID ] = new Worker ( p . createScriptURL ( 'ignored' ) , { { { wasmWorkerOptions } } } ) ;
188
173
} else
189
174
#endif
190
- worker = _wasmWorkers [ _wasmWorkersID ] = new Worker ( { { { wasmWorkerJs } } } ) ;
175
+ worker = _wasmWorkers [ _wasmWorkersID ] = new Worker ( { { { wasmWorkerJs } } } , { { { wasmWorkerOptions } } } ) ;
191
176
// Craft the Module object for the Wasm Worker scope:
192
177
worker . postMessage ( {
193
178
// Signal with a non-zero value that this Worker will be a Wasm Worker,
0 commit comments