1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

remove global_eval.ts (#1813)

This commit is contained in:
Yoshiya Hinosawa 2019-02-20 11:42:19 +09:00 committed by Ryan Dahl
parent a5720d9e28
commit c4e3728575
10 changed files with 18 additions and 35 deletions

View file

@ -74,7 +74,6 @@ ts_sources = [
"js/files.ts", "js/files.ts",
"js/flatbuffers.ts", "js/flatbuffers.ts",
"js/form_data.ts", "js/form_data.ts",
"js/global_eval.ts",
"js/globals.ts", "js/globals.ts",
"js/headers.ts", "js/headers.ts",
"js/io.ts", "js/io.ts",
@ -107,6 +106,7 @@ ts_sources = [
"js/url.ts", "js/url.ts",
"js/url_search_params.ts", "js/url_search_params.ts",
"js/util.ts", "js/util.ts",
"js/window.ts",
"js/workers.ts", "js/workers.ts",
"js/write_file.ts", "js/write_file.ts",
"js/performance.ts", "js/performance.ts",

View file

@ -1,9 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as ts from "typescript"; import * as ts from "typescript";
import * as msg from "gen/msg_generated"; import * as msg from "gen/msg_generated";
import { window } from "./window";
import { assetSourceCode } from "./assets"; import { assetSourceCode } from "./assets";
import { Console } from "./console"; import { Console } from "./console";
import { globalEval } from "./global_eval";
import { libdeno } from "./libdeno"; import { libdeno } from "./libdeno";
import * as os from "./os"; import * as os from "./os";
import { TextDecoder, TextEncoder } from "./text_encoding"; import { TextDecoder, TextEncoder } from "./text_encoding";
@ -15,9 +15,6 @@ const EOL = "\n";
const ASSETS = "$asset$"; const ASSETS = "$asset$";
const LIB_RUNTIME = `${ASSETS}/lib.deno_runtime.d.ts`; const LIB_RUNTIME = `${ASSETS}/lib.deno_runtime.d.ts`;
// A reference to the global scope
const window = globalEval("this");
// An instance of console // An instance of console
const console = new Console(libdeno.print); const console = new Console(libdeno.print);

View file

@ -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;

View file

@ -7,6 +7,7 @@
// Modules which will make up part of the global public API surface should be // 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 // imported as namespaces, so when the runtime tpye library is generated they
// can be expressed as a namespace in the type library. // can be expressed as a namespace in the type library.
import { window } from "./window";
import * as blob from "./blob"; import * as blob from "./blob";
import * as consoleTypes from "./console"; import * as consoleTypes from "./console";
import * as customEvent from "./custom_event"; 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 // These imports are not exposed and therefore are fine to just import the
// symbols required. // symbols required.
import { globalEval } from "./global_eval";
import { libdeno } from "./libdeno"; import { libdeno } from "./libdeno";
// During the build process, augmentations to the variable `window` in this // During the build process, augmentations to the variable `window` in this
@ -37,8 +37,6 @@ declare global {
const setTimeout: typeof timers.setTimeout; const setTimeout: typeof timers.setTimeout;
} }
// A reference to the global object.
export const window = globalEval("this");
// A self reference to the global object. // A self reference to the global object.
window.window = window; window.window = window;

View file

@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // 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. // The libdeno functions are moved so that users can't access them.
type MessageCallback = (msg: Uint8Array) => void; type MessageCallback = (msg: Uint8Array) => void;
@ -40,5 +40,4 @@ interface Libdeno {
errorToJSON: (e: Error) => string; errorToJSON: (e: Error) => string;
} }
const window = globalEval("this");
export const libdeno = window.libdeno as Libdeno; export const libdeno = window.libdeno as Libdeno;

View file

@ -2,7 +2,7 @@
import { URL } from "./url"; import { URL } from "./url";
import { notImplemented } from "./util"; import { notImplemented } from "./util";
import { Location } from "./dom_types"; import { Location } from "./dom_types";
import { window } from "./globals"; import { window } from "./window";
export function setLocation(url: string): void { export function setLocation(url: string): void {
window.location = new LocationImpl(url); window.location = new LocationImpl(url);

View file

@ -1,12 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { DomIterable } from "../dom_types"; import { DomIterable } from "../dom_types";
import { globalEval } from "../global_eval"; import { window } from "../window";
import { requiredArguments } from "../util"; 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 // tslint:disable:no-any
type Constructor<T = {}> = new (...args: any[]) => T; type Constructor<T = {}> = new (...args: any[]) => T;

View file

@ -5,12 +5,10 @@ import { assert } from "./util";
import { close } from "./files"; import { close } from "./files";
import * as dispatch from "./dispatch"; import * as dispatch from "./dispatch";
import { exit } from "./os"; import { exit } from "./os";
import { globalEval } from "./global_eval"; import { window } from "./window";
import { libdeno } from "./libdeno"; import { libdeno } from "./libdeno";
import { formatError } from "./format_error"; import { formatError } from "./format_error";
const window = globalEval("this");
const helpMsg = [ const helpMsg = [
"exit Exit the REPL", "exit Exit the REPL",
"help Print this help message" "help Print this help message"

10
js/window.ts Normal file
View file

@ -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

View file

@ -3,7 +3,7 @@ import * as dispatch from "./dispatch";
import * as msg from "gen/msg_generated"; import * as msg from "gen/msg_generated";
import * as flatbuffers from "./flatbuffers"; import * as flatbuffers from "./flatbuffers";
import { assert, log } from "./util"; import { assert, log } from "./util";
import { globalEval } from "./global_eval"; import { window } from "./window";
export async function postMessage(data: Uint8Array): Promise<void> { export async function postMessage(data: Uint8Array): Promise<void> {
const builder = flatbuffers.createBuilder(); const builder = flatbuffers.createBuilder();
@ -53,10 +53,6 @@ export function workerClose(): void {
export async function workerMain() { export async function workerMain() {
log("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) { while (!isClosing) {
const data = await getMessage(); const data = await getMessage();
if (data == null) { if (data == null) {