mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
reorg: Deno global initialization (#4317)
This commit is contained in:
parent
b8fa3fd5e7
commit
810e4a16be
3 changed files with 31 additions and 40 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue