summaryrefslogtreecommitdiff
path: root/core/core.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-06-21 16:34:43 +0200
committerGitHub <noreply@github.com>2020-06-21 16:34:43 +0200
commit79adc7b000a807caff01a3639b18cb91aef9bd9c (patch)
tree8592baf9a2d88aea7a55f55903739b63bd23fded /core/core.js
parent86448fd9aaa9d70078f7928c9ea1d5af2679ea08 (diff)
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.
Diffstat (limited to 'core/core.js')
-rw-r--r--core/core.js9
1 files changed, 8 insertions, 1 deletions
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: {