Skip to content

Use normal unquoted names in wasm worker messages. NFC #24232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/lib/libwasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ addToLibrary({
#endif
],
$_wasmWorkerInitializeRuntime: () => {
let m = Module;
#if ASSERTIONS
assert(m && m['$ww']);
assert(m['sb'] % 16 == 0);
assert(m['sz'] % 16 == 0);
assert(wwParams);
assert(wwParams.wwID);
assert(wwParams.stackLowestAddress % 16 == 0);
assert(wwParams.stackSize % 16 == 0);
#endif
#if RUNTIME_DEBUG
dbg("wasmWorkerInitializeRuntime $ww:", m['$ww']);
dbg("wasmWorkerInitializeRuntime wwID:", wwParams.wwID);
#endif

#if !MINIMAL_RUNTIME && isSymbolNeeded('$noExitRuntime')
Expand All @@ -113,11 +113,12 @@ addToLibrary({
// already exists". So for now, invoke this function from JS side. TODO:
// remove this in the future. Note that this call is not exactly correct,
// since this limit will include the TLS slot, that will be part of the
// region between m['sb'] and m['sz'], so we need to fix up the call below.
___set_stack_limits(m['sb'] + m['sz'], m['sb']);
// region between wwParams.stackLowestAddress and wwParams.stackSize, so we
// need to fix up the call below.
___set_stack_limits(wwParams.stackLowestAddress + wwParams.stackSize, wwParams.stackLowestAddress);
#endif
// Run the C side Worker initialization for stack and TLS.
__emscripten_wasm_worker_initialize(m['sb'], m['sz']);
__emscripten_wasm_worker_initialize(wwParams.stackLowestAddress, wwParams.stackSize);
#if PTHREADS
// Record the pthread configuration, and whether this Wasm Worker supports synchronous blocking in emscripten_futex_wait().
// (regular Wasm Workers do, AudioWorklets don't)
Expand Down Expand Up @@ -198,15 +199,15 @@ if (ENVIRONMENT_IS_WASM_WORKER
worker.postMessage({
// Signal with a non-zero value that this Worker will be a Wasm Worker,
// and not the main browser thread.
'$ww': _wasmWorkersID,
wwID: _wasmWorkersID,
#if MINIMAL_RUNTIME
'wasm': Module['wasm'],
wasm: Module['wasm'],
#else
'wasm': wasmModule,
wasm: wasmModule,
#endif
'mem': wasmMemory,
'sb': stackLowestAddress, // sb = stack bottom (lowest stack address, SP points at this when stack is full)
'sz': stackSize, // sz = stack size
wasmMemory,
stackLowestAddress, // sb = stack bottom (lowest stack address, SP points at this when stack is full)
stackSize, // sz = stack size
});
worker.onmessage = _wasmWorkerRunPostMessage;
#if ENVIRONMENT_MAY_BE_NODE
Expand Down Expand Up @@ -244,7 +245,7 @@ if (ENVIRONMENT_IS_WASM_WORKER
#endif
},

emscripten_wasm_worker_self_id: () => Module['$ww'],
emscripten_wasm_worker_self_id: () => wwParams?.wwID,

emscripten_wasm_worker_post_function_v: (id, funcPtr) => {
_wasmWorkers[id].postMessage({'_wsc': funcPtr, 'x': [] }); // "WaSm Call"
Expand Down
12 changes: 6 additions & 6 deletions src/lib/libwebaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ let LibraryWebAudio = {
// Assign the loaded AudioWorkletGlobalScope a Wasm Worker ID so that
// it can utilized its own TLS slots, and it is recognized to not be
// the main browser thread.
'$ww': _wasmWorkersID++,
wwID: _wasmWorkersID++,
#if MINIMAL_RUNTIME
'wasm': Module['wasm'],
wasm: Module['wasm'],
#else
'wasm': wasmModule,
wasm: wasmModule,
#endif
'mem': wasmMemory,
'sb': stackLowestAddress, // sb = stack base
'sz': stackSize, // sz = stack size
wasmMemory,
stackLowestAddress, // sb = stack base
stackSize, // sz = stack size
}
});
audioWorklet.bootstrapMessage.port.onmessage = _EmAudioDispatchProcessorCallback;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ function unexportedRuntimeSymbol(sym) {
function initWorkerLogging() {
function getLogPrefix() {
#if WASM_WORKERS
if (Module['$ww']) {
return `ww:${Module['$ww']}:`
if (wwParams?.wwID) {
return `ww:${wwParams?.wwID}:`
}
#endif
#if PTHREADS
Expand Down
19 changes: 9 additions & 10 deletions src/wasm_worker.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
var wwParams;

/**
* Called once the intiial message has been recieved from the creating thread.
* The `props` object is the list of properties sent via postMessage to create
* the worker.
* The `props` object is property bag sent via postMessage to create the worker.
*
* This function is called both in normal wasm workers and in audio worklets.
*/
function startWasmWorker(props) {
#if RUNTIME_DEBUG
dbg('startWasmWorker', props);
#endif
#if MINIMAL_RUNTIME
Module ||= {};
#endif
/** @suppress {checkTypes} */
Object.assign(Module, props);
wasmMemory = props['mem'];
wwParams = props;
wasmMemory = props.wasmMemory;
updateMemoryViews();
#if MINIMAL_RUNTIME
Module ||= {};
Module['wasm'] = props.wasm;
loadModule()
#else
wasmModuleReceived(props['wasm']);
wasmModuleReceived(props.wasm);
#endif
// Drop now unneeded references to from the Module object in this Worker,
// these are not needed anymore.
props['wasm'] = props['mem'] = 0;
props.wasm = props.memMemory = 0;
}

#if AUDIO_WORKLET
Expand Down
Loading
Loading