diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2022-03-12 01:18:49 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-12 01:18:49 +0900 |
commit | b198bfd7950ce3f20aeaef265be59ff038fc4e11 (patch) | |
tree | 4be0fc3266d6507504eb2fdf8164a12b182d4acb /core/01_core.js | |
parent | f9b4d262b307649966b6433c72a9ee2b57bde8f7 (diff) |
refactor(core): validate promise id in refOp (#13905)
Diffstat (limited to 'core/01_core.js')
-rw-r--r-- | core/01_core.js | 29 |
1 files changed, 28 insertions, 1 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 }); |