mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 13:14:48 +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
|
@ -9,8 +9,6 @@ import { setPrepareStackTrace } from "./error_stack.ts";
|
|||
import { Start, opStart } from "./ops/runtime.ts";
|
||||
import { handleTimerMacrotask } from "./web/timers.ts";
|
||||
|
||||
export let OPS_CACHE: { [name: string]: number };
|
||||
|
||||
function getAsyncHandler(opName: string): (msg: Uint8Array) => void {
|
||||
switch (opName) {
|
||||
case "op_write":
|
||||
|
@ -24,8 +22,8 @@ function getAsyncHandler(opName: string): (msg: Uint8Array) => void {
|
|||
// TODO(bartlomieju): temporary solution, must be fixed when moving
|
||||
// dispatches to separate crates
|
||||
export function initOps(): void {
|
||||
OPS_CACHE = core.ops();
|
||||
for (const [name, opId] of Object.entries(OPS_CACHE)) {
|
||||
const opsMap = core.ops();
|
||||
for (const [name, opId] of Object.entries(opsMap)) {
|
||||
core.setAsyncHandler(opId, getAsyncHandler(name));
|
||||
}
|
||||
core.setMacrotaskCallback(handleTimerMacrotask);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue