Skip to content

Commit 78ee331

Browse files
authored
perf(runtime): convert 8 runtime JS files to lazy-loaded scripts (#33864)
Convert 8 runtime JS files from ESM modules to lazy-loaded scripts (IIFE form): - `01_errors.js`, `01_version.ts`, `06_util.js`, `10_permissions.js` - `11_workers.js`, `40_fs_events.js`, `40_tty.js`, `41_prompt.js` The ESM entry point (`90_deno_ns.js`) and `98_global_scope_*.js` files remain as ESM and load these via `core.loadExtScript()`.
1 parent 4aeb5bd commit 78ee331

14 files changed

Lines changed: 67 additions & 48 deletions

cli/js/40_test_common.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
22
import { core, primordials } from "ext:core/mod.js";
3-
import { serializePermissions } from "ext:runtime/10_permissions.js";
3+
const { serializePermissions } = core.loadExtScript(
4+
"ext:runtime/10_permissions.js",
5+
);
46
const ops = core.ops;
57
const {
68
StringPrototypeReplaceAll,

runtime/js/01_errors.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
22

3-
import { core, primordials } from "ext:core/mod.js";
3+
(function () {
4+
const { core, primordials } = globalThis.__bootstrap;
45
const { BadResource, Interrupted, NotCapable } = core;
56
const { Error } = primordials;
67

@@ -186,4 +187,5 @@ const errors = {
186187
NotCapable,
187188
};
188189

189-
export { errors };
190+
return { errors };
191+
})();

runtime/js/01_version.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
22

3-
import { primordials } from "ext:core/mod.js";
3+
(function () {
4+
const { primordials } = globalThis.__bootstrap;
45
const {
56
ObjectFreeze,
67
} = primordials;
78

8-
interface Version {
9-
deno: string;
10-
v8: string;
11-
typescript: string;
12-
}
13-
14-
const version: Version = {
9+
const version = {
1510
deno: "",
1611
v8: "",
1712
typescript: "",
@@ -29,4 +24,5 @@ function setVersions(
2924
ObjectFreeze(version);
3025
}
3126

32-
export { setVersions, version };
27+
return { setVersions, version };
28+
})();

runtime/js/06_util.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
22

3-
import { primordials } from "ext:core/mod.js";
4-
import { op_bootstrap_log_level } from "ext:core/ops";
3+
(function () {
4+
const { primordials } = globalThis.__bootstrap;
5+
const { op_bootstrap_log_level } = globalThis.__bootstrap.core.ops;
56
const { SafeArrayIterator } = primordials;
67

78
// WARNING: Keep this in sync with Rust (search for LogLevel)
@@ -33,4 +34,5 @@ function log(...args) {
3334
}
3435
}
3536

36-
export { log };
37+
return { log };
38+
})();

runtime/js/10_permissions.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
22

3-
import { core, primordials } from "ext:core/mod.js";
4-
import {
3+
(function () {
4+
const { core, primordials } = globalThis.__bootstrap;
5+
const {
56
op_query_permission,
67
op_request_permission,
78
op_revoke_permission,
8-
} from "ext:core/ops";
9+
} = core.ops;
910
const {
1011
ArrayIsArray,
1112
ArrayPrototypeIncludes,
@@ -304,4 +305,5 @@ function serializePermissions(permissions) {
304305
return permissions;
305306
}
306307

307-
export { Permissions, permissions, PermissionStatus, serializePermissions };
308+
return { Permissions, permissions, PermissionStatus, serializePermissions };
309+
})();

runtime/js/11_workers.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
22

3-
import { core, primordials } from "ext:core/mod.js";
4-
import {
3+
(function () {
4+
const { core, primordials } = globalThis.__bootstrap;
5+
const {
56
op_create_worker,
67
op_host_post_message,
78
op_host_post_message_raw,
89
op_host_recv_ctrl,
910
op_host_recv_message,
1011
op_host_terminate_worker,
11-
} from "ext:core/ops";
12+
} = core.ops;
1213
const {
1314
ArrayPrototypeFilter,
1415
ArrayPrototypeJoin,
@@ -28,8 +29,10 @@ const { createFilteredInspectProxy } = core.loadExtScript(
2829
);
2930
const { URL } = core.loadExtScript("ext:deno_web/00_url.js");
3031
const { getLocationHref } = core.loadExtScript("ext:deno_web/12_location.js");
31-
import { serializePermissions } from "ext:runtime/10_permissions.js";
32-
import { log } from "ext:runtime/06_util.js";
32+
const { serializePermissions } = core.loadExtScript(
33+
"ext:runtime/10_permissions.js",
34+
);
35+
const { log } = core.loadExtScript("ext:runtime/06_util.js");
3336
const {
3437
defineEventHandler,
3538
ErrorEvent,
@@ -42,7 +45,9 @@ const {
4245
MessagePortPrototype,
4346
serializeJsMessageData,
4447
} = core.loadExtScript("ext:deno_web/13_message_port.js");
45-
const { DOMException } = core.loadExtScript("ext:deno_web/01_dom_exception.js");
48+
const { DOMException } = core.loadExtScript(
49+
"ext:deno_web/01_dom_exception.js",
50+
);
4651

4752
function createWorker(
4853
specifier,
@@ -358,4 +363,5 @@ webidl.converters["WorkerType"] = webidl.createEnumConverter("WorkerType", [
358363
"module",
359364
]);
360365

361-
export { Worker };
366+
return { Worker };
367+
})();

runtime/js/40_fs_events.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
22

3-
import { core, primordials } from "ext:core/mod.js";
4-
import { op_fs_events_open, op_fs_events_poll } from "ext:core/ops";
3+
(function () {
4+
const { core, primordials } = globalThis.__bootstrap;
5+
const { op_fs_events_open, op_fs_events_poll } = core.ops;
56
const {
67
BadResourcePrototype,
78
InterruptedPrototype,
@@ -73,4 +74,5 @@ function watchFs(
7374
return new FsWatcher(ArrayIsArray(paths) ? paths : [paths], options);
7475
}
7576

76-
export { watchFs };
77+
return { watchFs };
78+
})();

runtime/js/40_tty.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
2-
import { core, primordials } from "ext:core/mod.js";
3-
import { op_console_size } from "ext:core/ops";
2+
(function () {
3+
const { core, primordials } = globalThis.__bootstrap;
4+
const { op_console_size } = core.ops;
45
const {
56
Uint32Array,
67
} = primordials;
@@ -21,4 +22,5 @@ function isatty(rid) {
2122
return isTerminal(rid);
2223
}
2324

24-
export { consoleSize, isatty };
25+
return { consoleSize, isatty };
26+
})();

runtime/js/41_prompt.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
2-
import { core, primordials } from "ext:core/mod.js";
3-
import { op_read_line_prompt } from "ext:core/ops";
2+
(function () {
3+
const { core, primordials } = globalThis.__bootstrap;
4+
const { op_read_line_prompt } = core.ops;
45
const { ArrayPrototypePush, StringPrototypeCharCodeAt, Uint8Array } =
56
primordials;
67

@@ -69,4 +70,5 @@ function readLineFromStdinSync() {
6970
return core.decode(new Uint8Array(buf));
7071
}
7172

72-
export { alert, confirm, prompt };
73+
return { alert, confirm, prompt };
74+
})();

runtime/js/90_deno_ns.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ const tls = core.loadExtScript("ext:deno_net/02_tls.js");
1717
const serve = core.loadExtScript("ext:deno_http/00_serve.ts");
1818
const http = core.loadExtScript("ext:deno_http/01_http.js");
1919
const websocket = core.loadExtScript("ext:deno_http/02_websocket.ts");
20-
import * as errors from "ext:runtime/01_errors.js";
21-
import * as version from "ext:runtime/01_version.ts";
22-
import * as permissions from "ext:runtime/10_permissions.js";
20+
const errors = core.loadExtScript("ext:runtime/01_errors.js");
21+
const version = core.loadExtScript("ext:runtime/01_version.ts");
22+
const permissions = core.loadExtScript("ext:runtime/10_permissions.js");
2323
const io = core.loadExtScript("ext:deno_io/12_io.js");
2424
const fs = core.loadExtScript("ext:deno_fs/30_fs.js");
2525
const os = core.loadExtScript("ext:deno_os/30_os.js");
26-
import * as fsEvents from "ext:runtime/40_fs_events.js";
26+
const fsEvents = core.loadExtScript("ext:runtime/40_fs_events.js");
2727
const process = core.loadExtScript("ext:deno_process/40_process.js");
2828
const signals = core.loadExtScript("ext:deno_os/40_signals.js");
29-
import * as tty from "ext:runtime/40_tty.js";
29+
const tty = core.loadExtScript("ext:runtime/40_tty.js");
3030
const kv = core.loadExtScript("ext:deno_kv/01_db.ts");
3131
const cron = core.loadExtScript("ext:deno_cron/01_cron.ts");
3232
const surface = core.loadExtScript("ext:deno_canvas/02_surface.js");

0 commit comments

Comments
 (0)