2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-06-14 23:04:30 -04:00
|
|
|
|
|
|
|
// Remove Intl.v8BreakIterator because it is a non-standard API.
|
|
|
|
delete Intl.v8BreakIterator;
|
|
|
|
|
2024-09-14 17:30:06 -04:00
|
|
|
import * as internalConsole from "ext:deno_console/01_console.js";
|
2023-12-07 08:21:01 -05:00
|
|
|
import { core, internals, primordials } from "ext:core/mod.js";
|
2023-02-07 14:22:46 -05:00
|
|
|
const ops = core.ops;
|
2024-01-31 17:17:49 -05:00
|
|
|
import {
|
|
|
|
op_bootstrap_args,
|
2024-05-14 17:32:09 -04:00
|
|
|
op_bootstrap_is_stderr_tty,
|
|
|
|
op_bootstrap_is_stdout_tty,
|
2024-01-31 17:17:49 -05:00
|
|
|
op_bootstrap_no_color,
|
|
|
|
op_bootstrap_pid,
|
|
|
|
op_main_module,
|
|
|
|
op_ppid,
|
|
|
|
op_set_format_exception_callback,
|
|
|
|
op_snapshot_options,
|
2024-02-05 18:58:06 -05:00
|
|
|
op_worker_close,
|
|
|
|
op_worker_get_type,
|
|
|
|
op_worker_post_message,
|
|
|
|
op_worker_recv_message,
|
|
|
|
op_worker_sync_fetch,
|
2024-01-31 17:17:49 -05:00
|
|
|
} from "ext:core/ops";
|
2023-02-07 14:22:46 -05:00
|
|
|
const {
|
2023-05-01 09:30:02 -04:00
|
|
|
ArrayPrototypeFilter,
|
2024-09-10 17:36:43 -04:00
|
|
|
ArrayPrototypeForEach,
|
2023-11-25 11:41:21 -05:00
|
|
|
ArrayPrototypeIncludes,
|
2023-05-01 09:30:02 -04:00
|
|
|
ArrayPrototypeMap,
|
2023-02-07 14:22:46 -05:00
|
|
|
Error,
|
|
|
|
ErrorPrototype,
|
|
|
|
FunctionPrototypeBind,
|
2023-05-01 09:30:02 -04:00
|
|
|
FunctionPrototypeCall,
|
2023-02-07 14:22:46 -05:00
|
|
|
ObjectAssign,
|
|
|
|
ObjectDefineProperties,
|
2023-05-01 09:30:02 -04:00
|
|
|
ObjectDefineProperty,
|
2024-04-24 15:45:49 -04:00
|
|
|
ObjectHasOwn,
|
2023-12-08 08:24:49 -05:00
|
|
|
ObjectKeys,
|
2024-09-10 17:36:43 -04:00
|
|
|
ObjectGetOwnPropertyDescriptor,
|
2024-12-05 08:55:50 -05:00
|
|
|
ObjectGetOwnPropertyDescriptors,
|
2023-02-07 14:22:46 -05:00
|
|
|
ObjectPrototypeIsPrototypeOf,
|
|
|
|
ObjectSetPrototypeOf,
|
2023-05-01 09:30:02 -04:00
|
|
|
PromisePrototypeThen,
|
2023-02-07 14:22:46 -05:00
|
|
|
PromiseResolve,
|
2024-08-14 18:26:21 -04:00
|
|
|
StringPrototypePadEnd,
|
2023-02-07 14:22:46 -05:00
|
|
|
Symbol,
|
|
|
|
SymbolIterator,
|
|
|
|
TypeError,
|
2024-12-05 08:55:50 -05:00
|
|
|
uncurryThis,
|
2023-02-07 14:22:46 -05:00
|
|
|
} = primordials;
|
2024-01-03 23:12:38 -05:00
|
|
|
const {
|
|
|
|
isNativeError,
|
|
|
|
} = core;
|
2024-04-24 15:45:49 -04:00
|
|
|
import { registerDeclarativeServer } from "ext:deno_http/00_serve.ts";
|
2023-03-08 06:44:54 -05:00
|
|
|
import * as event from "ext:deno_web/02_event.js";
|
|
|
|
import * as location from "ext:deno_web/12_location.js";
|
|
|
|
import * as version from "ext:runtime/01_version.ts";
|
|
|
|
import * as os from "ext:runtime/30_os.js";
|
|
|
|
import * as timers from "ext:deno_web/02_timers.js";
|
2023-02-07 14:22:46 -05:00
|
|
|
import {
|
2023-04-30 03:24:13 -04:00
|
|
|
getDefaultInspectOptions,
|
2024-05-14 17:32:09 -04:00
|
|
|
getStderrNoColor,
|
2023-02-07 14:22:46 -05:00
|
|
|
inspectArgs,
|
|
|
|
quoteString,
|
2024-05-14 17:32:09 -04:00
|
|
|
setNoColorFns,
|
2023-04-30 05:11:37 -04:00
|
|
|
} from "ext:deno_console/01_console.js";
|
2023-03-08 06:44:54 -05:00
|
|
|
import * as performance from "ext:deno_web/15_performance.js";
|
|
|
|
import * as url from "ext:deno_url/00_url.js";
|
|
|
|
import * as fetch from "ext:deno_fetch/26_fetch.js";
|
|
|
|
import * as messagePort from "ext:deno_web/13_message_port.js";
|
2023-11-01 18:15:08 -04:00
|
|
|
import {
|
|
|
|
denoNs,
|
|
|
|
denoNsUnstableById,
|
2023-12-08 08:24:49 -05:00
|
|
|
unstableIds,
|
2023-11-01 18:15:08 -04:00
|
|
|
} from "ext:runtime/90_deno_ns.js";
|
2023-03-08 06:44:54 -05:00
|
|
|
import { errors } from "ext:runtime/01_errors.js";
|
|
|
|
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
2024-01-03 23:12:38 -05:00
|
|
|
import { DOMException } from "ext:deno_web/01_dom_exception.js";
|
2023-02-07 14:22:46 -05:00
|
|
|
import {
|
2023-12-08 08:24:49 -05:00
|
|
|
unstableForWindowOrWorkerGlobalScope,
|
2023-02-07 14:22:46 -05:00
|
|
|
windowOrWorkerGlobalScope,
|
2024-01-06 08:40:26 -05:00
|
|
|
} from "ext:runtime/98_global_scope_shared.js";
|
|
|
|
import {
|
|
|
|
mainRuntimeGlobalProperties,
|
|
|
|
memoizeLazy,
|
|
|
|
} from "ext:runtime/98_global_scope_window.js";
|
|
|
|
import {
|
2023-02-07 14:22:46 -05:00
|
|
|
workerRuntimeGlobalProperties,
|
2024-01-06 08:40:26 -05:00
|
|
|
} from "ext:runtime/98_global_scope_worker.js";
|
2024-07-01 18:48:52 -04:00
|
|
|
import { SymbolDispose, SymbolMetadata } from "ext:deno_web/00_infra.js";
|
2024-11-26 06:22:18 -05:00
|
|
|
import { bootstrap as bootstrapOtel } from "ext:deno_telemetry/telemetry.ts";
|
2024-11-13 05:38:46 -05:00
|
|
|
|
2024-02-06 08:57:25 -05:00
|
|
|
// deno-lint-ignore prefer-primordials
|
|
|
|
if (Symbol.metadata) {
|
2024-09-13 05:38:45 -04:00
|
|
|
throw "V8 supports Symbol.metadata now, no need to shim it";
|
2024-02-06 08:57:25 -05:00
|
|
|
}
|
2023-11-01 15:26:12 -04:00
|
|
|
ObjectDefineProperties(Symbol, {
|
|
|
|
dispose: {
|
2024-09-06 06:52:59 -04:00
|
|
|
__proto__: null,
|
2023-11-01 15:26:12 -04:00
|
|
|
value: SymbolDispose,
|
|
|
|
enumerable: false,
|
|
|
|
writable: false,
|
|
|
|
configurable: false,
|
|
|
|
},
|
2024-02-06 08:57:25 -05:00
|
|
|
metadata: {
|
2024-09-06 06:52:59 -04:00
|
|
|
__proto__: null,
|
2024-02-06 08:57:25 -05:00
|
|
|
value: SymbolMetadata,
|
|
|
|
enumerable: false,
|
|
|
|
writable: false,
|
|
|
|
configurable: false,
|
|
|
|
},
|
2023-11-01 15:26:12 -04:00
|
|
|
});
|
2023-09-14 14:08:59 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
let windowIsClosing = false;
|
|
|
|
let globalThis_;
|
|
|
|
|
|
|
|
function windowClose() {
|
|
|
|
if (!windowIsClosing) {
|
|
|
|
windowIsClosing = true;
|
|
|
|
// Push a macrotask to exit after a promise resolve.
|
|
|
|
// This is not perfect, but should be fine for first pass.
|
|
|
|
PromisePrototypeThen(
|
|
|
|
PromiseResolve(),
|
|
|
|
() =>
|
|
|
|
FunctionPrototypeCall(timers.setTimeout, null, () => {
|
|
|
|
// This should be fine, since only Window/MainWorker has .close()
|
|
|
|
os.exit(0);
|
|
|
|
}, 0),
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
function workerClose() {
|
|
|
|
if (isClosing) {
|
|
|
|
return;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
isClosing = true;
|
2024-02-05 18:58:06 -05:00
|
|
|
op_worker_close();
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
|
2024-05-22 18:03:35 -04:00
|
|
|
function postMessage(message, transferOrOptions = { __proto__: null }) {
|
2023-02-07 14:22:46 -05:00
|
|
|
const prefix =
|
|
|
|
"Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope'";
|
2023-05-01 06:47:13 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2023-02-07 14:22:46 -05:00
|
|
|
message = webidl.converters.any(message);
|
|
|
|
let options;
|
|
|
|
if (
|
|
|
|
webidl.type(transferOrOptions) === "Object" &&
|
|
|
|
transferOrOptions !== undefined &&
|
|
|
|
transferOrOptions[SymbolIterator] !== undefined
|
|
|
|
) {
|
|
|
|
const transfer = webidl.converters["sequence<object>"](
|
|
|
|
transferOrOptions,
|
2023-05-01 06:47:13 -04:00
|
|
|
prefix,
|
|
|
|
"Argument 2",
|
2023-02-07 14:22:46 -05:00
|
|
|
);
|
|
|
|
options = { transfer };
|
|
|
|
} else {
|
|
|
|
options = webidl.converters.StructuredSerializeOptions(
|
|
|
|
transferOrOptions,
|
2023-05-01 06:47:13 -04:00
|
|
|
prefix,
|
|
|
|
"Argument 2",
|
2023-02-07 14:22:46 -05:00
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
const { transfer } = options;
|
|
|
|
const data = messagePort.serializeJsMessageData(message, transfer);
|
2024-02-05 18:58:06 -05:00
|
|
|
op_worker_post_message(data);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let isClosing = false;
|
|
|
|
let globalDispatchEvent;
|
2024-03-15 16:38:16 -04:00
|
|
|
|
|
|
|
function hasMessageEventListener() {
|
fix(node): fix worker_threads issues blocking Angular support (#26024)
Fixes #22995. Fixes #23000.
There were a handful of bugs here causing the hang (each with a
corresponding minimized test):
- We were canceling recv futures when `receiveMessageOnPort` was called,
but this caused the "receive loop" in the message port to exit. This was
due to the fact that `CancelHandle`s are never reset (i.e., once you
`cancel` a `CancelHandle`, it remains cancelled). That meant that after
`receieveMessageOnPort` was called, the subsequent calls to
`op_message_port_recv_message` would throw `Interrupted` exceptions, and
we would exit the loop.
The cancellation, however, isn't actually necessary.
`op_message_port_recv_message` only borrows the underlying port for long
enough to poll the receiver, so the borrow there could never overlap
with `op_message_port_recv_message_sync`.
- Calling `MessagePort.unref()` caused the "receive loop" in the message
port to exit. This was because we were setting
`messageEventListenerCount` to 0 on unref. Not only does that break the
counter when multiple `MessagePort`s are present in the same thread, but
we also exited the "receive loop" whenever the listener count was 0. I
assume this was to prevent the recv promise from keeping the event loop
open.
Instead of this, I chose to just unref the recv promise as needed to
control the event loop.
- The last bug causing the hang (which was a doozy to debug) ended up
being an unfortunate interaction between how we implement our
messageport "receive loop" and a pattern found in `npm:piscina` (which
angular uses). The gist of it is that piscina uses an atomic wait loop
along with `receiveMessageOnPort` in its worker threads, and as the
worker is getting started, the following incredibly convoluted series of
events occurs:
1. Parent sends a MessagePort `p` to worker
2. Parent sends a message `m` to the port `p`
3. Parent notifies the worker with `Atomics.notify` that a new message
is available
4. Worker receives message, adds "message" listener to port `p`
5. Adding the listener triggers `MessagePort.start()` on `p`
6. Receive loop in MessagePort.start receives the message `m`, but then
hits an await point and yields (before dispatching the "message" event)
7. Worker continues execution, starts the atomic wait loop, and
immediately receives the existing notification from the parent that a
message is available
8. Worker attempts to receive the new message `m` with
`receiveMessageOnPort`, but this returns `undefined` because the receive
loop already took the message in 6
9. Atomic wait loop continues to next iteration, waiting for the next
message with `Atomic.wait`
10. `Atomic.wait` blocks the worker thread, which prevents the receive
loop from continuing and dispatching the "message" event for the
received message
11. The parent waits for the worker to respond to the first message, and
waits
12. The thread can't make any more progress, and the whole process hangs
The fix I've chosen here (which I don't particularly love, but it works)
is to just delay the `MessagePort.start` call until the end of the event
loop turn, so that the atomic wait loop receives the message first. This
prevents the hang.
---
Those were the main issues causing the hang. There ended up being a few
other small bugs as well, namely `exit` being emitted multiple times,
and not patching up the message port when it's received by
`receiveMessageOnPort`.
2024-10-04 12:26:32 -04:00
|
|
|
// the function name is kind of a misnomer, but we want to behave
|
|
|
|
// as if we have message event listeners if a node message port is explicitly
|
|
|
|
// refed (and the inverse as well)
|
2024-04-04 11:08:51 -04:00
|
|
|
return event.listenerCount(globalThis, "message") > 0 ||
|
fix(node): fix worker_threads issues blocking Angular support (#26024)
Fixes #22995. Fixes #23000.
There were a handful of bugs here causing the hang (each with a
corresponding minimized test):
- We were canceling recv futures when `receiveMessageOnPort` was called,
but this caused the "receive loop" in the message port to exit. This was
due to the fact that `CancelHandle`s are never reset (i.e., once you
`cancel` a `CancelHandle`, it remains cancelled). That meant that after
`receieveMessageOnPort` was called, the subsequent calls to
`op_message_port_recv_message` would throw `Interrupted` exceptions, and
we would exit the loop.
The cancellation, however, isn't actually necessary.
`op_message_port_recv_message` only borrows the underlying port for long
enough to poll the receiver, so the borrow there could never overlap
with `op_message_port_recv_message_sync`.
- Calling `MessagePort.unref()` caused the "receive loop" in the message
port to exit. This was because we were setting
`messageEventListenerCount` to 0 on unref. Not only does that break the
counter when multiple `MessagePort`s are present in the same thread, but
we also exited the "receive loop" whenever the listener count was 0. I
assume this was to prevent the recv promise from keeping the event loop
open.
Instead of this, I chose to just unref the recv promise as needed to
control the event loop.
- The last bug causing the hang (which was a doozy to debug) ended up
being an unfortunate interaction between how we implement our
messageport "receive loop" and a pattern found in `npm:piscina` (which
angular uses). The gist of it is that piscina uses an atomic wait loop
along with `receiveMessageOnPort` in its worker threads, and as the
worker is getting started, the following incredibly convoluted series of
events occurs:
1. Parent sends a MessagePort `p` to worker
2. Parent sends a message `m` to the port `p`
3. Parent notifies the worker with `Atomics.notify` that a new message
is available
4. Worker receives message, adds "message" listener to port `p`
5. Adding the listener triggers `MessagePort.start()` on `p`
6. Receive loop in MessagePort.start receives the message `m`, but then
hits an await point and yields (before dispatching the "message" event)
7. Worker continues execution, starts the atomic wait loop, and
immediately receives the existing notification from the parent that a
message is available
8. Worker attempts to receive the new message `m` with
`receiveMessageOnPort`, but this returns `undefined` because the receive
loop already took the message in 6
9. Atomic wait loop continues to next iteration, waiting for the next
message with `Atomic.wait`
10. `Atomic.wait` blocks the worker thread, which prevents the receive
loop from continuing and dispatching the "message" event for the
received message
11. The parent waits for the worker to respond to the first message, and
waits
12. The thread can't make any more progress, and the whole process hangs
The fix I've chosen here (which I don't particularly love, but it works)
is to just delay the `MessagePort.start` call until the end of the event
loop turn, so that the atomic wait loop receives the message first. This
prevents the hang.
---
Those were the main issues causing the hang. There ended up being a few
other small bugs as well, namely `exit` being emitted multiple times,
and not patching up the message port when it's received by
`receiveMessageOnPort`.
2024-10-04 12:26:32 -04:00
|
|
|
messagePort.refedMessagePortsCount > 0;
|
2024-03-15 16:38:16 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
|
|
|
|
async function pollForMessages() {
|
|
|
|
if (!globalDispatchEvent) {
|
|
|
|
globalDispatchEvent = FunctionPrototypeBind(
|
|
|
|
globalThis.dispatchEvent,
|
|
|
|
globalThis,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
while (!isClosing) {
|
2024-04-09 14:15:55 -04:00
|
|
|
const recvMessage = op_worker_recv_message();
|
|
|
|
if (globalThis[messagePort.unrefPollForMessages] === true) {
|
|
|
|
core.unrefOpPromise(recvMessage);
|
|
|
|
}
|
|
|
|
const data = await recvMessage;
|
|
|
|
// const data = await op_worker_recv_message();
|
2023-02-07 14:22:46 -05:00
|
|
|
if (data === null) break;
|
|
|
|
const v = messagePort.deserializeJsMessageData(data);
|
|
|
|
const message = v[0];
|
|
|
|
const transferables = v[1];
|
|
|
|
|
|
|
|
const msgEvent = new event.MessageEvent("message", {
|
|
|
|
cancelable: false,
|
|
|
|
data: message,
|
2023-05-01 09:30:02 -04:00
|
|
|
ports: ArrayPrototypeFilter(
|
|
|
|
transferables,
|
|
|
|
(t) =>
|
|
|
|
ObjectPrototypeIsPrototypeOf(messagePort.MessagePortPrototype, t),
|
2023-02-07 14:22:46 -05:00
|
|
|
),
|
|
|
|
});
|
2023-07-31 17:22:07 -04:00
|
|
|
event.setIsTrusted(msgEvent, true);
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
try {
|
|
|
|
globalDispatchEvent(msgEvent);
|
|
|
|
} catch (e) {
|
|
|
|
const errorEvent = new event.ErrorEvent("error", {
|
|
|
|
cancelable: true,
|
|
|
|
message: e.message,
|
|
|
|
lineno: e.lineNumber ? e.lineNumber + 1 : undefined,
|
|
|
|
colno: e.columnNumber ? e.columnNumber + 1 : undefined,
|
|
|
|
filename: e.fileName,
|
|
|
|
error: e,
|
2020-07-19 13:49:44 -04:00
|
|
|
});
|
|
|
|
|
2023-07-31 17:22:07 -04:00
|
|
|
event.setIsTrusted(errorEvent, true);
|
2023-02-07 14:22:46 -05:00
|
|
|
globalDispatchEvent(errorEvent);
|
|
|
|
if (!errorEvent.defaultPrevented) {
|
|
|
|
throw e;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
let loadedMainWorkerScript = false;
|
2021-08-16 08:29:54 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
function importScripts(...urls) {
|
2024-02-05 18:58:06 -05:00
|
|
|
if (op_worker_get_type() === "module") {
|
2024-09-13 05:38:45 -04:00
|
|
|
throw new TypeError("Cannot import scripts in a module worker");
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2021-08-16 08:29:54 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const baseUrl = location.getLocationHref();
|
|
|
|
const parsedUrls = ArrayPrototypeMap(urls, (scriptUrl) => {
|
|
|
|
try {
|
|
|
|
return new url.URL(scriptUrl, baseUrl ?? undefined).href;
|
|
|
|
} catch {
|
|
|
|
throw new DOMException(
|
2024-09-13 05:38:45 -04:00
|
|
|
`Failed to parse URL: ${scriptUrl}`,
|
2023-02-07 14:22:46 -05:00
|
|
|
"SyntaxError",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2021-08-16 08:29:54 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
// A classic worker's main script has looser MIME type checks than any
|
|
|
|
// imported scripts, so we use `loadedMainWorkerScript` to distinguish them.
|
|
|
|
// TODO(andreubotella) Refactor worker creation so the main script isn't
|
|
|
|
// loaded with `importScripts()`.
|
2024-02-05 18:58:06 -05:00
|
|
|
const scripts = op_worker_sync_fetch(
|
2023-02-07 14:22:46 -05:00
|
|
|
parsedUrls,
|
|
|
|
!loadedMainWorkerScript,
|
|
|
|
);
|
|
|
|
loadedMainWorkerScript = true;
|
|
|
|
|
|
|
|
for (let i = 0; i < scripts.length; ++i) {
|
|
|
|
const { url, script } = scripts[i];
|
|
|
|
const err = core.evalContext(script, url)[1];
|
|
|
|
if (err !== null) {
|
|
|
|
throw err.thrown;
|
2021-08-16 08:29:54 -04:00
|
|
|
}
|
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
|
2024-01-31 17:17:49 -05:00
|
|
|
const opArgs = memoizeLazy(() => op_bootstrap_args());
|
|
|
|
const opPid = memoizeLazy(() => op_bootstrap_pid());
|
2024-05-14 17:32:09 -04:00
|
|
|
setNoColorFns(
|
|
|
|
() => op_bootstrap_no_color() || !op_bootstrap_is_stdout_tty(),
|
|
|
|
() => op_bootstrap_no_color() || !op_bootstrap_is_stderr_tty(),
|
|
|
|
);
|
2023-11-12 23:52:59 -05:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
function formatException(error) {
|
2024-01-03 23:12:38 -05:00
|
|
|
if (
|
|
|
|
isNativeError(error) ||
|
|
|
|
ObjectPrototypeIsPrototypeOf(ErrorPrototype, error)
|
|
|
|
) {
|
2023-02-07 14:22:46 -05:00
|
|
|
return null;
|
|
|
|
} else if (typeof error == "string") {
|
|
|
|
return `Uncaught ${
|
2023-04-30 03:24:13 -04:00
|
|
|
inspectArgs([quoteString(error, getDefaultInspectOptions())], {
|
2024-05-14 17:32:09 -04:00
|
|
|
colors: !getStderrNoColor(),
|
2023-02-07 14:22:46 -05:00
|
|
|
})
|
|
|
|
}`;
|
|
|
|
} else {
|
2024-05-14 17:32:09 -04:00
|
|
|
return `Uncaught ${inspectArgs([error], { colors: !getStderrNoColor() })}`;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
|
2023-02-21 19:55:31 -05:00
|
|
|
core.registerErrorClass("NotFound", errors.NotFound);
|
|
|
|
core.registerErrorClass("ConnectionRefused", errors.ConnectionRefused);
|
|
|
|
core.registerErrorClass("ConnectionReset", errors.ConnectionReset);
|
|
|
|
core.registerErrorClass("ConnectionAborted", errors.ConnectionAborted);
|
|
|
|
core.registerErrorClass("NotConnected", errors.NotConnected);
|
|
|
|
core.registerErrorClass("AddrInUse", errors.AddrInUse);
|
|
|
|
core.registerErrorClass("AddrNotAvailable", errors.AddrNotAvailable);
|
|
|
|
core.registerErrorClass("BrokenPipe", errors.BrokenPipe);
|
2024-09-10 14:12:24 -04:00
|
|
|
core.registerErrorClass("PermissionDenied", errors.PermissionDenied);
|
2023-02-21 19:55:31 -05:00
|
|
|
core.registerErrorClass("AlreadyExists", errors.AlreadyExists);
|
|
|
|
core.registerErrorClass("InvalidData", errors.InvalidData);
|
|
|
|
core.registerErrorClass("TimedOut", errors.TimedOut);
|
|
|
|
core.registerErrorClass("WouldBlock", errors.WouldBlock);
|
|
|
|
core.registerErrorClass("WriteZero", errors.WriteZero);
|
|
|
|
core.registerErrorClass("UnexpectedEof", errors.UnexpectedEof);
|
|
|
|
core.registerErrorClass("Http", errors.Http);
|
|
|
|
core.registerErrorClass("Busy", errors.Busy);
|
|
|
|
core.registerErrorClass("NotSupported", errors.NotSupported);
|
2023-06-28 19:46:16 -04:00
|
|
|
core.registerErrorClass("FilesystemLoop", errors.FilesystemLoop);
|
|
|
|
core.registerErrorClass("IsADirectory", errors.IsADirectory);
|
|
|
|
core.registerErrorClass("NetworkUnreachable", errors.NetworkUnreachable);
|
|
|
|
core.registerErrorClass("NotADirectory", errors.NotADirectory);
|
2023-02-21 19:55:31 -05:00
|
|
|
core.registerErrorBuilder(
|
|
|
|
"DOMExceptionOperationError",
|
|
|
|
function DOMExceptionOperationError(msg) {
|
|
|
|
return new DOMException(msg, "OperationError");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
core.registerErrorBuilder(
|
|
|
|
"DOMExceptionQuotaExceededError",
|
|
|
|
function DOMExceptionQuotaExceededError(msg) {
|
|
|
|
return new DOMException(msg, "QuotaExceededError");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
core.registerErrorBuilder(
|
|
|
|
"DOMExceptionNotSupportedError",
|
|
|
|
function DOMExceptionNotSupportedError(msg) {
|
|
|
|
return new DOMException(msg, "NotSupported");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
core.registerErrorBuilder(
|
|
|
|
"DOMExceptionNetworkError",
|
|
|
|
function DOMExceptionNetworkError(msg) {
|
|
|
|
return new DOMException(msg, "NetworkError");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
core.registerErrorBuilder(
|
|
|
|
"DOMExceptionAbortError",
|
|
|
|
function DOMExceptionAbortError(msg) {
|
|
|
|
return new DOMException(msg, "AbortError");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
core.registerErrorBuilder(
|
|
|
|
"DOMExceptionInvalidCharacterError",
|
|
|
|
function DOMExceptionInvalidCharacterError(msg) {
|
|
|
|
return new DOMException(msg, "InvalidCharacterError");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
core.registerErrorBuilder(
|
|
|
|
"DOMExceptionDataError",
|
|
|
|
function DOMExceptionDataError(msg) {
|
|
|
|
return new DOMException(msg, "DataError");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-03-28 04:27:17 -04:00
|
|
|
function runtimeStart(
|
|
|
|
denoVersion,
|
|
|
|
v8Version,
|
|
|
|
tsVersion,
|
|
|
|
target,
|
|
|
|
) {
|
2023-02-07 14:22:46 -05:00
|
|
|
core.setWasmStreamingCallback(fetch.handleWasmStreaming);
|
|
|
|
core.setReportExceptionCallback(event.reportException);
|
2024-01-31 17:17:49 -05:00
|
|
|
op_set_format_exception_callback(formatException);
|
2023-02-07 14:22:46 -05:00
|
|
|
version.setVersions(
|
2023-03-28 04:27:17 -04:00
|
|
|
denoVersion,
|
|
|
|
v8Version,
|
|
|
|
tsVersion,
|
2023-02-07 14:22:46 -05:00
|
|
|
);
|
2023-03-28 04:27:17 -04:00
|
|
|
core.setBuildInfo(target);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
|
2023-12-06 19:02:52 -05:00
|
|
|
core.setUnhandledPromiseRejectionHandler(processUnhandledPromiseRejection);
|
2024-01-12 17:10:42 -05:00
|
|
|
core.setHandledPromiseRejectionHandler(processRejectionHandled);
|
|
|
|
|
2023-12-06 19:02:52 -05:00
|
|
|
// Notification that the core received an unhandled promise rejection that is about to
|
|
|
|
// terminate the runtime. If we can handle it, attempt to do so.
|
|
|
|
function processUnhandledPromiseRejection(promise, reason) {
|
|
|
|
const rejectionEvent = new event.PromiseRejectionEvent(
|
|
|
|
"unhandledrejection",
|
|
|
|
{
|
|
|
|
cancelable: true,
|
2023-02-07 14:22:46 -05:00
|
|
|
promise,
|
2023-12-06 19:02:52 -05:00
|
|
|
reason,
|
|
|
|
},
|
|
|
|
);
|
2023-02-07 14:22:46 -05:00
|
|
|
|
2023-12-06 19:02:52 -05:00
|
|
|
// Note that the handler may throw, causing a recursive "error" event
|
|
|
|
globalThis_.dispatchEvent(rejectionEvent);
|
2023-02-07 14:22:46 -05:00
|
|
|
|
2023-12-06 19:02:52 -05:00
|
|
|
// If event was not yet prevented, try handing it off to Node compat layer
|
|
|
|
// (if it was initialized)
|
|
|
|
if (
|
|
|
|
!rejectionEvent.defaultPrevented &&
|
|
|
|
typeof internals.nodeProcessUnhandledRejectionCallback !== "undefined"
|
|
|
|
) {
|
|
|
|
internals.nodeProcessUnhandledRejectionCallback(rejectionEvent);
|
|
|
|
}
|
2023-05-24 09:40:41 -04:00
|
|
|
|
2023-12-06 19:02:52 -05:00
|
|
|
// If event was not prevented (or "unhandledrejection" listeners didn't
|
|
|
|
// throw) we will let Rust side handle it.
|
|
|
|
if (rejectionEvent.defaultPrevented) {
|
|
|
|
return true;
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2023-12-06 19:02:52 -05:00
|
|
|
|
|
|
|
return false;
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
|
2024-01-12 17:10:42 -05:00
|
|
|
function processRejectionHandled(promise, reason) {
|
|
|
|
const rejectionHandledEvent = new event.PromiseRejectionEvent(
|
|
|
|
"rejectionhandled",
|
|
|
|
{ promise, reason },
|
|
|
|
);
|
|
|
|
|
|
|
|
// Note that the handler may throw, causing a recursive "error" event
|
|
|
|
globalThis_.dispatchEvent(rejectionHandledEvent);
|
|
|
|
|
|
|
|
if (typeof internals.nodeProcessRejectionHandledCallback !== "undefined") {
|
|
|
|
internals.nodeProcessRejectionHandledCallback(rejectionHandledEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-15 14:08:33 -04:00
|
|
|
function dispatchLoadEvent() {
|
|
|
|
globalThis_.dispatchEvent(new Event("load"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchBeforeUnloadEvent() {
|
|
|
|
return globalThis_.dispatchEvent(
|
|
|
|
new Event("beforeunload", { cancelable: true }),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchUnloadEvent() {
|
|
|
|
globalThis_.dispatchEvent(new Event("unload"));
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
let hasBootstrapped = false;
|
2023-03-07 10:11:54 -05:00
|
|
|
// Set up global properties shared by main and worker runtime.
|
|
|
|
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
|
2023-12-08 08:24:49 -05:00
|
|
|
|
|
|
|
// Set up global properties shared by main and worker runtime that are exposed
|
|
|
|
// by unstable features if those are enabled.
|
2024-09-09 17:44:29 -04:00
|
|
|
function exposeUnstableFeaturesForWindowOrWorkerGlobalScope(unstableFeatures) {
|
|
|
|
const featureIds = ArrayPrototypeMap(
|
|
|
|
ObjectKeys(
|
|
|
|
unstableForWindowOrWorkerGlobalScope,
|
|
|
|
),
|
|
|
|
(k) => k | 0,
|
|
|
|
);
|
2023-12-08 08:24:49 -05:00
|
|
|
|
2024-09-09 17:44:29 -04:00
|
|
|
for (let i = 0; i <= featureIds.length; i++) {
|
|
|
|
const featureId = featureIds[i];
|
|
|
|
if (ArrayPrototypeIncludes(unstableFeatures, featureId)) {
|
|
|
|
const props = unstableForWindowOrWorkerGlobalScope[featureId];
|
|
|
|
ObjectDefineProperties(globalThis, { ...props });
|
2023-12-08 08:24:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-05 08:55:50 -05:00
|
|
|
function shimTemporalDurationToLocaleString() {
|
|
|
|
const DurationFormat = Intl.DurationFormat;
|
|
|
|
if (!DurationFormat) {
|
|
|
|
// Intl.DurationFormat can be disabled with --v8-flags=--no-harmony-intl-duration-format
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const DurationFormatPrototype = DurationFormat.prototype;
|
|
|
|
const formatDuration = uncurryThis(DurationFormatPrototype.format);
|
|
|
|
|
|
|
|
const Duration = Temporal.Duration;
|
|
|
|
const DurationPrototype = Duration.prototype;
|
|
|
|
const desc = ObjectGetOwnPropertyDescriptors(DurationPrototype);
|
|
|
|
const assertDuration = uncurryThis(desc.toLocaleString.value);
|
|
|
|
const getYears = uncurryThis(desc.years.get);
|
|
|
|
const getMonths = uncurryThis(desc.months.get);
|
|
|
|
const getWeeks = uncurryThis(desc.weeks.get);
|
|
|
|
const getDays = uncurryThis(desc.days.get);
|
|
|
|
const getHours = uncurryThis(desc.hours.get);
|
|
|
|
const getMinutes = uncurryThis(desc.minutes.get);
|
|
|
|
const getSeconds = uncurryThis(desc.seconds.get);
|
|
|
|
const getMilliseconds = uncurryThis(desc.milliseconds.get);
|
|
|
|
const getMicroseconds = uncurryThis(desc.microseconds.get);
|
|
|
|
const getNanoseconds = uncurryThis(desc.nanoseconds.get);
|
|
|
|
|
|
|
|
ObjectAssign(DurationPrototype, {
|
|
|
|
toLocaleString(locales = undefined, options) {
|
|
|
|
assertDuration(this);
|
|
|
|
const durationFormat = new DurationFormat(locales, options);
|
|
|
|
const duration = {
|
|
|
|
years: getYears(this),
|
|
|
|
months: getMonths(this),
|
|
|
|
weeks: getWeeks(this),
|
|
|
|
days: getDays(this),
|
|
|
|
hours: getHours(this),
|
|
|
|
minutes: getMinutes(this),
|
|
|
|
seconds: getSeconds(this),
|
|
|
|
milliseconds: getMilliseconds(this),
|
|
|
|
microseconds: getMicroseconds(this),
|
|
|
|
nanoseconds: getNanoseconds(this),
|
|
|
|
};
|
|
|
|
return formatDuration(durationFormat, duration);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-31 16:39:56 -05:00
|
|
|
// NOTE(bartlomieju): remove all the ops that have already been imported using
|
|
|
|
// "virtual op module" (`ext:core/ops`).
|
|
|
|
const NOT_IMPORTED_OPS = [
|
2024-02-05 20:47:10 -05:00
|
|
|
// Related to `Deno.bench()` API
|
2024-01-31 16:39:56 -05:00
|
|
|
"op_bench_now",
|
|
|
|
"op_dispatch_bench_event",
|
2024-02-05 20:47:10 -05:00
|
|
|
"op_register_bench",
|
2024-03-24 01:22:37 -04:00
|
|
|
"op_bench_get_origin",
|
2024-02-05 20:47:10 -05:00
|
|
|
|
|
|
|
// Related to `Deno.jupyter` API
|
|
|
|
"op_jupyter_broadcast",
|
2024-07-04 18:12:14 -04:00
|
|
|
"op_jupyter_input",
|
2024-11-16 10:13:50 -05:00
|
|
|
// Used in jupyter API
|
|
|
|
"op_base64_encode",
|
2024-02-05 20:47:10 -05:00
|
|
|
|
|
|
|
// Related to `Deno.test()` API
|
|
|
|
"op_test_event_step_result_failed",
|
|
|
|
"op_test_event_step_result_ignored",
|
|
|
|
"op_test_event_step_result_ok",
|
|
|
|
"op_test_event_step_wait",
|
|
|
|
"op_test_op_sanitizer_collect",
|
|
|
|
"op_test_op_sanitizer_finish",
|
|
|
|
"op_test_op_sanitizer_get_async_message",
|
|
|
|
"op_test_op_sanitizer_report",
|
|
|
|
"op_restore_test_permissions",
|
|
|
|
"op_register_test_step",
|
|
|
|
"op_register_test",
|
2024-02-27 22:30:17 -05:00
|
|
|
"op_test_get_origin",
|
2024-02-05 20:47:10 -05:00
|
|
|
"op_pledge_test_permissions",
|
|
|
|
|
|
|
|
// TODO(bartlomieju): used in various integration tests - figure out a way
|
|
|
|
// to not depend on them.
|
|
|
|
"op_set_exit_code",
|
|
|
|
"op_napi_open",
|
2024-01-31 16:39:56 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
function removeImportedOps() {
|
|
|
|
const allOpNames = ObjectKeys(ops);
|
|
|
|
for (let i = 0; i < allOpNames.length; i++) {
|
|
|
|
const opName = allOpNames[i];
|
|
|
|
if (!ArrayPrototypeIncludes(NOT_IMPORTED_OPS, opName)) {
|
|
|
|
delete ops[opName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 18:37:03 -04:00
|
|
|
// FIXME(bartlomieju): temporarily add whole `Deno.core` to
|
|
|
|
// `Deno[Deno.internal]` namespace. It should be removed and only necessary
|
|
|
|
// methods should be left there.
|
2024-09-16 19:43:36 -04:00
|
|
|
ObjectAssign(internals, { core });
|
2023-03-07 23:20:54 -05:00
|
|
|
const internalSymbol = Symbol("Deno.internal");
|
|
|
|
const finalDenoNs = {
|
|
|
|
internal: internalSymbol,
|
|
|
|
[internalSymbol]: internals,
|
|
|
|
...denoNs,
|
2023-11-24 22:46:16 -05:00
|
|
|
// Deno.test and Deno.bench are noops here, but kept for compatibility; so
|
|
|
|
// that they don't cause errors when used outside of `deno test`/`deno bench`
|
|
|
|
// contexts.
|
|
|
|
test: () => {},
|
|
|
|
bench: () => {},
|
2023-03-07 23:20:54 -05:00
|
|
|
};
|
2022-07-20 14:28:19 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
ObjectDefineProperties(finalDenoNs, {
|
|
|
|
pid: core.propGetterOnly(opPid),
|
|
|
|
// `ppid` should not be memoized.
|
|
|
|
// https://github.com/denoland/deno/issues/23004
|
|
|
|
ppid: core.propGetterOnly(() => op_ppid()),
|
|
|
|
noColor: core.propGetterOnly(() => op_bootstrap_no_color()),
|
|
|
|
args: core.propGetterOnly(opArgs),
|
|
|
|
mainModule: core.propGetterOnly(() => op_main_module()),
|
2024-05-29 19:16:27 -04:00
|
|
|
exitCode: {
|
2024-09-06 06:52:59 -04:00
|
|
|
__proto__: null,
|
2024-05-29 19:16:27 -04:00
|
|
|
get() {
|
|
|
|
return os.getExitCode();
|
|
|
|
},
|
|
|
|
set(value) {
|
|
|
|
os.setExitCode(value);
|
|
|
|
},
|
|
|
|
},
|
2024-03-22 16:49:07 -04:00
|
|
|
});
|
|
|
|
|
2023-11-15 07:25:55 -05:00
|
|
|
const {
|
|
|
|
tsVersion,
|
|
|
|
v8Version,
|
|
|
|
target,
|
2024-01-31 17:17:49 -05:00
|
|
|
} = op_snapshot_options();
|
2023-11-15 07:25:55 -05:00
|
|
|
|
2024-04-24 15:45:49 -04:00
|
|
|
const executionModes = {
|
|
|
|
none: 0,
|
|
|
|
worker: 1,
|
|
|
|
run: 2,
|
|
|
|
repl: 3,
|
|
|
|
eval: 4,
|
|
|
|
test: 5,
|
|
|
|
bench: 6,
|
|
|
|
serve: 7,
|
|
|
|
jupyter: 8,
|
|
|
|
};
|
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
function bootstrapMainRuntime(runtimeOptions, warmup = false) {
|
|
|
|
if (!warmup) {
|
|
|
|
if (hasBootstrapped) {
|
|
|
|
throw new Error("Worker runtime already bootstrapped");
|
|
|
|
}
|
2022-07-20 14:28:19 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
const {
|
2024-08-15 17:47:16 -04:00
|
|
|
0: denoVersion,
|
|
|
|
1: location_,
|
2024-09-09 17:44:29 -04:00
|
|
|
2: unstableFeatures,
|
|
|
|
3: inspectFlag,
|
|
|
|
5: hasNodeModulesDir,
|
|
|
|
6: argv0,
|
|
|
|
7: nodeDebug,
|
|
|
|
8: mode,
|
|
|
|
9: servePort,
|
|
|
|
10: serveHost,
|
|
|
|
11: serveIsMain,
|
|
|
|
12: serveWorkerCount,
|
2024-11-13 05:38:46 -05:00
|
|
|
13: otelConfig,
|
2024-03-22 16:49:07 -04:00
|
|
|
} = runtimeOptions;
|
|
|
|
|
2024-08-14 18:26:21 -04:00
|
|
|
if (mode === executionModes.serve) {
|
|
|
|
if (serveIsMain && serveWorkerCount) {
|
2024-09-14 17:30:06 -04:00
|
|
|
// deno-lint-ignore no-global-assign
|
|
|
|
console = new internalConsole.Console((msg, level) =>
|
|
|
|
core.print("[serve-worker-0 ] " + msg, level > 1)
|
|
|
|
);
|
2024-08-14 18:26:21 -04:00
|
|
|
} else if (serveWorkerCount !== null) {
|
|
|
|
const base = `serve-worker-${serveWorkerCount + 1}`;
|
|
|
|
// 15 = "serve-worker-nn".length, assuming
|
|
|
|
// serveWorkerCount < 100
|
|
|
|
const prefix = `[${StringPrototypePadEnd(base, 15, " ")}]`;
|
2024-09-14 17:30:06 -04:00
|
|
|
// deno-lint-ignore no-global-assign
|
|
|
|
console = new internalConsole.Console((msg, level) =>
|
|
|
|
core.print(`${prefix} ` + msg, level > 1)
|
|
|
|
);
|
2024-08-14 18:26:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-24 15:45:49 -04:00
|
|
|
if (mode === executionModes.run || mode === executionModes.serve) {
|
|
|
|
let serve = undefined;
|
|
|
|
core.addMainModuleHandler((main) => {
|
|
|
|
if (ObjectHasOwn(main, "default")) {
|
|
|
|
try {
|
|
|
|
serve = registerDeclarativeServer(main.default);
|
|
|
|
} catch (e) {
|
|
|
|
if (mode === executionModes.serve) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode === executionModes.serve && !serve) {
|
2024-08-14 18:26:21 -04:00
|
|
|
if (serveIsMain) {
|
|
|
|
// Only error if main worker
|
2024-08-20 15:14:37 -04:00
|
|
|
// deno-lint-ignore no-console
|
2024-08-14 18:26:21 -04:00
|
|
|
console.error(
|
|
|
|
`%cerror: %cdeno serve requires %cexport default { fetch }%c in the main module, did you mean to run \"deno run\"?`,
|
|
|
|
"color: yellow;",
|
|
|
|
"color: inherit;",
|
|
|
|
"font-weight: bold;",
|
|
|
|
"font-weight: normal;",
|
|
|
|
);
|
|
|
|
}
|
2024-04-24 15:45:49 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serve) {
|
|
|
|
if (mode === executionModes.run) {
|
2024-08-20 15:14:37 -04:00
|
|
|
// deno-lint-ignore no-console
|
2024-04-24 15:45:49 -04:00
|
|
|
console.error(
|
|
|
|
`%cwarning: %cDetected %cexport default { fetch }%c, did you mean to run \"deno serve\"?`,
|
|
|
|
"color: yellow;",
|
|
|
|
"color: inherit;",
|
|
|
|
"font-weight: bold;",
|
|
|
|
"font-weight: normal;",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (mode === executionModes.serve) {
|
2024-08-14 18:26:21 -04:00
|
|
|
serve({ servePort, serveHost, serveIsMain, serveWorkerCount });
|
2024-04-24 15:45:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
removeImportedOps();
|
|
|
|
|
2024-11-08 17:20:24 -05:00
|
|
|
performance.setTimeOrigin();
|
2024-03-22 16:49:07 -04:00
|
|
|
globalThis_ = globalThis;
|
|
|
|
|
|
|
|
// Remove bootstrapping data from the global scope
|
|
|
|
delete globalThis.__bootstrap;
|
|
|
|
delete globalThis.bootstrap;
|
|
|
|
hasBootstrapped = true;
|
|
|
|
|
|
|
|
// If the `--location` flag isn't set, make `globalThis.location` `undefined` and
|
|
|
|
// writable, so that they can mock it themselves if they like. If the flag was
|
|
|
|
// set, define `globalThis.location`, using the provided value.
|
|
|
|
if (location_ == null) {
|
|
|
|
mainRuntimeGlobalProperties.location = {
|
|
|
|
writable: true,
|
2024-09-23 08:18:07 -04:00
|
|
|
configurable: true,
|
2024-03-22 16:49:07 -04:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
location.setLocationHref(location_);
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2024-09-09 17:44:29 -04:00
|
|
|
exposeUnstableFeaturesForWindowOrWorkerGlobalScope(unstableFeatures);
|
2024-03-22 16:49:07 -04:00
|
|
|
ObjectDefineProperties(globalThis, mainRuntimeGlobalProperties);
|
|
|
|
ObjectDefineProperties(globalThis, {
|
|
|
|
// TODO(bartlomieju): in the future we might want to change the
|
|
|
|
// behavior of setting `name` to actually update the process name.
|
|
|
|
// Empty string matches what browsers do.
|
|
|
|
name: core.propWritable(""),
|
|
|
|
close: core.propWritable(windowClose),
|
|
|
|
closed: core.propGetterOnly(() => windowIsClosing),
|
|
|
|
});
|
|
|
|
ObjectSetPrototypeOf(globalThis, Window.prototype);
|
2021-06-26 20:27:50 -04:00
|
|
|
|
2024-11-13 05:38:46 -05:00
|
|
|
bootstrapOtel(otelConfig);
|
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
if (inspectFlag) {
|
2024-11-13 05:38:46 -05:00
|
|
|
core.wrapConsole(globalThis.console, core.v8Console);
|
2024-03-22 16:49:07 -04:00
|
|
|
}
|
2022-08-10 14:57:30 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
event.defineEventHandler(globalThis, "error");
|
|
|
|
event.defineEventHandler(globalThis, "load");
|
|
|
|
event.defineEventHandler(globalThis, "beforeunload");
|
|
|
|
event.defineEventHandler(globalThis, "unload");
|
2021-06-26 20:27:50 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
runtimeStart(
|
|
|
|
denoVersion,
|
|
|
|
v8Version,
|
|
|
|
tsVersion,
|
|
|
|
target,
|
|
|
|
);
|
2021-03-12 15:23:59 -05:00
|
|
|
|
2024-09-04 08:21:02 -04:00
|
|
|
// TODO(bartlomieju): this is not ideal, but because we use `ObjectAssign`
|
|
|
|
// above any properties that are defined elsewhere using `Object.defineProperty`
|
|
|
|
// are lost.
|
|
|
|
let jupyterNs = undefined;
|
|
|
|
ObjectDefineProperty(finalDenoNs, "jupyter", {
|
2024-11-04 12:17:11 -05:00
|
|
|
__proto__: null,
|
2024-09-04 08:21:02 -04:00
|
|
|
get() {
|
|
|
|
if (jupyterNs) {
|
|
|
|
return jupyterNs;
|
|
|
|
}
|
|
|
|
throw new Error(
|
2024-09-13 05:38:45 -04:00
|
|
|
"Deno.jupyter is only available in `deno jupyter` subcommand",
|
2024-09-04 08:21:02 -04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
jupyterNs = val;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-09-09 17:44:29 -04:00
|
|
|
for (let i = 0; i <= unstableFeatures.length; i++) {
|
|
|
|
const id = unstableFeatures[i];
|
|
|
|
ObjectAssign(finalDenoNs, denoNsUnstableById[id]);
|
2023-11-01 18:15:08 -04:00
|
|
|
}
|
2022-11-10 16:03:28 -05:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
if (!ArrayPrototypeIncludes(unstableFeatures, unstableIds.unsafeProto)) {
|
|
|
|
// Removes the `__proto__` for security reasons.
|
|
|
|
// https://tc39.es/ecma262/#sec-get-object.prototype.__proto__
|
|
|
|
delete Object.prototype.__proto__;
|
|
|
|
}
|
2023-11-25 11:41:21 -05:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
if (!ArrayPrototypeIncludes(unstableFeatures, unstableIds.temporal)) {
|
|
|
|
// Removes the `Temporal` API.
|
|
|
|
delete globalThis.Temporal;
|
|
|
|
delete globalThis.Date.prototype.toTemporalInstant;
|
2024-08-02 04:56:14 -04:00
|
|
|
} else {
|
|
|
|
// Removes the obsoleted `Temporal` API.
|
|
|
|
// https://github.com/tc39/proposal-temporal/pull/2895
|
|
|
|
// https://github.com/tc39/proposal-temporal/pull/2914
|
2024-09-10 17:36:43 -04:00
|
|
|
// https://github.com/tc39/proposal-temporal/pull/2925
|
|
|
|
if (typeof globalThis.Temporal.Instant.fromEpochSeconds === "undefined") {
|
2024-09-13 05:38:45 -04:00
|
|
|
throw "V8 removes obsoleted Temporal API now, no need to delete them";
|
2024-08-02 04:56:14 -04:00
|
|
|
}
|
2024-09-10 17:36:43 -04:00
|
|
|
delete globalThis.Temporal.Instant.fromEpochSeconds;
|
|
|
|
delete globalThis.Temporal.Instant.fromEpochMicroseconds;
|
|
|
|
delete globalThis.Temporal.Instant.prototype.epochSeconds;
|
|
|
|
delete globalThis.Temporal.Instant.prototype.epochMicroseconds;
|
|
|
|
delete globalThis.Temporal.Instant.prototype.toZonedDateTime;
|
|
|
|
delete globalThis.Temporal.PlainDate.prototype.getISOFiels; // weird
|
|
|
|
delete globalThis.Temporal.PlainDate.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.PlainDateTime.prototype.withPlainDate;
|
|
|
|
delete globalThis.Temporal.PlainDateTime.prototype.toPlainYearMonth;
|
|
|
|
delete globalThis.Temporal.PlainDateTime.prototype.toPlainMonthDay;
|
|
|
|
delete globalThis.Temporal.PlainDateTime.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.PlainMonthDay.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.PlainTime.prototype.calendar;
|
|
|
|
delete globalThis.Temporal.PlainTime.prototype.toPlainDateTime;
|
|
|
|
delete globalThis.Temporal.PlainTime.prototype.toZonedDateTime;
|
|
|
|
delete globalThis.Temporal.PlainTime.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.PlainYearMonth.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.epochSeconds;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.epochMicroseconds;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.withPlainDate;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.toPlainYearMonth;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.toPlainMonthDay;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.Now.zonedDateTime;
|
|
|
|
delete globalThis.Temporal.Now.plainDateTime;
|
|
|
|
delete globalThis.Temporal.Now.plainDate;
|
|
|
|
delete globalThis.Temporal.Calendar;
|
|
|
|
delete globalThis.Temporal.TimeZone;
|
|
|
|
|
|
|
|
// Modify `Temporal.Calendar` to calendarId string
|
|
|
|
ArrayPrototypeForEach([
|
|
|
|
globalThis.Temporal.PlainDate,
|
|
|
|
globalThis.Temporal.PlainDateTime,
|
|
|
|
globalThis.Temporal.PlainMonthDay,
|
|
|
|
globalThis.Temporal.PlainYearMonth,
|
|
|
|
globalThis.Temporal.ZonedDateTime,
|
|
|
|
], (target) => {
|
|
|
|
const getCalendar =
|
|
|
|
ObjectGetOwnPropertyDescriptor(target.prototype, "calendar").get;
|
|
|
|
ObjectDefineProperty(target.prototype, "calendarId", {
|
|
|
|
__proto__: null,
|
|
|
|
get: function calendarId() {
|
|
|
|
return FunctionPrototypeCall(getCalendar, this).id;
|
|
|
|
},
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
delete target.prototype.calendar;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Modify `Temporal.TimeZone` to timeZoneId string
|
|
|
|
{
|
|
|
|
const getTimeZone = ObjectGetOwnPropertyDescriptor(
|
|
|
|
globalThis.Temporal.ZonedDateTime.prototype,
|
|
|
|
"timeZone",
|
|
|
|
).get;
|
|
|
|
ObjectDefineProperty(
|
|
|
|
globalThis.Temporal.ZonedDateTime.prototype,
|
|
|
|
"timeZoneId",
|
|
|
|
{
|
|
|
|
__proto__: null,
|
|
|
|
get: function timeZoneId() {
|
|
|
|
return FunctionPrototypeCall(getTimeZone, this).id;
|
|
|
|
},
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.timeZone;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const nowTimeZone = globalThis.Temporal.Now.timeZone;
|
|
|
|
ObjectDefineProperty(globalThis.Temporal.Now, "timeZoneId", {
|
|
|
|
__proto__: null,
|
|
|
|
value: function timeZoneId() {
|
|
|
|
return nowTimeZone().id;
|
|
|
|
},
|
|
|
|
writable: true,
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
delete globalThis.Temporal.Now.timeZone;
|
|
|
|
}
|
2024-12-05 08:55:50 -05:00
|
|
|
|
|
|
|
// deno-lint-ignore prefer-primordials
|
|
|
|
if (new Temporal.Duration().toLocaleString("en-US") !== "PT0S") {
|
|
|
|
throw "V8 supports Temporal.Duration.prototype.toLocaleString now, no need to shim it";
|
|
|
|
}
|
|
|
|
shimTemporalDurationToLocaleString();
|
2024-03-22 16:49:07 -04:00
|
|
|
}
|
2024-03-07 18:06:28 -05:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
// Setup `Deno` global - we're actually overriding already existing global
|
|
|
|
// `Deno` with `Deno` namespace from "./deno.ts".
|
|
|
|
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
|
2023-01-24 12:54:10 -05:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
if (nodeBootstrap) {
|
2024-05-05 10:16:02 -04:00
|
|
|
nodeBootstrap({
|
|
|
|
usesLocalNodeModulesDir: hasNodeModulesDir,
|
|
|
|
runningOnMainThread: true,
|
|
|
|
argv0,
|
|
|
|
nodeDebug,
|
|
|
|
});
|
2024-03-22 16:49:07 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Warmup
|
2024-02-14 23:50:17 -05:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
function bootstrapWorkerRuntime(
|
|
|
|
runtimeOptions,
|
|
|
|
name,
|
|
|
|
internalName,
|
2024-03-13 15:52:53 -04:00
|
|
|
workerId,
|
2024-03-11 18:18:03 -04:00
|
|
|
maybeWorkerMetadata,
|
2024-03-22 16:49:07 -04:00
|
|
|
warmup = false,
|
2023-02-07 14:22:46 -05:00
|
|
|
) {
|
2024-03-22 16:49:07 -04:00
|
|
|
if (!warmup) {
|
|
|
|
if (hasBootstrapped) {
|
|
|
|
throw new Error("Worker runtime already bootstrapped");
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
const {
|
2024-08-15 17:47:16 -04:00
|
|
|
0: denoVersion,
|
|
|
|
1: location_,
|
2024-09-09 17:44:29 -04:00
|
|
|
2: unstableFeatures,
|
|
|
|
4: enableTestingFeaturesFlag,
|
|
|
|
5: hasNodeModulesDir,
|
|
|
|
6: argv0,
|
|
|
|
7: nodeDebug,
|
2024-11-13 05:38:46 -05:00
|
|
|
13: otelConfig,
|
2024-03-22 16:49:07 -04:00
|
|
|
} = runtimeOptions;
|
|
|
|
|
2024-11-08 17:20:24 -05:00
|
|
|
performance.setTimeOrigin();
|
2024-03-22 16:49:07 -04:00
|
|
|
globalThis_ = globalThis;
|
|
|
|
|
|
|
|
// Remove bootstrapping data from the global scope
|
|
|
|
delete globalThis.__bootstrap;
|
|
|
|
delete globalThis.bootstrap;
|
|
|
|
hasBootstrapped = true;
|
|
|
|
|
2024-09-09 17:44:29 -04:00
|
|
|
exposeUnstableFeaturesForWindowOrWorkerGlobalScope(unstableFeatures);
|
2024-03-22 16:49:07 -04:00
|
|
|
ObjectDefineProperties(globalThis, workerRuntimeGlobalProperties);
|
|
|
|
ObjectDefineProperties(globalThis, {
|
|
|
|
name: core.propWritable(name),
|
|
|
|
// TODO(bartlomieju): should be readonly?
|
|
|
|
close: core.propNonEnumerable(workerClose),
|
|
|
|
postMessage: core.propWritable(postMessage),
|
|
|
|
});
|
|
|
|
if (enableTestingFeaturesFlag) {
|
|
|
|
ObjectDefineProperty(
|
|
|
|
globalThis,
|
|
|
|
"importScripts",
|
|
|
|
core.propWritable(importScripts),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
ObjectSetPrototypeOf(globalThis, DedicatedWorkerGlobalScope.prototype);
|
2021-06-26 20:27:50 -04:00
|
|
|
|
2024-11-13 05:38:46 -05:00
|
|
|
bootstrapOtel(otelConfig);
|
|
|
|
|
|
|
|
core.wrapConsole(globalThis.console, core.v8Console);
|
2021-06-26 20:27:50 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
event.defineEventHandler(self, "message");
|
|
|
|
event.defineEventHandler(self, "error", undefined, true);
|
2021-06-26 20:27:50 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
// `Deno.exit()` is an alias to `self.close()`. Setting and exit
|
|
|
|
// code using an op in worker context is a no-op.
|
|
|
|
os.setExitHandler((_exitCode) => {
|
|
|
|
workerClose();
|
|
|
|
});
|
2022-07-20 14:28:19 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
runtimeStart(
|
|
|
|
denoVersion,
|
|
|
|
v8Version,
|
|
|
|
tsVersion,
|
|
|
|
target,
|
|
|
|
internalName ?? name,
|
|
|
|
);
|
2022-07-20 14:28:19 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
location.setLocationHref(location_);
|
2021-07-10 17:32:10 -04:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
globalThis.pollForMessages = pollForMessages;
|
|
|
|
globalThis.hasMessageEventListener = hasMessageEventListener;
|
2022-11-21 08:36:26 -05:00
|
|
|
|
2024-09-09 17:44:29 -04:00
|
|
|
for (let i = 0; i <= unstableFeatures.length; i++) {
|
|
|
|
const id = unstableFeatures[i];
|
|
|
|
ObjectAssign(finalDenoNs, denoNsUnstableById[id]);
|
2023-11-01 18:15:08 -04:00
|
|
|
}
|
2023-11-25 11:41:21 -05:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
// Not available in workers
|
|
|
|
delete finalDenoNs.mainModule;
|
2023-11-25 11:41:21 -05:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
if (!ArrayPrototypeIncludes(unstableFeatures, unstableIds.unsafeProto)) {
|
|
|
|
// Removes the `__proto__` for security reasons.
|
|
|
|
// https://tc39.es/ecma262/#sec-get-object.prototype.__proto__
|
|
|
|
delete Object.prototype.__proto__;
|
|
|
|
}
|
2024-03-07 18:06:28 -05:00
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
if (!ArrayPrototypeIncludes(unstableFeatures, unstableIds.temporal)) {
|
|
|
|
// Removes the `Temporal` API.
|
|
|
|
delete globalThis.Temporal;
|
|
|
|
delete globalThis.Date.prototype.toTemporalInstant;
|
2024-08-02 04:56:14 -04:00
|
|
|
} else {
|
|
|
|
// Removes the obsoleted `Temporal` API.
|
|
|
|
// https://github.com/tc39/proposal-temporal/pull/2895
|
|
|
|
// https://github.com/tc39/proposal-temporal/pull/2914
|
2024-09-10 17:36:43 -04:00
|
|
|
// https://github.com/tc39/proposal-temporal/pull/2925
|
|
|
|
if (typeof globalThis.Temporal.Instant.fromEpochSeconds === "undefined") {
|
2024-09-13 05:38:45 -04:00
|
|
|
throw "V8 removes obsoleted Temporal API now, no need to delete them";
|
2024-08-02 04:56:14 -04:00
|
|
|
}
|
2024-09-10 17:36:43 -04:00
|
|
|
delete globalThis.Temporal.Instant.fromEpochSeconds;
|
|
|
|
delete globalThis.Temporal.Instant.fromEpochMicroseconds;
|
|
|
|
delete globalThis.Temporal.Instant.prototype.epochSeconds;
|
|
|
|
delete globalThis.Temporal.Instant.prototype.epochMicroseconds;
|
|
|
|
delete globalThis.Temporal.Instant.prototype.toZonedDateTime;
|
|
|
|
delete globalThis.Temporal.PlainDate.prototype.getISOFiels; // weird
|
|
|
|
delete globalThis.Temporal.PlainDate.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.PlainDateTime.prototype.withPlainDate;
|
|
|
|
delete globalThis.Temporal.PlainDateTime.prototype.toPlainYearMonth;
|
|
|
|
delete globalThis.Temporal.PlainDateTime.prototype.toPlainMonthDay;
|
|
|
|
delete globalThis.Temporal.PlainDateTime.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.PlainMonthDay.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.PlainTime.prototype.calendar;
|
|
|
|
delete globalThis.Temporal.PlainTime.prototype.toPlainDateTime;
|
|
|
|
delete globalThis.Temporal.PlainTime.prototype.toZonedDateTime;
|
|
|
|
delete globalThis.Temporal.PlainTime.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.PlainYearMonth.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.epochSeconds;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.epochMicroseconds;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.withPlainDate;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.toPlainYearMonth;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.toPlainMonthDay;
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.getISOFields;
|
|
|
|
delete globalThis.Temporal.Now.zonedDateTime;
|
|
|
|
delete globalThis.Temporal.Now.plainDateTime;
|
|
|
|
delete globalThis.Temporal.Now.plainDate;
|
|
|
|
delete globalThis.Temporal.Calendar;
|
|
|
|
delete globalThis.Temporal.TimeZone;
|
|
|
|
|
|
|
|
// Modify `Temporal.Calendar` to calendarId string
|
|
|
|
ArrayPrototypeForEach([
|
|
|
|
globalThis.Temporal.PlainDate,
|
|
|
|
globalThis.Temporal.PlainDateTime,
|
|
|
|
globalThis.Temporal.PlainMonthDay,
|
|
|
|
globalThis.Temporal.PlainYearMonth,
|
|
|
|
globalThis.Temporal.ZonedDateTime,
|
|
|
|
], (target) => {
|
|
|
|
const getCalendar =
|
|
|
|
ObjectGetOwnPropertyDescriptor(target.prototype, "calendar").get;
|
|
|
|
ObjectDefineProperty(target.prototype, "calendarId", {
|
|
|
|
__proto__: null,
|
|
|
|
get: function calendarId() {
|
|
|
|
return FunctionPrototypeCall(getCalendar, this).id;
|
|
|
|
},
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
delete target.prototype.calendar;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Modify `Temporal.TimeZone` to timeZoneId string
|
|
|
|
{
|
|
|
|
const getTimeZone = ObjectGetOwnPropertyDescriptor(
|
|
|
|
globalThis.Temporal.ZonedDateTime.prototype,
|
|
|
|
"timeZone",
|
|
|
|
).get;
|
|
|
|
ObjectDefineProperty(
|
|
|
|
globalThis.Temporal.ZonedDateTime.prototype,
|
|
|
|
"timeZoneId",
|
|
|
|
{
|
|
|
|
__proto__: null,
|
|
|
|
get: function timeZoneId() {
|
|
|
|
return FunctionPrototypeCall(getTimeZone, this).id;
|
|
|
|
},
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
delete globalThis.Temporal.ZonedDateTime.prototype.timeZone;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const nowTimeZone = globalThis.Temporal.Now.timeZone;
|
|
|
|
ObjectDefineProperty(globalThis.Temporal.Now, "timeZoneId", {
|
|
|
|
__proto__: null,
|
|
|
|
value: function timeZoneId() {
|
|
|
|
return nowTimeZone().id;
|
|
|
|
},
|
|
|
|
writable: true,
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
delete globalThis.Temporal.Now.timeZone;
|
|
|
|
}
|
2024-12-05 08:55:50 -05:00
|
|
|
|
|
|
|
shimTemporalDurationToLocaleString();
|
2024-03-22 16:49:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup `Deno` global - we're actually overriding already existing global
|
|
|
|
// `Deno` with `Deno` namespace from "./deno.ts".
|
|
|
|
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
|
|
|
|
|
|
|
|
const workerMetadata = maybeWorkerMetadata
|
|
|
|
? messagePort.deserializeJsMessageData(maybeWorkerMetadata)
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
if (nodeBootstrap) {
|
2024-05-05 10:16:02 -04:00
|
|
|
nodeBootstrap({
|
|
|
|
usesLocalNodeModulesDir: hasNodeModulesDir,
|
|
|
|
runningOnMainThread: false,
|
2024-03-22 16:49:07 -04:00
|
|
|
argv0,
|
|
|
|
workerId,
|
2024-05-05 10:16:02 -04:00
|
|
|
maybeWorkerMetadata: workerMetadata,
|
|
|
|
nodeDebug,
|
|
|
|
});
|
2024-03-22 16:49:07 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Warmup
|
|
|
|
return;
|
2023-08-15 15:36:36 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
|
2024-03-22 16:49:07 -04:00
|
|
|
const nodeBootstrap = globalThis.nodeBootstrap;
|
|
|
|
delete globalThis.nodeBootstrap;
|
2024-04-16 09:45:41 -04:00
|
|
|
const dispatchProcessExitEvent = internals.dispatchProcessExitEvent;
|
|
|
|
delete internals.dispatchProcessExitEvent;
|
|
|
|
const dispatchProcessBeforeExitEvent = internals.dispatchProcessBeforeExitEvent;
|
|
|
|
delete internals.dispatchProcessBeforeExitEvent;
|
2024-03-22 16:49:07 -04:00
|
|
|
|
2023-03-07 10:11:54 -05:00
|
|
|
globalThis.bootstrap = {
|
|
|
|
mainRuntime: bootstrapMainRuntime,
|
|
|
|
workerRuntime: bootstrapWorkerRuntime,
|
2024-04-15 14:08:33 -04:00
|
|
|
dispatchLoadEvent,
|
|
|
|
dispatchUnloadEvent,
|
|
|
|
dispatchBeforeUnloadEvent,
|
2024-04-16 09:45:41 -04:00
|
|
|
dispatchProcessExitEvent,
|
|
|
|
dispatchProcessBeforeExitEvent,
|
2023-03-07 10:11:54 -05:00
|
|
|
};
|
2024-03-22 16:49:07 -04:00
|
|
|
|
|
|
|
event.setEventTargetData(globalThis);
|
|
|
|
event.saveGlobalThisReference(globalThis);
|
|
|
|
event.defineEventHandler(globalThis, "unhandledrejection");
|
|
|
|
|
|
|
|
// Nothing listens to this, but it warms up the code paths for event dispatch
|
|
|
|
(new event.EventTarget()).dispatchEvent(new Event("warmup"));
|
|
|
|
|
|
|
|
removeImportedOps();
|
|
|
|
|
|
|
|
// Run the warmup path through node and runtime/worker bootstrap functions
|
|
|
|
bootstrapMainRuntime(undefined, true);
|
|
|
|
bootstrapWorkerRuntime(
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
true,
|
|
|
|
);
|
2024-05-05 10:16:02 -04:00
|
|
|
nodeBootstrap({ warmup: true });
|