mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
feat: support Deno namespace in Worker API (#4784)
This commit is contained in:
parent
1cd1f7de70
commit
d359789c52
13 changed files with 190 additions and 21 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue