diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-06-09 22:21:02 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-09 22:21:02 +1000 |
commit | e779ea956546fc311ad5a98260d1091127a9bfe7 (patch) | |
tree | e406f10ee3e0fd4da9ae4e7326a0766d7b840f8e /runtime/js/99_main.js | |
parent | c84c747ea491bd42f11323e1a0cc54900e1146c0 (diff) |
fix(runtime): early binding to dispatchEvent in workers (#10904)
Diffstat (limited to 'runtime/js/99_main.js')
-rw-r--r-- | runtime/js/99_main.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index f196f3008..aac6fc0ea 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -82,7 +82,12 @@ delete Object.prototype.__proto__; } let isClosing = false; + let globalDispatchEvent; + async function pollForMessages() { + if (!globalDispatchEvent) { + globalDispatchEvent = globalThis.dispatchEvent.bind(globalThis); + } while (!isClosing) { const bufferMsg = await core.opAsync("op_worker_get_message"); const data = core.deserialize(bufferMsg); @@ -96,7 +101,7 @@ delete Object.prototype.__proto__; if (globalThis.onmessage) { await globalThis.onmessage(msgEvent); } - globalThis.dispatchEvent(msgEvent); + globalDispatchEvent(msgEvent); } catch (e) { let handled = false; @@ -120,7 +125,7 @@ delete Object.prototype.__proto__; handled = ret === true; } - globalThis.dispatchEvent(errorEvent); + globalDispatchEvent(errorEvent); if (errorEvent.defaultPrevented) { handled = true; } |