mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +00:00
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.
This commit is contained in:
parent
86448fd9aa
commit
79adc7b000
6 changed files with 27 additions and 41 deletions
|
@ -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: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue