summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2019-02-20 11:42:19 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-02-19 21:42:19 -0500
commitc4e37285758ff4cc5d388db2d880ed91decb3d29 (patch)
tree0c4f813da45a6407359ea739d0cd9b06af138d8e /js
parenta5720d9e28f7ee5868049504816405392c2821d7 (diff)
remove global_eval.ts (#1813)
Diffstat (limited to 'js')
-rw-r--r--js/compiler.ts5
-rw-r--r--js/global_eval.ts11
-rw-r--r--js/globals.ts4
-rw-r--r--js/libdeno.ts3
-rw-r--r--js/location.ts2
-rw-r--r--js/mixins/dom_iterable.ts6
-rw-r--r--js/repl.ts4
-rw-r--r--js/window.ts10
-rw-r--r--js/workers.ts6
9 files changed, 17 insertions, 34 deletions
diff --git a/js/compiler.ts b/js/compiler.ts
index 27b97dd2d..27890babd 100644
--- a/js/compiler.ts
+++ b/js/compiler.ts
@@ -1,9 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as ts from "typescript";
import * as msg from "gen/msg_generated";
+import { window } from "./window";
import { assetSourceCode } from "./assets";
import { Console } from "./console";
-import { globalEval } from "./global_eval";
import { libdeno } from "./libdeno";
import * as os from "./os";
import { TextDecoder, TextEncoder } from "./text_encoding";
@@ -15,9 +15,6 @@ const EOL = "\n";
const ASSETS = "$asset$";
const LIB_RUNTIME = `${ASSETS}/lib.deno_runtime.d.ts`;
-// A reference to the global scope
-const window = globalEval("this");
-
// An instance of console
const console = new Console(libdeno.print);
diff --git a/js/global_eval.ts b/js/global_eval.ts
deleted file mode 100644
index b447c9954..000000000
--- a/js/global_eval.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-
-/** If you use the eval function indirectly, by invoking it via a reference
- * other than eval, as of ECMAScript 5 it works in the global scope rather than
- * the local scope. This means, for instance, that function declarations create
- * global functions, and that the code being evaluated doesn't have access to
- * local variables within the scope where it's being called.
- *
- * @internal
- */
-export const globalEval = eval;
diff --git a/js/globals.ts b/js/globals.ts
index 935890be4..9bd0584b2 100644
--- a/js/globals.ts
+++ b/js/globals.ts
@@ -7,6 +7,7 @@
// Modules which will make up part of the global public API surface should be
// imported as namespaces, so when the runtime tpye library is generated they
// can be expressed as a namespace in the type library.
+import { window } from "./window";
import * as blob from "./blob";
import * as consoleTypes from "./console";
import * as customEvent from "./custom_event";
@@ -26,7 +27,6 @@ import * as performanceUtil from "./performance";
// These imports are not exposed and therefore are fine to just import the
// symbols required.
-import { globalEval } from "./global_eval";
import { libdeno } from "./libdeno";
// During the build process, augmentations to the variable `window` in this
@@ -37,8 +37,6 @@ declare global {
const setTimeout: typeof timers.setTimeout;
}
-// A reference to the global object.
-export const window = globalEval("this");
// A self reference to the global object.
window.window = window;
diff --git a/js/libdeno.ts b/js/libdeno.ts
index 79ce4272a..61e259b54 100644
--- a/js/libdeno.ts
+++ b/js/libdeno.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { globalEval } from "./global_eval";
+import { window } from "./window";
// The libdeno functions are moved so that users can't access them.
type MessageCallback = (msg: Uint8Array) => void;
@@ -40,5 +40,4 @@ interface Libdeno {
errorToJSON: (e: Error) => string;
}
-const window = globalEval("this");
export const libdeno = window.libdeno as Libdeno;
diff --git a/js/location.ts b/js/location.ts
index 5e7cb07b4..5d7f44707 100644
--- a/js/location.ts
+++ b/js/location.ts
@@ -2,7 +2,7 @@
import { URL } from "./url";
import { notImplemented } from "./util";
import { Location } from "./dom_types";
-import { window } from "./globals";
+import { window } from "./window";
export function setLocation(url: string): void {
window.location = new LocationImpl(url);
diff --git a/js/mixins/dom_iterable.ts b/js/mixins/dom_iterable.ts
index e2fcd2dbd..ae5a030ce 100644
--- a/js/mixins/dom_iterable.ts
+++ b/js/mixins/dom_iterable.ts
@@ -1,12 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { DomIterable } from "../dom_types";
-import { globalEval } from "../global_eval";
+import { window } from "../window";
import { requiredArguments } from "../util";
-// if we import it directly from "globals" it will break the unit tests so we
-// have to grab a reference to the global scope a different way
-const window = globalEval("this");
-
// tslint:disable:no-any
type Constructor<T = {}> = new (...args: any[]) => T;
diff --git a/js/repl.ts b/js/repl.ts
index f7ddb2bdf..2c050bf5b 100644
--- a/js/repl.ts
+++ b/js/repl.ts
@@ -5,12 +5,10 @@ import { assert } from "./util";
import { close } from "./files";
import * as dispatch from "./dispatch";
import { exit } from "./os";
-import { globalEval } from "./global_eval";
+import { window } from "./window";
import { libdeno } from "./libdeno";
import { formatError } from "./format_error";
-const window = globalEval("this");
-
const helpMsg = [
"exit Exit the REPL",
"help Print this help message"
diff --git a/js/window.ts b/js/window.ts
new file mode 100644
index 000000000..6773ea5b2
--- /dev/null
+++ b/js/window.ts
@@ -0,0 +1,10 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+
+// (0, eval) is indirect eval.
+// See the links below for details:
+// - https://stackoverflow.com/a/14120023
+// - https://tc39.github.io/ecma262/#sec-performeval (spec)
+export const window = (0, eval)("this");
+// TODO: The above should be replaced with globalThis
+// when the globalThis proposal goes to stage 4
+// See https://github.com/tc39/proposal-global
diff --git a/js/workers.ts b/js/workers.ts
index fd82e2304..1716f8ef6 100644
--- a/js/workers.ts
+++ b/js/workers.ts
@@ -3,7 +3,7 @@ import * as dispatch from "./dispatch";
import * as msg from "gen/msg_generated";
import * as flatbuffers from "./flatbuffers";
import { assert, log } from "./util";
-import { globalEval } from "./global_eval";
+import { window } from "./window";
export async function postMessage(data: Uint8Array): Promise<void> {
const builder = flatbuffers.createBuilder();
@@ -53,10 +53,6 @@ export function workerClose(): void {
export async function workerMain() {
log("workerMain");
- // TODO avoid using globalEval to get Window. But circular imports if getting
- // it from globals.ts
- const window = globalEval("this");
-
while (!isClosing) {
const data = await getMessage();
if (data == null) {