Skip to content

Commit

Permalink
refactor: remove global_eval.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Feb 20, 2019
1 parent a5720d9 commit aed71ea
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 35 deletions.
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ ts_sources = [
"js/files.ts",
"js/flatbuffers.ts",
"js/form_data.ts",
"js/global_eval.ts",
"js/globals.ts",
"js/headers.ts",
"js/io.ts",
Expand Down Expand Up @@ -107,6 +106,7 @@ ts_sources = [
"js/url.ts",
"js/url_search_params.ts",
"js/util.ts",
"js/window.ts",
"js/workers.ts",
"js/write_file.ts",
"js/performance.ts",
Expand Down
5 changes: 1 addition & 4 deletions js/compiler.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);

Expand Down
11 changes: 0 additions & 11 deletions js/global_eval.ts

This file was deleted.

4 changes: 1 addition & 3 deletions js/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand All @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions js/libdeno.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -40,5 +40,4 @@ interface Libdeno {
errorToJSON: (e: Error) => string;
}

const window = globalEval("this");
export const libdeno = window.libdeno as Libdeno;
2 changes: 1 addition & 1 deletion js/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions js/mixins/dom_iterable.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 1 addition & 3 deletions js/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions js/window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// If you use the eval function indirectly, it works in the global scope rather than
// the local scope.
// See https://stackoverflow.com/questions/14119988/return-this-0-evalthis/14120023#14120023
// TODO: this should be replaced with globalThis
// when the proposal goes to stage 4
// See https://github.com/tc39/proposal-global
export const window = (0, eval)("this");
6 changes: 1 addition & 5 deletions js/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit aed71ea

Please sign in to comment.