summaryrefslogtreecommitdiff
path: root/cli/js/runtime_worker.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/runtime_worker.ts')
-rw-r--r--cli/js/runtime_worker.ts32
1 files changed, 29 insertions, 3 deletions
diff --git a/cli/js/runtime_worker.ts b/cli/js/runtime_worker.ts
index 1e7a9a67d..60c845a18 100644
--- a/cli/js/runtime_worker.ts
+++ b/cli/js/runtime_worker.ts
@@ -17,12 +17,23 @@ import {
eventTargetProperties,
setEventTargetData,
} from "./globals.ts";
+import * as Deno from "./deno.ts";
import * as webWorkerOps from "./ops/web_worker.ts";
import { LocationImpl } from "./web/location.ts";
import { log, assert, immutableDefine } from "./util.ts";
import { MessageEvent, ErrorEvent } from "./web/workers.ts";
import { TextEncoder } from "./web/text_encoding.ts";
import * as runtime from "./runtime.ts";
+import { internalObject } from "./internals.ts";
+import { symbols } from "./symbols.ts";
+import { setSignals } from "./signals.ts";
+
+// FIXME(bartlomieju): duplicated in `runtime_main.ts`
+// TODO: factor out `Deno` global assignment to separate function
+// Add internal object to Deno object.
+// This is not exposed as part of the Deno types.
+// @ts-ignore
+Deno[symbols.internal] = internalObject;
const encoder = new TextEncoder();
@@ -109,6 +120,7 @@ export const workerRuntimeGlobalProperties = {
export function bootstrapWorkerRuntime(
name: string,
+ useDenoNamespace: boolean,
internalName?: string
): void {
if (hasBootstrapped) {
@@ -128,7 +140,21 @@ export function bootstrapWorkerRuntime(
immutableDefine(globalThis, "location", location);
Object.freeze(globalThis.location);
- // globalThis.Deno is not available in worker scope
- delete globalThis.Deno;
- assert(globalThis.Deno === undefined);
+ if (useDenoNamespace) {
+ Object.defineProperties(Deno, {
+ pid: readOnly(s.pid),
+ noColor: readOnly(s.noColor),
+ args: readOnly(Object.freeze(s.args)),
+ });
+ // Setup `Deno` global - we're actually overriding already
+ // existing global `Deno` with `Deno` namespace from "./deno.ts".
+ immutableDefine(globalThis, "Deno", Deno);
+ Object.freeze(globalThis.Deno);
+ Object.freeze(globalThis.Deno.core);
+ Object.freeze(globalThis.Deno.core.sharedQueue);
+ setSignals();
+ } else {
+ delete globalThis.Deno;
+ assert(globalThis.Deno === undefined);
+ }
}