diff options
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; } |