From 60b53fd6b6dc2af83a64c332b9f3a1926f43d631 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 21 Jan 2020 01:30:30 +1100 Subject: Use globalThis to reference global scope (#3719) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk --- cli/js/repl.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'cli/js/repl.ts') diff --git a/cli/js/repl.ts b/cli/js/repl.ts index 922cd499d..813f0cb21 100644 --- a/cli/js/repl.ts +++ b/cli/js/repl.ts @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { close } from "./files.ts"; import { exit } from "./os.ts"; -import { window } from "./window.ts"; import { core } from "./core.ts"; import { formatError } from "./format_error.ts"; import { stringifyArgs } from "./console.ts"; @@ -104,8 +103,8 @@ function evaluate(code: string): boolean { // @internal export async function replLoop(): Promise { - const { console } = window; - Object.defineProperties(window, replCommands); + const { console } = globalThis; + Object.defineProperties(globalThis, replCommands); const historyFile = "deno_history.txt"; const rid = startRepl(historyFile); @@ -118,12 +117,12 @@ export async function replLoop(): Promise { exit(exitCode); }; - // Configure window._ to give the last evaluation result. - Object.defineProperty(window, "_", { + // Configure globalThis._ to give the last evaluation result. + Object.defineProperty(globalThis, "_", { configurable: true, get: (): Value => lastEvalResult, set: (value: Value): Value => { - Object.defineProperty(window, "_", { + Object.defineProperty(globalThis, "_", { value: value, writable: true, enumerable: true, @@ -133,12 +132,12 @@ export async function replLoop(): Promise { } }); - // Configure window._error to give the last thrown error. - Object.defineProperty(window, "_error", { + // Configure globalThis._error to give the last thrown error. + Object.defineProperty(globalThis, "_error", { configurable: true, get: (): Value => lastThrownError, set: (value: Value): Value => { - Object.defineProperty(window, "_error", { + Object.defineProperty(globalThis, "_error", { value: value, writable: true, enumerable: true, -- cgit v1.2.3