summaryrefslogtreecommitdiff
path: root/core/01_core.js
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2022-06-07 10:25:10 +0100
committerGitHub <noreply@github.com>2022-06-07 11:25:10 +0200
commit9385a913125df07f5216322e0b18aec1c6883957 (patch)
tree88705e174bf9ba5626a3c9a80911a56e77294682 /core/01_core.js
parentcfb6067f9bc0900a7d7fc6c75f19930542ed679c (diff)
refactor(core): Move Deno.core bindings to ops (#14793)
Diffstat (limited to 'core/01_core.js')
-rw-r--r--core/01_core.js77
1 files changed, 41 insertions, 36 deletions
diff --git a/core/01_core.js b/core/01_core.js
index d48424288..9337c0231 100644
--- a/core/01_core.js
+++ b/core/01_core.js
@@ -24,12 +24,10 @@
StringPrototypeSlice,
ObjectAssign,
SymbolFor,
+ setQueueMicrotask,
} = window.__bootstrap.primordials;
const ops = window.Deno.core.ops;
- // Available on start due to bindings.
- const { refOp_, unrefOp_ } = window.Deno.core;
-
const errorMap = {};
// Builtin v8 / JS errors
registerErrorClass("Error", Error);
@@ -176,53 +174,33 @@
if (!hasPromise(promiseId)) {
return;
}
- refOp_(promiseId);
+ opSync("op_ref_op", promiseId);
}
function unrefOp(promiseId) {
if (!hasPromise(promiseId)) {
return;
}
- unrefOp_(promiseId);
+ opSync("op_unref_op", promiseId);
}
function resources() {
return ObjectFromEntries(opSync("op_resources"));
}
- function read(rid, buf) {
- return opAsync("op_read", rid, buf);
- }
-
- function write(rid, buf) {
- return opAsync("op_write", rid, buf);
- }
-
- function shutdown(rid) {
- return opAsync("op_shutdown", rid);
- }
-
- function close(rid) {
- opSync("op_close", rid);
- }
-
- function tryClose(rid) {
- opSync("op_try_close", rid);
- }
-
- function print(str, isErr = false) {
- opSync("op_print", str, isErr);
- }
-
function metrics() {
const [aggregate, perOps] = opSync("op_metrics");
aggregate.ops = ObjectFromEntries(ArrayPrototypeMap(
- core.opNames(),
+ core.opSync("op_op_names"),
(opName, opId) => [opName, perOps[opId]],
));
return aggregate;
}
+ function queueMicrotask(...args) {
+ return opSync("op_queue_microtask", ...args);
+ }
+
// Some "extensions" rely on "BadResource" and "Interrupted" errors in the
// JS code (eg. "deno_net") so they are provided in "Deno.core" but later
// reexported on "Deno.errors"
@@ -246,12 +224,6 @@
const core = ObjectAssign(globalThis.Deno.core, {
opAsync,
opSync,
- close,
- tryClose,
- read,
- write,
- shutdown,
- print,
resources,
metrics,
registerErrorBuilder,
@@ -266,8 +238,41 @@
opCallTraces,
refOp,
unrefOp,
+ close: opSync.bind(null, "op_close"),
+ tryClose: opSync.bind(null, "op_try_close"),
+ read: opAsync.bind(null, "op_read"),
+ write: opAsync.bind(null, "op_write"),
+ shutdown: opAsync.bind(null, "op_shutdown"),
+ print: opSync.bind(null, "op_print"),
+ setMacrotaskCallback: opSync.bind(null, "op_set_macrotask_callback"),
+ setNextTickCallback: opSync.bind(null, "op_set_next_tick_callback"),
+ runMicrotasks: opSync.bind(null, "op_run_microtasks"),
+ hasTickScheduled: opSync.bind(null, "op_has_tick_scheduled"),
+ setHasTickScheduled: opSync.bind(null, "op_set_has_tick_scheduled"),
+ evalContext: opSync.bind(null, "op_eval_context"),
+ createHostObject: opSync.bind(null, "op_create_host_object"),
+ encode: opSync.bind(null, "op_encode"),
+ decode: opSync.bind(null, "op_decode"),
+ serialize: opSync.bind(null, "op_serialize"),
+ deserialize: opSync.bind(null, "op_deserialize"),
+ getPromiseDetails: opSync.bind(null, "op_get_promise_details"),
+ getProxyDetails: opSync.bind(null, "op_get_proxy_details"),
+ isProxy: opSync.bind(null, "op_is_proxy"),
+ memoryUsage: opSync.bind(null, "op_memory_usage"),
+ setWasmStreamingCallback: opSync.bind(
+ null,
+ "op_set_wasm_streaming_callback",
+ ),
+ abortWasmStreaming: opSync.bind(null, "op_abort_wasm_streaming"),
+ destructureError: opSync.bind(null, "op_destructure_error"),
+ terminate: opSync.bind(null, "op_terminate"),
+ opNames: opSync.bind(null, "op_op_names"),
});
ObjectAssign(globalThis.__bootstrap, { core });
ObjectAssign(globalThis.Deno, { core });
+
+ // Direct bindings on `globalThis`
+ ObjectAssign(globalThis, { queueMicrotask });
+ setQueueMicrotask(queueMicrotask);
})(globalThis);