From abd96105300a7729a4d8eb69af2e81dd6307a163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 24 Jan 2023 18:54:10 +0100 Subject: refactor: remove Deno.core (#16881) This commit removes "Deno.core" namespace. It is strictly private API that has no stability guarantees, we were supposed to remove it long time ago. Co-authored-by: Yoshiya Hinosawa --- cli/tests/unit/globals_test.ts | 18 +++++++----------- cli/tests/unit/metrics_test.ts | 12 +++++++----- cli/tests/unit/opcall_test.ts | 15 +++++++-------- cli/tests/unit/promise_hooks_test.ts | 4 ++-- cli/tests/unit/ref_unref_test.ts | 2 +- cli/tests/unit/text_encoding_test.ts | 4 ++-- 6 files changed, 26 insertions(+), 29 deletions(-) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/globals_test.ts b/cli/tests/unit/globals_test.ts index cf7293bba..c63b28973 100644 --- a/cli/tests/unit/globals_test.ts +++ b/cli/tests/unit/globals_test.ts @@ -71,12 +71,8 @@ Deno.test(function webAssemblyExists() { assert(typeof WebAssembly.compile === "function"); }); -declare global { - namespace Deno { - // deno-lint-ignore no-explicit-any, no-var - var core: any; - } -} +// @ts-ignore This is not publicly typed namespace, but it's there for sure. +const core = Deno[Deno.internal].core; Deno.test(function DenoNamespaceConfigurable() { const desc = Object.getOwnPropertyDescriptor(globalThis, "Deno"); @@ -86,19 +82,19 @@ Deno.test(function DenoNamespaceConfigurable() { }); Deno.test(function DenoCoreNamespaceIsImmutable() { - const { print } = Deno.core; + const { print } = core; try { - Deno.core.print = 1; + core.print = 1; } catch { // pass } - assert(print === Deno.core.print); + assert(print === core.print); try { - delete Deno.core.print; + delete core.print; } catch { // pass } - assert(print === Deno.core.print); + assert(print === core.print); }); Deno.test(async function windowQueueMicrotask() { diff --git a/cli/tests/unit/metrics_test.ts b/cli/tests/unit/metrics_test.ts index 5ada58b97..df2f1b2be 100644 --- a/cli/tests/unit/metrics_test.ts +++ b/cli/tests/unit/metrics_test.ts @@ -77,13 +77,15 @@ Deno.test(function metricsForOpCrates() { assert(m1.opsCompleted > 0); }); -// Test that op_names == Objects.keys(Deno.core.ops) +// Test that op_names == Objects.keys(Deno[Deno.internal].core.ops) // since building the per-op metrics depends on op_names being complete Deno.test(function opNamesMatch() { assertEquals( - // @ts-ignore: Deno.core allowed - Deno.core.opNames().sort(), - // @ts-ignore: Deno.core allowed - Object.keys(Deno.core.ops).sort().filter((name) => name !== "asyncOpsInfo"), + // @ts-ignore: Deno[Deno.internal].core allowed + Deno[Deno.internal].core.opNames().sort(), + // @ts-ignore: Deno[Deno.internal].core allowed + Object.keys(Deno[Deno.internal].core.ops).sort().filter((name) => + name !== "asyncOpsInfo" + ), ); }); diff --git a/cli/tests/unit/opcall_test.ts b/cli/tests/unit/opcall_test.ts index 61c3c8849..3f4f4472c 100644 --- a/cli/tests/unit/opcall_test.ts +++ b/cli/tests/unit/opcall_test.ts @@ -22,17 +22,13 @@ Deno.test(async function sendAsyncStackTrace() { } }); -declare global { - namespace Deno { - // deno-lint-ignore no-explicit-any, no-var - var core: any; - } -} +// @ts-ignore This is not publicly typed namespace, but it's there for sure. +const core = Deno[Deno.internal].core; Deno.test(async function opsAsyncBadResource() { try { const nonExistingRid = 9999; - await Deno.core.read( + await core.read( nonExistingRid, new Uint8Array(0), ); @@ -46,7 +42,10 @@ Deno.test(async function opsAsyncBadResource() { Deno.test(function opsSyncBadResource() { try { const nonExistingRid = 9999; - Deno.core.ops.op_read_sync(nonExistingRid, new Uint8Array(0)); + core.ops.op_read_sync( + nonExistingRid, + new Uint8Array(0), + ); } catch (e) { if (!(e instanceof Deno.errors.BadResource)) { throw e; diff --git a/cli/tests/unit/promise_hooks_test.ts b/cli/tests/unit/promise_hooks_test.ts index cbdb6320a..a0883d4b5 100644 --- a/cli/tests/unit/promise_hooks_test.ts +++ b/cli/tests/unit/promise_hooks_test.ts @@ -12,8 +12,8 @@ function monitorPromises(outputArray: string[]) { return promiseIds.get(promise); } - // @ts-ignore: Deno.core allowed - Deno.core.setPromiseHooks( + // @ts-ignore: Deno[Deno.internal].core allowed + Deno[Deno.internal].core.setPromiseHooks( (promise: Promise, parentPromise?: Promise) => { outputArray.push( `init ${identify(promise)}` + diff --git a/cli/tests/unit/ref_unref_test.ts b/cli/tests/unit/ref_unref_test.ts index 7ce72a170..eea93b165 100644 --- a/cli/tests/unit/ref_unref_test.ts +++ b/cli/tests/unit/ref_unref_test.ts @@ -4,7 +4,7 @@ import { assertNotEquals, execCode } from "./test_util.ts"; Deno.test("[unrefOp] unref'ing invalid ops does not have effects", async () => { const [statusCode, _] = await execCode(` - Deno.core.unrefOp(-1); + Deno[Deno.internal].core.unrefOp(-1); setTimeout(() => { throw new Error() }, 10) `); // Invalid unrefOp call doesn't affect exit condition of event loop diff --git a/cli/tests/unit/text_encoding_test.ts b/cli/tests/unit/text_encoding_test.ts index 78e4267a9..940dd9f74 100644 --- a/cli/tests/unit/text_encoding_test.ts +++ b/cli/tests/unit/text_encoding_test.ts @@ -264,8 +264,8 @@ Deno.test(function textEncoderShouldCoerceToString() { }); Deno.test(function binaryEncode() { - // @ts-ignore: Deno.core allowed - const ops = Deno.core.ops; + // @ts-ignore: Deno[Deno.internal].core allowed + const ops = Deno[Deno.internal].core.ops; function asBinaryString(bytes: Uint8Array): string { return Array.from(bytes).map( (v: number) => String.fromCodePoint(v), -- cgit v1.2.3