diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-03-14 23:14:15 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 18:44:15 +0100 |
commit | b4e42953e1d243f2eda20e5be6b845d60b7bf688 (patch) | |
tree | 10b3bfff165f9c04f9174c7c399d44b9b724c3b3 /core/01_core.js | |
parent | 4e3ed37037a2aa1edeac260dc3463a81d9cf9b88 (diff) |
feat(core): codegen ops (#13861)
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
Diffstat (limited to 'core/01_core.js')
-rw-r--r-- | core/01_core.js | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/core/01_core.js b/core/01_core.js index b6c72e5d2..747d69241 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -16,7 +16,6 @@ ErrorCaptureStackTrace, Promise, ObjectEntries, - ObjectFreeze, ObjectFromEntries, MapPrototypeGet, MapPrototypeDelete, @@ -27,11 +26,12 @@ ObjectAssign, SymbolFor, } = window.__bootstrap.primordials; + const ops = window.Deno.core.ops; + const opIds = Object.keys(ops).reduce((a, v, i) => ({ ...a, [v]: i }), {}); // Available on start due to bindings. - const { opcallSync, opcallAsync, refOp_, unrefOp_ } = window.Deno.core; + const { refOp_, unrefOp_ } = window.Deno.core; - let opsCache = {}; const errorMap = {}; // Builtin v8 / JS errors registerErrorClass("Error", Error); @@ -110,15 +110,6 @@ return promiseRing[idx] != NO_PROMISE; } - function ops() { - return opsCache; - } - - function syncOpsCache() { - // op id 0 is a special value to retrieve the map of registered ops. - opsCache = ObjectFreeze(ObjectFromEntries(opcallSync(0))); - } - function opresolve() { for (let i = 0; i < arguments.length; i += 2) { const promiseId = arguments[i]; @@ -160,7 +151,7 @@ function opAsync(opName, arg1 = null, arg2 = null) { const promiseId = nextPromiseId++; - const maybeError = opcallAsync(opsCache[opName], promiseId, arg1, arg2); + const maybeError = ops[opName](opIds[opName], promiseId, arg1, arg2); // Handle sync error (e.g: error parsing args) if (maybeError) return unwrapOpResult(maybeError); let p = PromisePrototypeThen(setPromise(promiseId), unwrapOpResult); @@ -179,8 +170,8 @@ return p; } - function opSync(opName, arg1 = null, arg2 = null) { - return unwrapOpResult(opcallSync(opsCache[opName], arg1, arg2)); + function opSync(opName, arg1, arg2) { + return unwrapOpResult(ops[opName](opIds[opName], arg1, arg2)); } function refOp(promiseId) { @@ -228,7 +219,7 @@ function metrics() { const [aggregate, perOps] = opSync("op_metrics"); aggregate.ops = ObjectFromEntries(ArrayPrototypeMap( - ObjectEntries(opsCache), + ObjectEntries(opIds), ([opName, opId]) => [opName, perOps[opId]], )); return aggregate; @@ -257,7 +248,6 @@ const core = ObjectAssign(globalThis.Deno.core, { opAsync, opSync, - ops, close, tryClose, read, @@ -269,7 +259,6 @@ registerErrorBuilder, registerErrorClass, opresolve, - syncOpsCache, BadResource, BadResourcePrototype, Interrupted, |