Steps to reproduce
- Use
#[webworker_fn] or #[webworker_channel_fn] with a worker pool
- The worker has
addEventListener('message', handler) for task dispatch
- Send several tasks to the pool
Expected
Only the addEventListener handler processes messages.
Actual
Both addEventListener and wasm-bindgen's internally registered handler fire.
The wasm-bindgen handler receives wasmworker's {id, func_name, is_channel, arg}
format and fails:
TypeError: Cannot read properties of undefined (reading 'length')
Could not deserialize response
Root cause
mod.default() during init registers a message handler (via self.onmessage
setter). Subsequent addEventListener('message', ...) adds a second handler,
and both fire for every postMessage.
Proposed fix
Lock onmessage via Object.defineProperty with a no-op setter after
mod.default(), so addEventListener remains the sole dispatch path.
See commit: 200ec0e
PR: #25
Steps to reproduce
#[webworker_fn]or#[webworker_channel_fn]with a worker pooladdEventListener('message', handler)for task dispatchExpected
Only the
addEventListenerhandler processes messages.Actual
Both
addEventListenerand wasm-bindgen's internally registered handler fire.The wasm-bindgen handler receives wasmworker's
{id, func_name, is_channel, arg}format and fails:
TypeError: Cannot read properties of undefined (reading 'length')
Could not deserialize response
Root cause
mod.default()during init registers a message handler (viaself.onmessagesetter). Subsequent
addEventListener('message', ...)adds a second handler,and both fire for every
postMessage.Proposed fix
Lock
onmessageviaObject.definePropertywith a no-op setter aftermod.default(), soaddEventListenerremains the sole dispatch path.See commit:
200ec0ePR: #25