diff --git a/js/workers.ts b/js/workers.ts index 38a80368ffab19..6d644edbdbb131 100644 --- a/js/workers.ts +++ b/js/workers.ts @@ -1,9 +1,9 @@ import * as dispatch from "./dispatch"; import * as msg from "gen/msg_generated"; import * as flatbuffers from "./flatbuffers"; -import { window } from "./globals"; import { libdeno } from "./libdeno"; import { assert, log, setLogDebug } from "./util"; +import { globalEval } from "./global_eval"; export async function postMessage(data: Uint8Array): Promise { const builder = flatbuffers.createBuilder(); @@ -56,14 +56,18 @@ export async function workerMain() { setLogDebug(true); log("workerMain"); + // TODO avoid using globalEval to get Window. But circular imports if getting + // it from globals.ts + const window = globalEval("this"); + while (!isClosing) { - let data = await getMessage(); + const data = await getMessage(); if (data == null) { log("workerMain got null message. quitting."); break; } if (window["onmessage"]) { - let event = { data }; + const event = { data }; window.onmessage(event); } else { break;