summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
authorKenta Moriuchi <moriken@kimamass.com>2024-01-11 07:37:25 +0900
committerGitHub <noreply@github.com>2024-01-10 15:37:25 -0700
commit515a34b4de222e35c7ade1b92614d746e73d4c2e (patch)
tree8284201fc826a33f12597959a8a8be14e0f524bd /runtime/js
parentd4893eb51a01c5a692d8ca74a3b8ff95c5fd1d9f (diff)
refactor: use `core.ensureFastOps()` (#21888)
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/01_version.ts6
-rw-r--r--runtime/js/06_util.js6
-rw-r--r--runtime/js/10_permissions.js17
-rw-r--r--runtime/js/11_workers.js19
-rw-r--r--runtime/js/13_buffer.js5
-rw-r--r--runtime/js/30_os.js53
-rw-r--r--runtime/js/40_fs_events.js15
-rw-r--r--runtime/js/40_http.js7
-rw-r--r--runtime/js/40_process.js29
-rw-r--r--runtime/js/40_signals.js13
-rw-r--r--runtime/js/40_tty.js9
-rw-r--r--runtime/js/41_prompt.js9
-rw-r--r--runtime/js/90_deno_ns.js16
-rw-r--r--runtime/js/98_global_scope_window.js12
-rw-r--r--runtime/js/98_global_scope_worker.js12
15 files changed, 147 insertions, 81 deletions
diff --git a/runtime/js/01_version.ts b/runtime/js/01_version.ts
index e0a187961..33a8f50cd 100644
--- a/runtime/js/01_version.ts
+++ b/runtime/js/01_version.ts
@@ -1,7 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-const primordials = globalThis.__bootstrap.primordials;
-const { ObjectFreeze } = primordials;
+import { primordials } from "ext:core/mod.js";
+const {
+ ObjectFreeze,
+} = primordials;
interface Version {
deno: string;
diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js
index 31eed51e3..64ec4ba9b 100644
--- a/runtime/js/06_util.js
+++ b/runtime/js/06_util.js
@@ -1,7 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_bootstrap_log_level,
+} = core.ensureFastOps();
const {
Promise,
SafeArrayIterator,
@@ -20,7 +22,7 @@ const logSource = "JS";
let logLevel_ = null;
function logLevel() {
if (logLevel_ === null) {
- logLevel_ = ops.op_bootstrap_log_level() || 3;
+ logLevel_ = op_bootstrap_log_level() || 3;
}
return logLevel_;
}
diff --git a/runtime/js/10_permissions.js b/runtime/js/10_permissions.js
index 60dd61f2c..19923a342 100644
--- a/runtime/js/10_permissions.js
+++ b/runtime/js/10_permissions.js
@@ -1,9 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const ops = core.ops;
-import { pathFromURL } from "ext:deno_web/00_infra.js";
-import { Event, EventTarget } from "ext:deno_web/02_event.js";
+const {
+ op_query_permission,
+ op_request_permission,
+ op_revoke_permission,
+} = core.ensureFastOps();
const {
ArrayIsArray,
ArrayPrototypeIncludes,
@@ -23,6 +25,9 @@ const {
TypeError,
} = primordials;
+import { pathFromURL } from "ext:deno_web/00_infra.js";
+import { Event, EventTarget } from "ext:deno_web/02_event.js";
+
const illegalConstructorKey = Symbol("illegalConstructorKey");
/**
@@ -49,7 +54,7 @@ const permissionNames = [
* @returns {Deno.PermissionState}
*/
function opQuery(desc) {
- return ops.op_query_permission(desc);
+ return op_query_permission(desc);
}
/**
@@ -57,7 +62,7 @@ function opQuery(desc) {
* @returns {Deno.PermissionState}
*/
function opRevoke(desc) {
- return ops.op_revoke_permission(desc);
+ return op_revoke_permission(desc);
}
/**
@@ -65,7 +70,7 @@ function opRevoke(desc) {
* @returns {Deno.PermissionState}
*/
function opRequest(desc) {
- return ops.op_request_permission(desc);
+ return op_request_permission(desc);
}
class PermissionStatus extends EventTarget {
diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js
index 473691014..774fd3434 100644
--- a/runtime/js/11_workers.js
+++ b/runtime/js/11_workers.js
@@ -1,7 +1,13 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_create_worker,
+ op_host_post_message,
+ op_host_recv_ctrl,
+ op_host_recv_message,
+ op_host_terminate_worker,
+} = core.ensureFastOps();
const {
ArrayPrototypeFilter,
Error,
@@ -12,6 +18,7 @@ const {
SymbolIterator,
SymbolToStringTag,
} = primordials;
+
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { URL } from "ext:deno_url/00_url.js";
@@ -30,10 +37,6 @@ import {
MessagePortPrototype,
serializeJsMessageData,
} from "ext:deno_web/13_message_port.js";
-const {
- op_host_recv_ctrl,
- op_host_recv_message,
-} = core.ensureFastOps();
function createWorker(
specifier,
@@ -43,7 +46,7 @@ function createWorker(
name,
workerType,
) {
- return ops.op_create_worker({
+ return op_create_worker({
hasSourceCode,
name,
permissions: serializePermissions(permissions),
@@ -54,11 +57,11 @@ function createWorker(
}
function hostTerminateWorker(id) {
- ops.op_host_terminate_worker(id);
+ op_host_terminate_worker(id);
}
function hostPostMessage(id, data) {
- ops.op_host_post_message(id, data);
+ op_host_post_message(id, data);
}
function hostRecvCtrl(id) {
diff --git a/runtime/js/13_buffer.js b/runtime/js/13_buffer.js
index 0692939de..36d979e75 100644
--- a/runtime/js/13_buffer.js
+++ b/runtime/js/13_buffer.js
@@ -4,8 +4,7 @@
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
// https://github.com/golang/go/blob/master/LICENSE
-import { assert } from "ext:deno_web/00_infra.js";
-const primordials = globalThis.__bootstrap.primordials;
+import { primordials } from "ext:core/mod.js";
const {
ArrayBufferPrototypeGetByteLength,
TypedArrayPrototypeSubarray,
@@ -20,6 +19,8 @@ const {
Error,
} = primordials;
+import { assert } from "ext:deno_web/00_infra.js";
+
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
// buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond
// what is required to hold the contents of r, readFrom() will not grow the
diff --git a/runtime/js/30_os.js b/runtime/js/30_os.js
index 5f88bd27e..b35f34e1a 100644
--- a/runtime/js/30_os.js
+++ b/runtime/js/30_os.js
@@ -1,49 +1,68 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const ops = core.ops;
-import { Event, EventTarget } from "ext:deno_web/02_event.js";
+const {
+ op_delete_env,
+ op_env,
+ op_exec_path,
+ op_exit,
+ op_get_env,
+ op_gid,
+ op_hostname,
+ op_loadavg,
+ op_network_interfaces,
+ op_os_release,
+ op_os_uptime,
+ op_set_env,
+ op_system_memory_info,
+ op_uid,
+} = core.ensureFastOps();
+const {
+ op_set_exit_code,
+} = core.ensureFastOps(true);
const {
Error,
FunctionPrototypeBind,
SymbolFor,
} = primordials;
+import { Event, EventTarget } from "ext:deno_web/02_event.js";
+
const windowDispatchEvent = FunctionPrototypeBind(
EventTarget.prototype.dispatchEvent,
globalThis,
);
function loadavg() {
- return ops.op_loadavg();
+ return op_loadavg();
}
function hostname() {
- return ops.op_hostname();
+ return op_hostname();
}
function osRelease() {
- return ops.op_os_release();
+ return op_os_release();
}
function osUptime() {
- return ops.op_os_uptime();
+ return op_os_uptime();
}
function systemMemoryInfo() {
- return ops.op_system_memory_info();
+ return op_system_memory_info();
}
function networkInterfaces() {
- return ops.op_network_interfaces();
+ return op_network_interfaces();
}
function gid() {
- return ops.op_gid();
+ return op_gid();
}
function uid() {
- return ops.op_uid();
+ return op_uid();
}
// This is an internal only method used by the test harness to override the
@@ -56,7 +75,7 @@ function setExitHandler(fn) {
function exit(code) {
// Set exit code first so unload event listeners can override it.
if (typeof code === "number") {
- ops.op_set_exit_code(code);
+ op_set_exit_code(code);
} else {
code = 0;
}
@@ -73,26 +92,26 @@ function exit(code) {
return;
}
- ops.op_exit();
+ op_exit();
throw new Error("Code not reachable");
}
function setEnv(key, value) {
- ops.op_set_env(key, value);
+ op_set_env(key, value);
}
function getEnv(key) {
- return ops.op_get_env(key) ?? undefined;
+ return op_get_env(key) ?? undefined;
}
function deleteEnv(key) {
- ops.op_delete_env(key);
+ op_delete_env(key);
}
const env = {
get: getEnv,
toObject() {
- return ops.op_env();
+ return op_env();
},
set: setEnv,
has(key) {
@@ -102,7 +121,7 @@ const env = {
};
function execPath() {
- return ops.op_exec_path();
+ return op_exec_path();
}
export {
diff --git a/runtime/js/40_fs_events.js b/runtime/js/40_fs_events.js
index d5af0359b..13cacc36b 100644
--- a/runtime/js/40_fs_events.js
+++ b/runtime/js/40_fs_events.js
@@ -1,24 +1,29 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const { BadResourcePrototype, InterruptedPrototype, ops } = core;
+const {
+ BadResourcePrototype,
+ InterruptedPrototype,
+} = core;
+const {
+ op_fs_events_open,
+ op_fs_events_poll,
+} = core.ensureFastOps();
const {
ArrayIsArray,
ObjectPrototypeIsPrototypeOf,
PromiseResolve,
SymbolAsyncIterator,
} = primordials;
+
import { SymbolDispose } from "ext:deno_web/00_infra.js";
-const {
- op_fs_events_poll,
-} = core.ensureFastOps();
class FsWatcher {
#rid = 0;
constructor(paths, options) {
const { recursive } = options;
- this.#rid = ops.op_fs_events_open({ recursive, paths });
+ this.#rid = op_fs_events_open({ recursive, paths });
}
get rid() {
diff --git a/runtime/js/40_http.js b/runtime/js/40_http.js
index 6ec8f4314..d38caa55d 100644
--- a/runtime/js/40_http.js
+++ b/runtime/js/40_http.js
@@ -1,10 +1,13 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_http_start,
+} = core.ensureFastOps();
+
import { HttpConn } from "ext:deno_http/01_http.js";
function serveHttp(conn) {
- const rid = ops.op_http_start(conn.rid);
+ const rid = op_http_start(conn.rid);
return new HttpConn(rid, conn.remoteAddr, conn.localAddr);
}
diff --git a/runtime/js/40_process.js b/runtime/js/40_process.js
index 24ae65ab6..c90f38664 100644
--- a/runtime/js/40_process.js
+++ b/runtime/js/40_process.js
@@ -1,7 +1,15 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, internals, primordials } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_kill,
+ op_run,
+ op_run_status,
+ op_spawn_child,
+ op_spawn_kill,
+ op_spawn_sync,
+ op_spawn_wait,
+} = core.ensureFastOps();
const {
ArrayPrototypeMap,
ArrayPrototypeSlice,
@@ -14,6 +22,7 @@ const {
SafePromiseAll,
Symbol,
} = primordials;
+
import { FsFile } from "ext:deno_fs/30_fs.js";
import { readAll } from "ext:deno_io/12_io.js";
import {
@@ -30,13 +39,9 @@ import {
ReadableStreamPrototype,
writableStreamForRid,
} from "ext:deno_web/06_streams.js";
-const {
- op_run_status,
- op_spawn_wait,
-} = core.ensureFastOps();
function opKill(pid, signo, apiName) {
- ops.op_kill(pid, signo, apiName);
+ op_kill(pid, signo, apiName);
}
function kill(pid, signo = "SIGTERM") {
@@ -49,7 +54,7 @@ function opRunStatus(rid) {
function opRun(request) {
assert(request.cmd.length > 0);
- return ops.op_run(request);
+ return op_run(request);
}
async function runStatus(rid) {
@@ -187,7 +192,7 @@ function spawnChildInner(opFn, command, apiName, {
function spawnChild(command, options = {}) {
return spawnChildInner(
- ops.op_spawn_child,
+ op_spawn_child,
command,
"Deno.Command().spawn()",
options,
@@ -331,12 +336,12 @@ class ChildProcess {
if (this.#waitComplete) {
throw new TypeError("Child process has already terminated.");
}
- ops.op_spawn_kill(this.#rid, signo);
+ op_spawn_kill(this.#rid, signo);
}
async [SymbolAsyncDispose]() {
try {
- ops.op_spawn_kill(this.#rid, "SIGTERM");
+ op_spawn_kill(this.#rid, "SIGTERM");
} catch {
// ignore errors from killing the process (such as ESRCH or BadResource)
}
@@ -363,7 +368,7 @@ function spawn(command, options) {
);
}
return spawnChildInner(
- ops.op_spawn_child,
+ op_spawn_child,
command,
"Deno.Command().output()",
options,
@@ -388,7 +393,7 @@ function spawnSync(command, {
"Piped stdin is not supported for this function, use 'Deno.Command().spawn()' instead",
);
}
- const result = ops.op_spawn_sync({
+ const result = op_spawn_sync({
cmd: pathFromURL(command),
args: ArrayPrototypeMap(args, String),
cwd: pathFromURL(cwd),
diff --git a/runtime/js/40_signals.js b/runtime/js/40_signals.js
index a1b1897fc..c654dd2dd 100644
--- a/runtime/js/40_signals.js
+++ b/runtime/js/40_signals.js
@@ -1,7 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_signal_bind,
+ op_signal_poll,
+ op_signal_unbind,
+} = core.ensureFastOps();
const {
SafeSet,
SafeSetIterator,
@@ -9,12 +13,9 @@ const {
SetPrototypeDelete,
TypeError,
} = primordials;
-const {
- op_signal_poll,
-} = core.ensureFastOps();
function bindSignal(signo) {
- return ops.op_signal_bind(signo);
+ return op_signal_bind(signo);
}
function pollSignal(rid) {
@@ -24,7 +25,7 @@ function pollSignal(rid) {
}
function unbindSignal(rid) {
- ops.op_signal_unbind(rid);
+ op_signal_unbind(rid);
}
// Stores signal listeners and resource data. This has type of
diff --git a/runtime/js/40_tty.js b/runtime/js/40_tty.js
index 3e6cc29a5..e94fc0374 100644
--- a/runtime/js/40_tty.js
+++ b/runtime/js/40_tty.js
@@ -1,6 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_console_size,
+ op_isatty,
+} = core.ensureFastOps();
const {
Uint32Array,
} = primordials;
@@ -8,12 +11,12 @@ const {
const size = new Uint32Array(2);
function consoleSize() {
- ops.op_console_size(size);
+ op_console_size(size);
return { columns: size[0], rows: size[1] };
}
function isatty(rid) {
- return ops.op_isatty(rid);
+ return op_isatty(rid);
}
export { consoleSize, isatty };
diff --git a/runtime/js/41_prompt.js b/runtime/js/41_prompt.js
index 787b9f9f7..4e2f0fffc 100644
--- a/runtime/js/41_prompt.js
+++ b/runtime/js/41_prompt.js
@@ -1,9 +1,14 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
+const {
+ ArrayPrototypePush,
+ StringPrototypeCharCodeAt,
+ Uint8Array,
+} = primordials;
+
import { isatty } from "ext:runtime/40_tty.js";
import { stdin } from "ext:deno_io/12_io.js";
-const { ArrayPrototypePush, StringPrototypeCharCodeAt, Uint8Array } =
- primordials;
+
const LF = StringPrototypeCharCodeAt("\n", 0);
const CR = StringPrototypeCharCodeAt("\r", 0);
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index 4c0806f8e..e196fd104 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -1,7 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_net_listen_udp,
+ op_net_listen_unixpacket,
+ op_runtime_memory_usage,
+} = core.ensureFastOps();
import * as timers from "ext:deno_web/02_timers.js";
import * as httpClient from "ext:deno_fetch/22_http_client.js";
@@ -50,7 +54,7 @@ const denoNs = {
makeTempDir: fs.makeTempDir,
makeTempFileSync: fs.makeTempFileSync,
makeTempFile: fs.makeTempFile,
- memoryUsage: () => ops.op_runtime_memory_usage(),
+ memoryUsage: () => op_runtime_memory_usage(),
mkdirSync: fs.mkdirSync,
mkdir: fs.mkdir,
chdir: fs.chdir,
@@ -210,8 +214,8 @@ denoNsUnstableById[unstableIds.kv] = {
denoNsUnstableById[unstableIds.net] = {
listenDatagram: net.createListenDatagram(
- ops.op_net_listen_udp,
- ops.op_net_listen_unixpacket,
+ op_net_listen_udp,
+ op_net_listen_unixpacket,
),
};
@@ -224,8 +228,8 @@ denoNsUnstableById[unstableIds.net] = {
// when editing this list, also update unstableDenoProps in cli/tsc/99_main_compiler.js
const denoNsUnstable = {
listenDatagram: net.createListenDatagram(
- ops.op_net_listen_udp,
- ops.op_net_listen_unixpacket,
+ op_net_listen_udp,
+ op_net_listen_unixpacket,
),
umask: fs.umask,
HttpClient: httpClient.HttpClient,
diff --git a/runtime/js/98_global_scope_window.js b/runtime/js/98_global_scope_window.js
index 42cefdfb0..63b346dd5 100644
--- a/runtime/js/98_global_scope_window.js
+++ b/runtime/js/98_global_scope_window.js
@@ -1,7 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_bootstrap_language,
+ op_bootstrap_numcpus,
+ op_bootstrap_user_agent,
+} = core.ensureFastOps(true);
const {
ObjectDefineProperties,
ObjectPrototypeIsPrototypeOf,
@@ -51,9 +55,9 @@ function memoizeLazy(f) {
};
}
-const numCpus = memoizeLazy(() => ops.op_bootstrap_numcpus());
-const userAgent = memoizeLazy(() => ops.op_bootstrap_user_agent());
-const language = memoizeLazy(() => ops.op_bootstrap_language());
+const numCpus = memoizeLazy(() => op_bootstrap_numcpus());
+const userAgent = memoizeLazy(() => op_bootstrap_user_agent());
+const language = memoizeLazy(() => op_bootstrap_language());
ObjectDefineProperties(Navigator.prototype, {
gpu: {
diff --git a/runtime/js/98_global_scope_worker.js b/runtime/js/98_global_scope_worker.js
index 6b0ad480c..d43af4faf 100644
--- a/runtime/js/98_global_scope_worker.js
+++ b/runtime/js/98_global_scope_worker.js
@@ -1,7 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_bootstrap_language,
+ op_bootstrap_numcpus,
+ op_bootstrap_user_agent,
+} = core.ensureFastOps(true);
const {
ObjectDefineProperties,
ObjectPrototypeIsPrototypeOf,
@@ -25,9 +29,9 @@ function memoizeLazy(f) {
};
}
-const numCpus = memoizeLazy(() => ops.op_bootstrap_numcpus());
-const userAgent = memoizeLazy(() => ops.op_bootstrap_user_agent());
-const language = memoizeLazy(() => ops.op_bootstrap_language());
+const numCpus = memoizeLazy(() => op_bootstrap_numcpus());
+const userAgent = memoizeLazy(() => op_bootstrap_user_agent());
+const language = memoizeLazy(() => op_bootstrap_language());
class WorkerNavigator {
constructor() {