From 79adc7b000a807caff01a3639b18cb91aef9bd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 21 Jun 2020 16:34:43 +0200 Subject: core: add Deno.core.dispatchByName (#6395) This commit adds alternate dispatch method to core JS API. "Deno.core.dispatchByName()" works like "Deno.core.dispatch()", but takes op name instead of op id as a first argument. --- core/core.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'core/core.js') diff --git a/core/core.js b/core/core.js index 23cc325ab..b3c0ddc13 100644 --- a/core/core.js +++ b/core/core.js @@ -37,6 +37,7 @@ SharedQueue Binary Layout let asyncHandlers; let initialized = false; + let opsCache = {}; function maybeInit() { if (!initialized) { @@ -61,7 +62,8 @@ SharedQueue Binary Layout // op id 0 is a special value to retrieve the map of registered ops. const opsMapBytes = send(0, new Uint8Array([])); const opsMapJson = String.fromCharCode.apply(null, opsMapBytes); - return JSON.parse(opsMapJson); + opsCache = JSON.parse(opsMapJson); + return { ...opsCache }; } function assert(cond) { @@ -181,9 +183,14 @@ SharedQueue Binary Layout } } + function dispatch(opName, control, ...zeroCopy) { + return send(opsCache[opName], control, ...zeroCopy); + } + Object.assign(window.Deno.core, { setAsyncHandler, dispatch: send, + dispatchByName: dispatch, ops, // sharedQueue is private but exposed for testing. sharedQueue: { -- cgit v1.2.3