summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/01_core.js29
-rw-r--r--core/bindings.rs4
2 files changed, 30 insertions, 3 deletions
diff --git a/core/01_core.js b/core/01_core.js
index 50d4537f0..b6c72e5d2 100644
--- a/core/01_core.js
+++ b/core/01_core.js
@@ -29,7 +29,7 @@
} = window.__bootstrap.primordials;
// Available on start due to bindings.
- const { opcallSync, opcallAsync } = window.Deno.core;
+ const { opcallSync, opcallAsync, refOp_, unrefOp_ } = window.Deno.core;
let opsCache = {};
const errorMap = {};
@@ -99,6 +99,17 @@
return promise;
}
+ function hasPromise(promiseId) {
+ // Check if out of ring bounds, fallback to map
+ const outOfBounds = promiseId < nextPromiseId - RING_SIZE;
+ if (outOfBounds) {
+ return MapPrototypeHas(promiseMap, promiseId);
+ }
+ // Otherwise check it in ring
+ const idx = promiseId % RING_SIZE;
+ return promiseRing[idx] != NO_PROMISE;
+ }
+
function ops() {
return opsCache;
}
@@ -172,6 +183,20 @@
return unwrapOpResult(opcallSync(opsCache[opName], arg1, arg2));
}
+ function refOp(promiseId) {
+ if (!hasPromise(promiseId)) {
+ return;
+ }
+ refOp_(promiseId);
+ }
+
+ function unrefOp(promiseId) {
+ if (!hasPromise(promiseId)) {
+ return;
+ }
+ unrefOp_(promiseId);
+ }
+
function resources() {
return ObjectFromEntries(opSync("op_resources"));
}
@@ -252,6 +277,8 @@
enableOpCallTracing,
isOpCallTracingEnabled,
opCallTraces,
+ refOp,
+ unrefOp,
});
ObjectAssign(globalThis.__bootstrap, { core });
diff --git a/core/bindings.rs b/core/bindings.rs
index 084d30a15..f84711abf 100644
--- a/core/bindings.rs
+++ b/core/bindings.rs
@@ -173,8 +173,8 @@ pub fn initialize_context<'s>(
// Bind functions to Deno.core.*
set_func(scope, core_val, "opcallSync", opcall_sync);
set_func(scope, core_val, "opcallAsync", opcall_async);
- set_func(scope, core_val, "refOp", ref_op);
- set_func(scope, core_val, "unrefOp", unref_op);
+ set_func(scope, core_val, "refOp_", ref_op);
+ set_func(scope, core_val, "unrefOp_", unref_op);
set_func(
scope,
core_val,