diff options
Diffstat (limited to 'core/01_core.js')
-rw-r--r-- | core/01_core.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/core/01_core.js b/core/01_core.js index 75bfc884f..c3fd7cf9d 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -23,6 +23,7 @@ MapPrototypeSet, PromisePrototypeThen, ObjectAssign, + SymbolFor, } = window.__bootstrap.primordials; // Available on start due to bindings. @@ -43,6 +44,9 @@ const RING_SIZE = 4 * 1024; const NO_PROMISE = null; // Alias to null is faster than plain nulls const promiseRing = ArrayPrototypeFill(new Array(RING_SIZE), NO_PROMISE); + // TODO(bartlomieju): it future use `v8::Private` so it's not visible + // to users. Currently missing bindings. + const promiseIdSymbol = SymbolFor("Deno.core.internalPromiseId"); function setPromise(promiseId) { const idx = promiseId % RING_SIZE; @@ -135,7 +139,10 @@ const maybeError = opcallAsync(opsCache[opName], promiseId, arg1, arg2); // Handle sync error (e.g: error parsing args) if (maybeError) return unwrapOpResult(maybeError); - return PromisePrototypeThen(setPromise(promiseId), unwrapOpResult); + const p = PromisePrototypeThen(setPromise(promiseId), unwrapOpResult); + // Save the id on the promise so it can later be ref'ed or unref'ed + p[promiseIdSymbol] = promiseId; + return p; } function opSync(opName, arg1 = null, arg2 = null) { |