summaryrefslogtreecommitdiff
path: root/core/runtime/bindings.js
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-06-13 20:03:10 -0600
committerGitHub <noreply@github.com>2023-06-14 02:03:10 +0000
commitec8e9d4f5bd2c8eed5f086356c1c6dd7c8b40b7f (patch)
tree2ffda9204901bfb757e8ce6359d1fc6aa2f9964b /core/runtime/bindings.js
parentfd9d6baea311d9b227b130749647a86838ba2ccc (diff)
chore(core): Refactor runtime and split out tests (#19491)
This is a quick first refactoring to split the tests out of runtime and move runtime-related code to a top-level runtime module. There will be a followup to refactor imports a bit, but this is the major change that will most likely conflict with other work and I want to merge it early.
Diffstat (limited to 'core/runtime/bindings.js')
-rw-r--r--core/runtime/bindings.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/core/runtime/bindings.js b/core/runtime/bindings.js
new file mode 100644
index 000000000..21d27a2c3
--- /dev/null
+++ b/core/runtime/bindings.js
@@ -0,0 +1,51 @@
+// 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;
+};