Skip to content

Commit 5a85d47

Browse files
authored
Use normal unquoted names in wasm worker messages. NFC (#24232)
Now that the wasm worker code is always in the same file as the main JS code there is no need to quote or minify these names. See #24163.
1 parent 4e6d9a7 commit 5a85d47

9 files changed

+161
-161
lines changed

src/lib/libwasm_worker.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ addToLibrary({
9191
#endif
9292
],
9393
$_wasmWorkerInitializeRuntime: () => {
94-
let m = Module;
9594
#if ASSERTIONS
96-
assert(m && m['$ww']);
97-
assert(m['sb'] % 16 == 0);
98-
assert(m['sz'] % 16 == 0);
95+
assert(wwParams);
96+
assert(wwParams.wwID);
97+
assert(wwParams.stackLowestAddress % 16 == 0);
98+
assert(wwParams.stackSize % 16 == 0);
9999
#endif
100100
#if RUNTIME_DEBUG
101-
dbg("wasmWorkerInitializeRuntime $ww:", m['$ww']);
101+
dbg("wasmWorkerInitializeRuntime wwID:", wwParams.wwID);
102102
#endif
103103

104104
#if !MINIMAL_RUNTIME && isSymbolNeeded('$noExitRuntime')
@@ -113,11 +113,12 @@ addToLibrary({
113113
// already exists". So for now, invoke this function from JS side. TODO:
114114
// remove this in the future. Note that this call is not exactly correct,
115115
// since this limit will include the TLS slot, that will be part of the
116-
// region between m['sb'] and m['sz'], so we need to fix up the call below.
117-
___set_stack_limits(m['sb'] + m['sz'], m['sb']);
116+
// region between wwParams.stackLowestAddress and wwParams.stackSize, so we
117+
// need to fix up the call below.
118+
___set_stack_limits(wwParams.stackLowestAddress + wwParams.stackSize, wwParams.stackLowestAddress);
118119
#endif
119120
// Run the C side Worker initialization for stack and TLS.
120-
__emscripten_wasm_worker_initialize(m['sb'], m['sz']);
121+
__emscripten_wasm_worker_initialize(wwParams.stackLowestAddress, wwParams.stackSize);
121122
#if PTHREADS
122123
// Record the pthread configuration, and whether this Wasm Worker supports synchronous blocking in emscripten_futex_wait().
123124
// (regular Wasm Workers do, AudioWorklets don't)
@@ -198,15 +199,15 @@ if (ENVIRONMENT_IS_WASM_WORKER
198199
worker.postMessage({
199200
// Signal with a non-zero value that this Worker will be a Wasm Worker,
200201
// and not the main browser thread.
201-
'$ww': _wasmWorkersID,
202+
wwID: _wasmWorkersID,
202203
#if MINIMAL_RUNTIME
203-
'wasm': Module['wasm'],
204+
wasm: Module['wasm'],
204205
#else
205-
'wasm': wasmModule,
206+
wasm: wasmModule,
206207
#endif
207-
'mem': wasmMemory,
208-
'sb': stackLowestAddress, // sb = stack bottom (lowest stack address, SP points at this when stack is full)
209-
'sz': stackSize, // sz = stack size
208+
wasmMemory,
209+
stackLowestAddress, // sb = stack bottom (lowest stack address, SP points at this when stack is full)
210+
stackSize, // sz = stack size
210211
});
211212
worker.onmessage = _wasmWorkerRunPostMessage;
212213
#if ENVIRONMENT_MAY_BE_NODE
@@ -244,7 +245,7 @@ if (ENVIRONMENT_IS_WASM_WORKER
244245
#endif
245246
},
246247

247-
emscripten_wasm_worker_self_id: () => Module['$ww'],
248+
emscripten_wasm_worker_self_id: () => wwParams?.wwID,
248249

249250
emscripten_wasm_worker_post_function_v: (id, funcPtr) => {
250251
_wasmWorkers[id].postMessage({'_wsc': funcPtr, 'x': [] }); // "WaSm Call"

src/lib/libwebaudio.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ let LibraryWebAudio = {
190190
// Assign the loaded AudioWorkletGlobalScope a Wasm Worker ID so that
191191
// it can utilized its own TLS slots, and it is recognized to not be
192192
// the main browser thread.
193-
'$ww': _wasmWorkersID++,
193+
wwID: _wasmWorkersID++,
194194
#if MINIMAL_RUNTIME
195-
'wasm': Module['wasm'],
195+
wasm: Module['wasm'],
196196
#else
197-
'wasm': wasmModule,
197+
wasm: wasmModule,
198198
#endif
199-
'mem': wasmMemory,
200-
'sb': stackLowestAddress, // sb = stack base
201-
'sz': stackSize, // sz = stack size
199+
wasmMemory,
200+
stackLowestAddress, // sb = stack base
201+
stackSize, // sz = stack size
202202
}
203203
});
204204
audioWorklet.bootstrapMessage.port.onmessage = _EmAudioDispatchProcessorCallback;

src/runtime_debug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ function unexportedRuntimeSymbol(sym) {
159159
function initWorkerLogging() {
160160
function getLogPrefix() {
161161
#if WASM_WORKERS
162-
if (Module['$ww']) {
163-
return `ww:${Module['$ww']}:`
162+
if (wwParams?.wwID) {
163+
return `ww:${wwParams?.wwID}:`
164164
}
165165
#endif
166166
#if PTHREADS

src/wasm_worker.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1+
var wwParams;
2+
13
/**
24
* Called once the intiial message has been recieved from the creating thread.
3-
* The `props` object is the list of properties sent via postMessage to create
4-
* the worker.
5+
* The `props` object is property bag sent via postMessage to create the worker.
56
*
67
* This function is called both in normal wasm workers and in audio worklets.
78
*/
89
function startWasmWorker(props) {
910
#if RUNTIME_DEBUG
1011
dbg('startWasmWorker', props);
1112
#endif
12-
#if MINIMAL_RUNTIME
13-
Module ||= {};
14-
#endif
15-
/** @suppress {checkTypes} */
16-
Object.assign(Module, props);
17-
wasmMemory = props['mem'];
13+
wwParams = props;
14+
wasmMemory = props.wasmMemory;
1815
updateMemoryViews();
1916
#if MINIMAL_RUNTIME
17+
Module ||= {};
18+
Module['wasm'] = props.wasm;
2019
loadModule()
2120
#else
22-
wasmModuleReceived(props['wasm']);
21+
wasmModuleReceived(props.wasm);
2322
#endif
2423
// Drop now unneeded references to from the Module object in this Worker,
2524
// these are not needed anymore.
26-
props['wasm'] = props['mem'] = 0;
25+
props.wasm = props.memMemory = 0;
2726
}
2827

2928
#if AUDIO_WORKLET

0 commit comments

Comments
 (0)