deno
0cd314be - fix(ext/node): prevent postMessage/onmessage overwrite in worker_threads

Commit
144 days ago
fix(ext/node): prevent postMessage/onmessage overwrite in worker_threads Since `parentPort === globalThis` in Deno's worker_threads polyfill, user code running in sloppy mode (like fflate's workerAdd shim) that assigns `postMessage = function(...){}` or `onmessage = function(...){}` overwrites the web worker's built-in methods on globalThis. This causes: - postMessage: infinite recursion (parentPort.postMessage calls itself) - onmessage: double message delivery (web event handler + parentPort.on) Fix by: 1. Capturing the original postMessage and making the property non-writable 2. Replacing onmessage/onmessageerror getter/setter with plain value properties (no web event handler side effects) 3. Adding messageListenerCount tracking so parentPort.onmessage still works when no on('message') listeners are registered Closes #26739 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
Parents
Loading