reorg: Deno global initialization (#4317)

This commit is contained in:
Bartek Iwańczuk 2020-03-11 21:57:24 +01:00 committed by GitHub
parent b8fa3fd5e7
commit 810e4a16be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 40 deletions

View file

@ -20,9 +20,10 @@ import {
import { internalObject } from "./internals.ts";
import { setSignals } from "./signals.ts";
import { replLoop } from "./repl.ts";
import { LocationImpl } from "./web/location.ts";
import * as runtime from "./runtime.ts";
import { symbols } from "./symbols.ts";
import { log } from "./util.ts";
import { log, immutableDefine } from "./util.ts";
// TODO: factor out `Deno` global assignment to separate function
// Add internal object to Deno object.
@ -33,8 +34,6 @@ Deno[symbols.internal] = internalObject;
export const mainRuntimeGlobalProperties = {
window: readOnly(globalThis),
self: readOnly(globalThis),
Deno: readOnly(Deno),
crypto: readOnly(csprng),
// TODO(bartlomieju): from MDN docs (https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope)
// it seems those two properties should be availble to workers as well
@ -69,15 +68,27 @@ export function bootstrapMainRuntime(): void {
}
});
const s = runtime.start(true);
const s = runtime.start();
const location = new LocationImpl(s.location);
immutableDefine(globalThis, "location", location);
Object.freeze(globalThis.location);
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();
log("cwd", s.cwd);
for (let i = 0; i < s.args.length; i++) {
Deno.args.push(s.args[i]);
}
log("args", Deno.args);
Object.freeze(Deno.args);
if (s.repl) {
replLoop();