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

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 <stibium121@gmail.com>
This commit is contained in:
Bartek Iwańczuk 2023-01-24 18:54:10 +01:00 committed by GitHub
parent 1084027d50
commit abd9610530
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 104 additions and 89 deletions

View file

@ -16,5 +16,5 @@ async function bench(fun) {
if (--total) queueMicrotask(() => bench(fun));
}
const { ops } = Deno.core;
const { ops } = Deno[Deno.internal].core;
bench(() => ops.op_void_async());

View file

@ -8,7 +8,7 @@ Deno.bench("date_now", { n: 5e5 }, () => {
// Fast API calls
{
// deno-lint-ignore camelcase
const { op_add } = Deno.core.ops;
const { op_add } = Deno[Deno.internal].core.ops;
// deno-lint-ignore no-inner-declarations
function add(a, b) {
return op_add(a, b);
@ -22,7 +22,7 @@ Deno.bench("date_now", { n: 5e5 }, () => {
}
// deno-lint-ignore camelcase
const { op_void_sync } = Deno.core.ops;
const { op_void_sync } = Deno[Deno.internal].core.ops;
function sync() {
return op_void_sync();
}
@ -34,7 +34,7 @@ Deno.bench("op_void_sync", () => sync());
Deno.bench(
"op_void_async",
{ n: 1e6 },
() => Deno.core.opAsync("op_void_async"),
() => Deno[Deno.internal].core.opAsync("op_void_async"),
);
// A very lightweight op, that should be highly optimizable

View file

@ -3,12 +3,10 @@
// deno-lint-ignore-file
const {
core: {
opAsync,
ops: { op_flash_make_request, op_flash_serve },
encode,
},
} = Deno;
opAsync,
ops: { op_flash_make_request, op_flash_serve },
encode,
} = Deno[Deno.internal].core;
const addr = Deno.args[0] || "127.0.0.1:4500";
const [hostname, port] = addr.split(":");
const serverId = op_flash_serve({ hostname, port, reuseport: true });

View file

@ -13,7 +13,10 @@ class Http {
[Symbol.asyncIterator]() {
return {
next: async () => {
const reqEvt = await Deno.core.opAsync("op_http_accept", this.id);
const reqEvt = await Deno[Deno.internal].core.opAsync(
"op_http_accept",
this.id,
);
return { value: reqEvt ?? undefined, done: reqEvt === null };
},
};
@ -21,20 +24,20 @@ class Http {
}
for await (const conn of tcp) {
const id = Deno.core.ops.op_http_start(conn.rid);
const id = Deno[Deno.internal].core.ops.op_http_start(conn.rid);
const http = new Http(id);
(async () => {
for await (const req of http) {
if (req == null) continue;
const { 0: stream } = req;
await Deno.core.opAsync(
await Deno[Deno.internal].core.opAsync(
"op_http_write_headers",
stream,
200,
[],
"Hello World",
);
Deno.core.close(stream);
Deno[Deno.internal].core.close(stream);
}
})();
}

View file

@ -1,5 +1,7 @@
const { serve, upgradeHttpRaw } = Deno;
const u8 = Deno.core.encode("HTTP/1.1 101 Switching Protocols\r\n\r\n");
const u8 = Deno[Deno.internal].core.encode(
"HTTP/1.1 101 Switching Protocols\r\n\r\n",
);
async function handler(req) {
const [conn, _firstPacket] = upgradeHttpRaw(req);

View file

@ -318,7 +318,7 @@ async fn inspector_break_on_first_line() {
"id":4,
"method":"Runtime.evaluate",
"params":{
"expression":"Deno.core.print(\"hello from the inspector\\n\")",
"expression":"Deno[Deno.internal].core.print(\"hello from the inspector\\n\")",
"contextId":1,
"includeCommandLineAPI":true,
"silent":false,

View file

@ -1,6 +1,6 @@
Deno.core.ops.op_pledge_test_permissions(
Deno[Deno.internal].core.ops.op_pledge_test_permissions(
"none",
);
Deno.core.ops.op_pledge_test_permissions(
Deno[Deno.internal].core.ops.op_pledge_test_permissions(
"inherit",
);

View file

@ -4,7 +4,7 @@ function childProcessFork(path) {
const p = Deno.run({
cmd: [Deno.execPath(), "run", "--unstable", "-A", path],
env: {
"DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE": Deno.core.ops.op_npm_process_state(),
"DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE": Deno[Deno.internal].core.ops.op_npm_process_state(),
}
});
p.status().then(() => {

View file

@ -1,4 +1,4 @@
// @ts-expect-error "Deno.core" is not a public interface
Deno.core.evalContext(
// @ts-expect-error "Deno[Deno.internal].core" is not a public interface
Deno[Deno.internal].core.evalContext(
"(async () => console.log(await import('./subdir/mod4.js')))()",
);

View file

@ -1,2 +1,4 @@
const [, errorInfo] = Deno.core.evalContext('throw new DOMException("foo")');
const [, errorInfo] = Deno[Deno.internal].core.evalContext(
'throw new DOMException("foo")',
);
console.log(errorInfo);

View file

@ -4,9 +4,9 @@ addEventListener("foo", () => {
throw new Error("bar");
});
console.log(1);
// @ts-ignore Deno.core
Deno.core.setNextTickCallback(() => console.log("nextTick"));
// @ts-ignore Deno.core
Deno.core.setHasTickScheduled(true);
// @ts-ignore Deno[Deno.internal].core
Deno[Deno.internal].core.setNextTickCallback(() => console.log("nextTick"));
// @ts-ignore Deno[Deno.internal].core
Deno[Deno.internal].core.setHasTickScheduled(true);
dispatchEvent(new CustomEvent("foo"));
console.log(2);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_load({ path: "", symbols: {} });
Deno[Deno.internal].core.ops.op_ffi_load({ path: "", symbols: {} });

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_i16(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_read_i16(0n, 0);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_u32(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_read_u32(0n, 0);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_i32(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_read_i32(0n, 0);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_u64(0n, 0, new Uint32Array(2));
Deno[Deno.internal].core.ops.op_ffi_read_u64(0n, 0, new Uint32Array(2));

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_f32(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_read_f32(0n, 0);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_f64(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_read_f64(0n, 0);

View file

@ -1,4 +1,4 @@
Deno.core.ops.op_ffi_call_ptr(0n, {
Deno[Deno.internal].core.ops.op_ffi_call_ptr(0n, {
name: null,
parameters: [],
result: "void",

View file

@ -1,4 +1,4 @@
Deno.core.opAsync("op_ffi_call_ptr_nonblocking", 0n, {
Deno[Deno.internal].core.opAsync("op_ffi_call_ptr_nonblocking", 0n, {
name: null,
parameters: [],
result: "void",

View file

@ -1 +1,4 @@
Deno.core.ops.op_ffi_ptr_of(new Uint8Array(0), new Uint32Array(2));
Deno[Deno.internal].core.ops.op_ffi_ptr_of(
new Uint8Array(0),
new Uint32Array(2),
);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_buf_copy_into(0n, 0, new Uint8Array(0), 0);
Deno[Deno.internal].core.ops.op_ffi_buf_copy_into(0n, 0, new Uint8Array(0), 0);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_cstr_read(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_cstr_read(0n, 0);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_u8(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_read_u8(0n, 0);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_i8(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_read_i8(0n, 0);

View file

@ -1 +1 @@
Deno.core.ops.op_ffi_read_u16(0n, 0);
Deno[Deno.internal].core.ops.op_ffi_read_u16(0n, 0);

View file

@ -8,7 +8,7 @@ function assertEquals(a, b) {
const registry = new FinalizationRegistry((value) => {
assertEquals(value, "called!");
Deno.core.print("FinalizationRegistry called!\n");
Deno[Deno.internal].core.print("FinalizationRegistry called!\n");
});
(function () {

View file

@ -2,8 +2,8 @@
// setting exit code in worker context is a no-op and is an alias for
// `self.close()`.
// @ts-ignore Deno.core doesn't have type-defs
Deno.core.ops.op_set_exit_code(21);
// @ts-ignore Deno[Deno.internal].core doesn't have type-defs
Deno[Deno.internal].core.ops.op_set_exit_code(21);
const worker = new Worker(
import.meta.resolve("./op_exit_op_set_exit_code_worker.js"),

View file

@ -1,4 +1,4 @@
self.onmessage = () => {
Deno.core.ops.op_set_exit_code(42);
Deno[Deno.internal].core.ops.op_set_exit_code(42);
Deno.exit();
};

View file

@ -1,2 +1,2 @@
Deno.core.ops.op_set_exit_code(42);
Deno[Deno.internal].core.ops.op_set_exit_code(42);
Deno.exit(0); // Takes precedence.

View file

@ -1,2 +1,2 @@
Deno.core.ops.op_set_exit_code(42);
Deno[Deno.internal].core.ops.op_set_exit_code(42);
Deno.exit();

View file

@ -1,2 +1,2 @@
Deno.core.ops.op_set_exit_code(42);
Deno[Deno.internal].core.ops.op_set_exit_code(42);
// Exits naturally.

View file

@ -1,6 +1,6 @@
Deno.core.ops.op_pledge_test_permissions(
Deno[Deno.internal].core.ops.op_pledge_test_permissions(
"none",
);
Deno.core.ops.op_pledge_test_permissions(
Deno[Deno.internal].core.ops.op_pledge_test_permissions(
"inherit",
);

View file

@ -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() {

View file

@ -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"
),
);
});

View file

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

View file

@ -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<unknown>, parentPromise?: Promise<unknown>) => {
outputArray.push(
`init ${identify(promise)}` +

View file

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

View file

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

View file

@ -186,7 +186,7 @@ impl CliMainWorker {
if self.ps.options.trace_ops() {
self.worker.js_runtime.execute_script(
&located_script_name!(),
"Deno.core.enableOpCallTracing();",
"Deno[Deno.internal].core.enableOpCallTracing();",
)?;
}
@ -231,7 +231,7 @@ impl CliMainWorker {
self.worker.execute_script(
&located_script_name!(),
"Deno.core.enableOpCallTracing();",
"Deno[Deno.internal].core.enableOpCallTracing();",
)?;
if mode != TestMode::Documentation {

View file

@ -485,8 +485,14 @@ delete Intl.v8BreakIterator;
},
});
const finalDenoNs = {
// FIXME(bartlomieju): temporarily add whole `Deno.core` to
// `Deno[Deno.internal]` namespace. It should be removed and only necessary
// methods should be left there.
ObjectAssign(internals, {
core,
});
const finalDenoNs = {
internal: internalSymbol,
[internalSymbol]: internals,
resources: core.resources,
@ -524,7 +530,6 @@ delete Intl.v8BreakIterator;
// Setup `Deno` global - we're actually overriding already existing global
// `Deno` with `Deno` namespace from "./deno.ts".
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
ObjectFreeze(globalThis.Deno.core);
util.log("args", runtimeOptions.args);
}
@ -625,8 +630,14 @@ delete Intl.v8BreakIterator;
},
});
const finalDenoNs = {
// FIXME(bartlomieju): temporarily add whole `Deno.core` to
// `Deno[Deno.internal]` namespace. It should be removed and only necessary
// methods should be left there.
ObjectAssign(internals, {
core,
});
const finalDenoNs = {
internal: internalSymbol,
[internalSymbol]: internals,
resources: core.resources,
@ -660,7 +671,6 @@ delete Intl.v8BreakIterator;
// Setup `Deno` global - we're actually overriding already
// existing global `Deno` with `Deno` namespace from "./deno.ts".
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
ObjectFreeze(globalThis.Deno.core);
}
ObjectDefineProperties(globalThis, {

View file

@ -17,5 +17,5 @@ const [libPrefix, libSuffix] = {
export function loadTestLibrary() {
const specifier = `${targetDir}/${libPrefix}test_napi.${libSuffix}`;
return Deno.core.ops.op_napi_open(specifier); // Internal, used in ext/node
return Deno[Deno.internal].core.ops.op_napi_open(specifier); // Internal, used in ext/node
}

View file

@ -185,9 +185,9 @@ async function generateBundle(location: URL): Promise<string> {
return scriptContents.map(([url, contents]) => `
(function() {
const [_,err] = Deno.core.evalContext(${JSON.stringify(contents)}, ${
JSON.stringify(url)
});
const [_,err] = Deno[Deno.internal].core.evalContext(${
JSON.stringify(contents)
}, ${JSON.stringify(url)});
if (err !== null) {
throw err?.thrown;
}