From 4041a7b8576047021c2eec711f013c6f01e471e0 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 28 Apr 2020 00:06:03 +0100 Subject: [PATCH] BREAKING: Remove Deno.symbols namespace (#4936) --- cli/js/deno.ts | 5 ++--- cli/js/internals.ts | 4 ++-- cli/js/lib.deno.ns.d.ts | 20 ++++++------------- cli/js/runtime_main.ts | 5 ++--- cli/js/runtime_worker.ts | 5 ++--- cli/js/symbols.ts | 8 -------- cli/js/tests/console_test.ts | 4 ++-- cli/js/tests/dom_iterable_test.ts | 2 +- cli/js/tests/error_stack_test.ts | 2 +- cli/js/tests/headers_test.ts | 2 +- cli/js/tests/internals_test.ts | 2 +- cli/js/tests/symbols_test.ts | 7 ------- cli/js/tests/unit_test_runner.ts | 4 ++-- cli/js/tests/unit_tests.ts | 1 - .../readable_byte_stream_controller.ts | 4 ++-- cli/js/web/streams/readable_stream.ts | 4 ++-- .../readable_stream_default_controller.ts | 4 ++-- .../streams/readable_stream_default_reader.ts | 4 ++-- cli/test_runner.rs | 2 +- 19 files changed, 31 insertions(+), 58 deletions(-) delete mode 100644 cli/js/symbols.ts delete mode 100644 cli/js/tests/symbols_test.ts diff --git a/cli/js/deno.ts b/cli/js/deno.ts index caf98ac70f..355000ac55 100644 --- a/cli/js/deno.ts +++ b/cli/js/deno.ts @@ -12,7 +12,7 @@ export { build, OperatingSystem, Arch } from "./build.ts"; export { chmodSync, chmod } from "./ops/fs/chmod.ts"; export { chownSync, chown } from "./ops/fs/chown.ts"; export { transpileOnly, compile, bundle } from "./compiler/api.ts"; -export { inspect } from "./web/console.ts"; +export { customInspect, inspect } from "./web/console.ts"; export { copyFileSync, copyFile } from "./ops/fs/copy_file.ts"; export { Diagnostic, @@ -38,6 +38,7 @@ export { } from "./files.ts"; export { read, readSync, write, writeSync } from "./ops/io.ts"; export { FsEvent, watchFs } from "./ops/fs_events.ts"; +export { internalSymbol as internal } from "./internals.ts"; export { EOF, copy, @@ -123,5 +124,3 @@ export { core } from "./core.ts"; export let pid: number; export let noColor: boolean; - -export { symbols } from "./symbols.ts"; diff --git a/cli/js/internals.ts b/cli/js/internals.ts index a675c5d7fb..dd02a5fa9a 100644 --- a/cli/js/internals.ts +++ b/cli/js/internals.ts @@ -1,12 +1,12 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -export const internalSymbol = Symbol("Deno.symbols.internal"); +export const internalSymbol = Symbol("Deno.internal"); // The object where all the internal fields for testing will be living. // eslint-disable-next-line @typescript-eslint/no-explicit-any export const internalObject: { [key: string]: any } = {}; // Register a field to internalObject for test access, -// through Deno[Deno.symbols.internal][name]. +// through Deno[Deno.internal][name]. // eslint-disable-next-line @typescript-eslint/no-explicit-any export function exposeForTest(name: string, value: any): void { Object.defineProperty(internalObject, name, { diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index d2106b4f84..835f2a95c0 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -379,7 +379,7 @@ declare namespace Deno { */ export function umask(mask?: number): number; - /** **UNSTABLE**: might move to `Deno.symbols`. */ + /** **UNSTABLE**: might be removed in favor of `null` (#3932). */ export const EOF: unique symbol; export type EOF = typeof EOF; @@ -2338,7 +2338,7 @@ declare namespace Deno { * class A { * x = 10; * y = "hello"; - * [Deno.symbols.customInspect](): string { + * [Deno.customInspect](): string { * return "x=" + this.x + ", y=" + this.y; * } * } @@ -2860,16 +2860,8 @@ declare namespace Deno { windowChange: () => SignalStream; }; - /** **UNSTABLE**: new API. Maybe move `Deno.EOF` here. - * - * Special Deno related symbols. */ - export const symbols: { - /** Symbol to access exposed internal Deno API */ - readonly internal: unique symbol; - /** A symbol which can be used as a key for a custom method which will be - * called when `Deno.inspect()` is called, or when the object is logged to - * the console. */ - readonly customInspect: unique symbol; - // TODO(ry) move EOF here? - }; + /** A symbol which can be used as a key for a custom method which will be + * called when `Deno.inspect()` is called, or when the object is logged to + * the console. */ + export const customInspect: unique symbol; } diff --git a/cli/js/runtime_main.ts b/cli/js/runtime_main.ts index 4c6df892cb..6c6617be05 100644 --- a/cli/js/runtime_main.ts +++ b/cli/js/runtime_main.ts @@ -19,20 +19,19 @@ import { eventTargetProperties, setEventTargetData, } from "./globals.ts"; -import { internalObject } from "./internals.ts"; +import { internalObject, internalSymbol } from "./internals.ts"; import { setSignals } from "./signals.ts"; import { replLoop } from "./repl.ts"; import { LocationImpl } from "./web/location.ts"; import { setTimeout } from "./web/timers.ts"; import * as runtime from "./runtime.ts"; -import { symbols } from "./symbols.ts"; import { log, immutableDefine } from "./util.ts"; // TODO: factor out `Deno` global assignment to separate function // Add internal object to Deno object. // This is not exposed as part of the Deno types. // @ts-ignore -Deno[symbols.internal] = internalObject; +Deno[internalSymbol] = internalObject; let windowIsClosing = false; diff --git a/cli/js/runtime_worker.ts b/cli/js/runtime_worker.ts index 6be8ff5869..0e6e84da89 100644 --- a/cli/js/runtime_worker.ts +++ b/cli/js/runtime_worker.ts @@ -24,8 +24,7 @@ import { log, assert, immutableDefine } from "./util.ts"; import { MessageEvent, ErrorEvent } from "./web/workers.ts"; import { TextEncoder } from "./web/text_encoding.ts"; import * as runtime from "./runtime.ts"; -import { internalObject } from "./internals.ts"; -import { symbols } from "./symbols.ts"; +import { internalObject, internalSymbol } from "./internals.ts"; import { setSignals } from "./signals.ts"; // FIXME(bartlomieju): duplicated in `runtime_main.ts` @@ -33,7 +32,7 @@ import { setSignals } from "./signals.ts"; // Add internal object to Deno object. // This is not exposed as part of the Deno types. // @ts-ignore -Deno[symbols.internal] = internalObject; +Deno[internalSymbol] = internalObject; const encoder = new TextEncoder(); diff --git a/cli/js/symbols.ts b/cli/js/symbols.ts deleted file mode 100644 index 59d0751c00..0000000000 --- a/cli/js/symbols.ts +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { internalSymbol } from "./internals.ts"; -import { customInspect } from "./web/console.ts"; - -export const symbols = { - internal: internalSymbol, - customInspect, -}; diff --git a/cli/js/tests/console_test.ts b/cli/js/tests/console_test.ts index 4a227aafe1..264987ba9d 100644 --- a/cli/js/tests/console_test.ts +++ b/cli/js/tests/console_test.ts @@ -8,12 +8,12 @@ const { // eslint-disable-next-line @typescript-eslint/no-explicit-any } = Deno as any; -const customInspect = Deno.symbols.customInspect; +const customInspect = Deno.customInspect; const { Console, stringifyArgs, // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol -} = Deno[Deno.symbols.internal]; +} = Deno[Deno.internal]; function stringify(...args: unknown[]): string { return stringifyArgs(args).replace(/\n$/, ""); diff --git a/cli/js/tests/dom_iterable_test.ts b/cli/js/tests/dom_iterable_test.ts index 827a788a9e..b9435b3bcc 100644 --- a/cli/js/tests/dom_iterable_test.ts +++ b/cli/js/tests/dom_iterable_test.ts @@ -21,7 +21,7 @@ function setup() { // This is using an internal API we don't want published as types, so having // to cast to any to "trick" TypeScript // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol - DomIterable: Deno[Deno.symbols.internal].DomIterableMixin(Base, dataSymbol), + DomIterable: Deno[Deno.internal].DomIterableMixin(Base, dataSymbol), }; } diff --git a/cli/js/tests/error_stack_test.ts b/cli/js/tests/error_stack_test.ts index 83a2020ac5..e5cedfcf51 100644 --- a/cli/js/tests/error_stack_test.ts +++ b/cli/js/tests/error_stack_test.ts @@ -2,7 +2,7 @@ import { unitTest, assert } from "./test_util.ts"; // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol -const { setPrepareStackTrace } = Deno[Deno.symbols.internal]; +const { setPrepareStackTrace } = Deno[Deno.internal]; interface CallSite { getThis(): unknown; diff --git a/cli/js/tests/headers_test.ts b/cli/js/tests/headers_test.ts index dbc54dc9f1..0711a77367 100644 --- a/cli/js/tests/headers_test.ts +++ b/cli/js/tests/headers_test.ts @@ -8,7 +8,7 @@ import { const { stringifyArgs, // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol -} = Deno[Deno.symbols.internal]; +} = Deno[Deno.internal]; // Logic heavily copied from web-platform-tests, make // sure pass mostly header basic test diff --git a/cli/js/tests/internals_test.ts b/cli/js/tests/internals_test.ts index b794bb5e8b..abd4c94c3d 100644 --- a/cli/js/tests/internals_test.ts +++ b/cli/js/tests/internals_test.ts @@ -5,6 +5,6 @@ unitTest(function internalsExists(): void { const { stringifyArgs, // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol - } = Deno[Deno.symbols.internal]; + } = Deno[Deno.internal]; assert(!!stringifyArgs); }); diff --git a/cli/js/tests/symbols_test.ts b/cli/js/tests/symbols_test.ts deleted file mode 100644 index ad05e9a706..0000000000 --- a/cli/js/tests/symbols_test.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { unitTest, assert } from "./test_util.ts"; - -unitTest(function symbolsExists(): void { - assert("internal" in Deno.symbols); - assert("customInspect" in Deno.symbols); -}); diff --git a/cli/js/tests/unit_test_runner.ts b/cli/js/tests/unit_test_runner.ts index 7a246cd39c..12d9101b85 100755 --- a/cli/js/tests/unit_test_runner.ts +++ b/cli/js/tests/unit_test_runner.ts @@ -11,8 +11,8 @@ import { reportToConn, } from "./test_util.ts"; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const internalObj = (Deno as any)[Deno.symbols.internal]; +// @ts-ignore +const internalObj = Deno[Deno.internal]; // eslint-disable-next-line @typescript-eslint/no-explicit-any const reportToConsole = internalObj.reportToConsole as (message: any) => void; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/cli/js/tests/unit_tests.ts b/cli/js/tests/unit_tests.ts index 74929c934b..627832ca9d 100644 --- a/cli/js/tests/unit_tests.ts +++ b/cli/js/tests/unit_tests.ts @@ -52,7 +52,6 @@ import "./request_test.ts"; import "./resources_test.ts"; import "./signal_test.ts"; import "./stat_test.ts"; -import "./symbols_test.ts"; import "./symlink_test.ts"; import "./text_encoding_test.ts"; import "./testing_test.ts"; diff --git a/cli/js/web/streams/readable_byte_stream_controller.ts b/cli/js/web/streams/readable_byte_stream_controller.ts index 615eff9681..80ba9ad850 100644 --- a/cli/js/web/streams/readable_byte_stream_controller.ts +++ b/cli/js/web/streams/readable_byte_stream_controller.ts @@ -22,7 +22,7 @@ import { import { ReadableStreamImpl } from "./readable_stream.ts"; import * as sym from "./symbols.ts"; import { assert } from "../../util.ts"; -import { symbols } from "../../symbols.ts"; +import { customInspect } from "../../web/console.ts"; export class ReadableByteStreamControllerImpl implements ReadableByteStreamController { @@ -135,7 +135,7 @@ export class ReadableByteStreamControllerImpl return promise; } - [symbols.customInspect](): string { + [customInspect](): string { return `ReadableByteStreamController { byobRequest: ${String( this.byobRequest )}, desiredSize: ${String(this.desiredSize)} }`; diff --git a/cli/js/web/streams/readable_stream.ts b/cli/js/web/streams/readable_stream.ts index f606319b16..e234c909de 100644 --- a/cli/js/web/streams/readable_stream.ts +++ b/cli/js/web/streams/readable_stream.ts @@ -18,8 +18,8 @@ import { ReadableByteStreamControllerImpl } from "./readable_byte_stream_control import { ReadableStreamAsyncIteratorPrototype } from "./readable_stream_async_iterator.ts"; import { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts"; import * as sym from "./symbols.ts"; -import { symbols } from "../../symbols.ts"; import { notImplemented } from "../../util.ts"; +import { customInspect } from "../../web/console.ts"; // eslint-disable-next-line @typescript-eslint/no-explicit-any export class ReadableStreamImpl implements ReadableStream { @@ -202,7 +202,7 @@ export class ReadableStreamImpl implements ReadableStream { return readableStreamTee(this, false); } - [symbols.customInspect](): string { + [customInspect](): string { return `ReadableStream { locked: ${String(this.locked)} }`; } diff --git a/cli/js/web/streams/readable_stream_default_controller.ts b/cli/js/web/streams/readable_stream_default_controller.ts index 866c6d79e3..bbdfa1f0d6 100644 --- a/cli/js/web/streams/readable_stream_default_controller.ts +++ b/cli/js/web/streams/readable_stream_default_controller.ts @@ -21,7 +21,7 @@ import { } from "./internals.ts"; import { ReadableStreamImpl } from "./readable_stream.ts"; import * as sym from "./symbols.ts"; -import { symbols } from "../../symbols.ts"; +import { customInspect } from "../../web/console.ts"; // eslint-disable-next-line @typescript-eslint/no-explicit-any export class ReadableStreamDefaultControllerImpl @@ -112,7 +112,7 @@ export class ReadableStreamDefaultControllerImpl return pendingPromise; } - [symbols.customInspect](): string { + [customInspect](): string { return `ReadableStreamDefaultController { desiredSize: ${String( this.desiredSize )} }`; diff --git a/cli/js/web/streams/readable_stream_default_reader.ts b/cli/js/web/streams/readable_stream_default_reader.ts index 9bdce3e9c9..20fb212081 100644 --- a/cli/js/web/streams/readable_stream_default_reader.ts +++ b/cli/js/web/streams/readable_stream_default_reader.ts @@ -12,7 +12,7 @@ import { } from "./internals.ts"; import { ReadableStreamImpl } from "./readable_stream.ts"; import * as sym from "./symbols.ts"; -import { symbols } from "../../symbols.ts"; +import { customInspect } from "../../web/console.ts"; // eslint-disable-next-line @typescript-eslint/no-explicit-any export class ReadableStreamDefaultReaderImpl @@ -83,7 +83,7 @@ export class ReadableStreamDefaultReaderImpl readableStreamReaderGenericRelease(this); } - [symbols.customInspect](): string { + [customInspect](): string { return `ReadableStreamDefaultReader { closed: Promise }`; } } diff --git a/cli/test_runner.rs b/cli/test_runner.rs index 0c2318052a..8ad42d161d 100644 --- a/cli/test_runner.rs +++ b/cli/test_runner.rs @@ -79,7 +79,7 @@ pub fn render_test_file( }; let run_tests_cmd = format!( - "(Deno as any)[Deno.symbols.internal].runTests({});\n", + "// @ts-ignore\nDeno[Deno.internal].runTests({});\n", options ); test_file.push_str(&run_tests_cmd);