mirror of
https://github.com/denoland/deno.git
synced 2024-12-02 17:01:14 -05:00
9ec4989776
This commit ensures that JavaScript functions generated for registered ops have proper names set up - the function name matches the name of the op. A test was added in `core/runtime.rs` that verifies this. Closes https://github.com/denoland/deno/issues/19206
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
if (!globalThis.Deno) {
|
|
globalThis.Deno = {
|
|
core: {
|
|
ops: {},
|
|
asyncOps: {},
|
|
},
|
|
};
|
|
}
|
|
|
|
Deno.__op__console = function (callConsole, console) {
|
|
Deno.core.callConsole = callConsole;
|
|
Deno.core.console = console;
|
|
};
|
|
|
|
Deno.__op__registerOp = function (isAsync, op, opName) {
|
|
const core = Deno.core;
|
|
if (isAsync) {
|
|
if (core.ops[opName] !== undefined) {
|
|
return;
|
|
}
|
|
core.asyncOps[opName] = op;
|
|
const fn = function (...args) {
|
|
if (this !== core.ops) {
|
|
// deno-lint-ignore prefer-primordials
|
|
throw new Error(
|
|
"An async stub cannot be separated from Deno.core.ops. Use ???",
|
|
);
|
|
}
|
|
return core.asyncStub(opName, args);
|
|
};
|
|
fn.name = opName;
|
|
core.ops[opName] = fn;
|
|
} else {
|
|
core.ops[opName] = op;
|
|
}
|
|
};
|
|
|
|
Deno.__op__unregisterOp = function (isAsync, opName) {
|
|
if (isAsync) {
|
|
delete Deno.core.asyncOps[opName];
|
|
}
|
|
delete Deno.core.ops[opName];
|
|
};
|
|
|
|
Deno.__op__cleanup = function () {
|
|
delete Deno.__op__console;
|
|
delete Deno.__op__registerOp;
|
|
delete Deno.__op__unregisterOp;
|
|
delete Deno.__op__cleanup;
|
|
};
|