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:
parent
a5720d9e28
commit
c4e3728575
10 changed files with 18 additions and 35 deletions
2
BUILD.gn
2
BUILD.gn
|
@ -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",
|
||||
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
10
js/window.ts
Normal file
10
js/window.ts
Normal 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
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue