summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2021-07-02 12:18:30 +0200
committerGitHub <noreply@github.com>2021-07-02 12:18:30 +0200
commitc9204c4aee81a0e61fe591bf97cdb0956de5f1eb (patch)
tree9252569ebb46405f3232b1a1e2b0210cce6994fc
parent7b0375fae7578c0c7e4f4229e59ad5046ecf75ab (diff)
refactor: introduce primordials (#10939)
This commit introduces primordials to deno_core. Primordials are a frozen set of all intrinsic objects in the runtime. They are not vulnerable to prototype pollution.
-rw-r--r--core/00_primordials.js462
-rw-r--r--core/01_core.js (renamed from core/core.js)43
-rw-r--r--core/02_error.js (renamed from core/error.js)72
-rw-r--r--core/internal.d.ts902
-rw-r--r--core/ops_builtin.rs5
-rw-r--r--core/runtime.rs10
6 files changed, 1447 insertions, 47 deletions
diff --git a/core/00_primordials.js b/core/00_primordials.js
new file mode 100644
index 000000000..85d924a00
--- /dev/null
+++ b/core/00_primordials.js
@@ -0,0 +1,462 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+// Based on https://github.com/nodejs/node/blob/889ad35d3d41e376870f785b0c1b669cb732013d/lib/internal/per_context/primordials.js
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+// This file subclasses and stores the JS builtins that come from the VM
+// so that Node.js's builtin modules do not need to later look these up from
+// the global proxy, which can be mutated by users.
+
+// Use of primordials have sometimes a dramatic impact on performance, please
+// benchmark all changes made in performance-sensitive areas of the codebase.
+// See: https://github.com/nodejs/node/pull/38248
+
+"use strict";
+
+(() => {
+ const primordials = {};
+
+ const {
+ defineProperty: ReflectDefineProperty,
+ getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
+ ownKeys: ReflectOwnKeys,
+ } = Reflect;
+
+ // `uncurryThis` is equivalent to `func => Function.prototype.call.bind(func)`.
+ // It is using `bind.bind(call)` to avoid using `Function.prototype.bind`
+ // and `Function.prototype.call` after it may have been mutated by users.
+ const { apply, bind, call } = Function.prototype;
+ const uncurryThis = bind.bind(call);
+ primordials.uncurryThis = uncurryThis;
+
+ // `applyBind` is equivalent to `func => Function.prototype.apply.bind(func)`.
+ // It is using `bind.bind(apply)` to avoid using `Function.prototype.bind`
+ // and `Function.prototype.apply` after it may have been mutated by users.
+ const applyBind = bind.bind(apply);
+ primordials.applyBind = applyBind;
+
+ // Methods that accept a variable number of arguments, and thus it's useful to
+ // also create `${prefix}${key}Apply`, which uses `Function.prototype.apply`,
+ // instead of `Function.prototype.call`, and thus doesn't require iterator
+ // destructuring.
+ const varargsMethods = [
+ // 'ArrayPrototypeConcat' is omitted, because it performs the spread
+ // on its own for arrays and array-likes with a truthy
+ // @@isConcatSpreadable symbol property.
+ "ArrayOf",
+ "ArrayPrototypePush",
+ "ArrayPrototypeUnshift",
+ // 'FunctionPrototypeCall' is omitted, since there's 'ReflectApply'
+ // and 'FunctionPrototypeApply'.
+ "MathHypot",
+ "MathMax",
+ "MathMin",
+ "StringPrototypeConcat",
+ "TypedArrayOf",
+ ];
+
+ function getNewKey(key) {
+ return typeof key === "symbol"
+ ? `Symbol${key.description[7].toUpperCase()}${key.description.slice(8)}`
+ : `${key[0].toUpperCase()}${key.slice(1)}`;
+ }
+
+ function copyAccessor(dest, prefix, key, { enumerable, get, set }) {
+ ReflectDefineProperty(dest, `${prefix}Get${key}`, {
+ value: uncurryThis(get),
+ enumerable,
+ });
+ if (set !== undefined) {
+ ReflectDefineProperty(dest, `${prefix}Set${key}`, {
+ value: uncurryThis(set),
+ enumerable,
+ });
+ }
+ }
+
+ function copyPropsRenamed(src, dest, prefix) {
+ for (const key of ReflectOwnKeys(src)) {
+ const newKey = getNewKey(key);
+ const desc = ReflectGetOwnPropertyDescriptor(src, key);
+ if ("get" in desc) {
+ copyAccessor(dest, prefix, newKey, desc);
+ } else {
+ const name = `${prefix}${newKey}`;
+ ReflectDefineProperty(dest, name, desc);
+ if (varargsMethods.includes(name)) {
+ ReflectDefineProperty(dest, `${name}Apply`, {
+ // `src` is bound as the `this` so that the static `this` points
+ // to the object it was defined on,
+ // e.g.: `ArrayOfApply` gets a `this` of `Array`:
+ value: applyBind(desc.value, src),
+ });
+ }
+ }
+ }
+ }
+
+ function copyPropsRenamedBound(src, dest, prefix) {
+ for (const key of ReflectOwnKeys(src)) {
+ const newKey = getNewKey(key);
+ const desc = ReflectGetOwnPropertyDescriptor(src, key);
+ if ("get" in desc) {
+ copyAccessor(dest, prefix, newKey, desc);
+ } else {
+ const { value } = desc;
+ if (typeof value === "function") {
+ desc.value = value.bind(src);
+ }
+
+ const name = `${prefix}${newKey}`;
+ ReflectDefineProperty(dest, name, desc);
+ if (varargsMethods.includes(name)) {
+ ReflectDefineProperty(dest, `${name}Apply`, {
+ value: applyBind(value, src),
+ });
+ }
+ }
+ }
+ }
+
+ function copyPrototype(src, dest, prefix) {
+ for (const key of ReflectOwnKeys(src)) {
+ const newKey = getNewKey(key);
+ const desc = ReflectGetOwnPropertyDescriptor(src, key);
+ if ("get" in desc) {
+ copyAccessor(dest, prefix, newKey, desc);
+ } else {
+ const { value } = desc;
+ if (typeof value === "function") {
+ desc.value = uncurryThis(value);
+ }
+
+ const name = `${prefix}${newKey}`;
+ ReflectDefineProperty(dest, name, desc);
+ if (varargsMethods.includes(name)) {
+ ReflectDefineProperty(dest, `${name}Apply`, {
+ value: applyBind(value),
+ });
+ }
+ }
+ }
+ }
+
+ // Create copies of configurable value properties of the global object
+ [
+ "Proxy",
+ "globalThis",
+ ].forEach((name) => {
+ primordials[name] = globalThis[name];
+ });
+
+ // Create copies of URI handling functions
+ [
+ decodeURI,
+ decodeURIComponent,
+ encodeURI,
+ encodeURIComponent,
+ ].forEach((fn) => {
+ primordials[fn.name] = fn;
+ });
+
+ // Create copies of the namespace objects
+ [
+ "JSON",
+ "Math",
+ "Proxy",
+ "Reflect",
+ ].forEach((name) => {
+ copyPropsRenamed(globalThis[name], primordials, name);
+ });
+
+ // Create copies of intrinsic objects
+ [
+ "AggregateError",
+ "Array",
+ "ArrayBuffer",
+ "BigInt",
+ "BigInt64Array",
+ "BigUint64Array",
+ "Boolean",
+ "DataView",
+ "Date",
+ "Error",
+ "EvalError",
+ // TODO(lucacasonato): not present in snapshots. Why?
+ // "FinalizationRegistry",
+ "Float32Array",
+ "Float64Array",
+ "Function",
+ "Int16Array",
+ "Int32Array",
+ "Int8Array",
+ "Map",
+ "Number",
+ "Object",
+ "RangeError",
+ "ReferenceError",
+ "RegExp",
+ "Set",
+ "String",
+ "Symbol",
+ "SyntaxError",
+ "TypeError",
+ "URIError",
+ "Uint16Array",
+ "Uint32Array",
+ "Uint8Array",
+ "Uint8ClampedArray",
+ "WeakMap",
+ // TODO(lucacasonato): not present in snapshots. Why?
+ // "WeakRef",
+ "WeakSet",
+ ].forEach((name) => {
+ const original = globalThis[name];
+ primordials[name] = original;
+ copyPropsRenamed(original, primordials, name);
+ copyPrototype(original.prototype, primordials, `${name}Prototype`);
+ });
+
+ // Create copies of intrinsic objects that require a valid `this` to call
+ // static methods.
+ // Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all
+ [
+ "Promise",
+ ].forEach((name) => {
+ const original = globalThis[name];
+ primordials[name] = original;
+ copyPropsRenamedBound(original, primordials, name);
+ copyPrototype(original.prototype, primordials, `${name}Prototype`);
+ });
+
+ // Create copies of abstract intrinsic objects that are not directly exposed
+ // on the global object.
+ // Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
+ [
+ { name: "TypedArray", original: Reflect.getPrototypeOf(Uint8Array) },
+ {
+ name: "ArrayIterator",
+ original: {
+ prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
+ },
+ },
+ {
+ name: "StringIterator",
+ original: {
+ prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),
+ },
+ },
+ ].forEach(({ name, original }) => {
+ primordials[name] = original;
+ // The static %TypedArray% methods require a valid `this`, but can't be bound,
+ // as they need a subclass constructor as the receiver:
+ copyPrototype(original, primordials, name);
+ copyPrototype(original.prototype, primordials, `${name}Prototype`);
+ });
+
+ const {
+ ArrayPrototypeForEach,
+ FunctionPrototypeCall,
+ Map,
+ ObjectFreeze,
+ ObjectSetPrototypeOf,
+ Promise,
+ PromisePrototypeThen,
+ Set,
+ SymbolIterator,
+ WeakMap,
+ WeakSet,
+ } = primordials;
+
+ // Because these functions are used by `makeSafe`, which is exposed
+ // on the `primordials` object, it's important to use const references
+ // to the primordials that they use:
+ const createSafeIterator = (factory, next) => {
+ class SafeIterator {
+ constructor(iterable) {
+ this._iterator = factory(iterable);
+ }
+ next() {
+ return next(this._iterator);
+ }
+ [SymbolIterator]() {
+ return this;
+ }
+ }
+ ObjectSetPrototypeOf(SafeIterator.prototype, null);
+ ObjectFreeze(SafeIterator.prototype);
+ ObjectFreeze(SafeIterator);
+ return SafeIterator;
+ };
+
+ primordials.SafeArrayIterator = createSafeIterator(
+ primordials.ArrayPrototypeSymbolIterator,
+ primordials.ArrayIteratorPrototypeNext,
+ );
+ primordials.SafeStringIterator = createSafeIterator(
+ primordials.StringPrototypeSymbolIterator,
+ primordials.StringIteratorPrototypeNext,
+ );
+
+ const copyProps = (src, dest) => {
+ ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {
+ if (!ReflectGetOwnPropertyDescriptor(dest, key)) {
+ ReflectDefineProperty(
+ dest,
+ key,
+ ReflectGetOwnPropertyDescriptor(src, key),
+ );
+ }
+ });
+ };
+
+ /**
+ * @type {typeof primordials.makeSafe}
+ */
+ const makeSafe = (unsafe, safe) => {
+ if (SymbolIterator in unsafe.prototype) {
+ const dummy = new unsafe();
+ let next; // We can reuse the same `next` method.
+
+ ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => {
+ if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) {
+ const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key);
+ if (
+ typeof desc.value === "function" &&
+ desc.value.length === 0 &&
+ SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {})
+ ) {
+ const createIterator = uncurryThis(desc.value);
+ next ??= uncurryThis(createIterator(dummy).next);
+ const SafeIterator = createSafeIterator(createIterator, next);
+ desc.value = function () {
+ return new SafeIterator(this);
+ };
+ }
+ ReflectDefineProperty(safe.prototype, key, desc);
+ }
+ });
+ } else {
+ copyProps(unsafe.prototype, safe.prototype);
+ }
+ copyProps(unsafe, safe);
+
+ ObjectSetPrototypeOf(safe.prototype, null);
+ ObjectFreeze(safe.prototype);
+ ObjectFreeze(safe);
+ return safe;
+ };
+ primordials.makeSafe = makeSafe;
+
+ // Subclass the constructors because we need to use their prototype
+ // methods later.
+ // Defining the `constructor` is necessary here to avoid the default
+ // constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`.
+ primordials.SafeMap = makeSafe(
+ Map,
+ class SafeMap extends Map {
+ constructor(i) {
+ super(i);
+ }
+ },
+ );
+ primordials.SafeWeakMap = makeSafe(
+ WeakMap,
+ class SafeWeakMap extends WeakMap {
+ constructor(i) {
+ super(i);
+ }
+ },
+ );
+
+ primordials.SafeSet = makeSafe(
+ Set,
+ class SafeSet extends Set {
+ constructor(i) {
+ super(i);
+ }
+ },
+ );
+ primordials.SafeWeakSet = makeSafe(
+ WeakSet,
+ class SafeWeakSet extends WeakSet {
+ constructor(i) {
+ super(i);
+ }
+ },
+ );
+
+ // TODO(lucacasonato): not present in snapshots. Why?
+ // primordials.SafeFinalizationRegistry = makeSafe(
+ // FinalizationRegistry,
+ // class SafeFinalizationRegistry extends FinalizationRegistry {
+ // constructor(cleanupCallback) {
+ // super(cleanupCallback);
+ // }
+ // },
+ // );
+
+ // TODO(lucacasonato): not present in snapshots. Why?
+ // primordials.SafeWeakRef = makeSafe(
+ // WeakRef,
+ // class SafeWeakRef extends WeakRef {
+ // constructor(target) {
+ // super(target);
+ // }
+ // },
+ // );
+
+ const SafePromise = makeSafe(
+ Promise,
+ class SafePromise extends Promise {
+ constructor(executor) {
+ super(executor);
+ }
+ },
+ );
+
+ primordials.PromisePrototypeCatch = (thisPromise, onRejected) =>
+ PromisePrototypeThen(thisPromise, undefined, onRejected);
+
+ /**
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or
+ * rejected). The resolved value cannot be modified from the callback.
+ * Prefer using async functions when possible.
+ * @param {Promise<any>} thisPromise
+ * @param {() => void) | undefined | null} onFinally The callback to execute
+ * when the Promise is settled (fulfilled or rejected).
+ * @returns A Promise for the completion of the callback.
+ */
+ primordials.SafePromisePrototypeFinally = (thisPromise, onFinally) =>
+ // Wrapping on a new Promise is necessary to not expose the SafePromise
+ // prototype to user-land.
+ new Promise((a, b) =>
+ new SafePromise((a, b) => PromisePrototypeThen(thisPromise, a, b))
+ .finally(onFinally)
+ .then(a, b)
+ );
+
+ ObjectSetPrototypeOf(primordials, null);
+ ObjectFreeze(primordials);
+
+ // Provide bootstrap namespace
+ globalThis.__bootstrap = { primordials };
+})();
diff --git a/core/core.js b/core/01_core.js
index 9ce563869..74e00b5df 100644
--- a/core/core.js
+++ b/core/01_core.js
@@ -2,6 +2,26 @@
"use strict";
((window) => {
+ const {
+ Error,
+ RangeError,
+ ReferenceError,
+ SyntaxError,
+ TypeError,
+ URIError,
+ Map,
+ Array,
+ ArrayPrototypeFill,
+ Promise,
+ ObjectFreeze,
+ ObjectFromEntries,
+ MapPrototypeGet,
+ MapPrototypeDelete,
+ MapPrototypeSet,
+ PromisePrototypeThen,
+ ObjectAssign,
+ } = window.__bootstrap.primordials;
+
// Available on start due to bindings.
const { opcall } = window.Deno.core;
@@ -19,7 +39,7 @@
const promiseMap = new Map();
const RING_SIZE = 4 * 1024;
const NO_PROMISE = null; // Alias to null is faster than plain nulls
- const promiseRing = new Array(RING_SIZE).fill(NO_PROMISE);
+ const promiseRing = ArrayPrototypeFill(new Array(RING_SIZE), NO_PROMISE);
function setPromise(promiseId) {
const idx = promiseId % RING_SIZE;
@@ -27,7 +47,7 @@
const oldPromise = promiseRing[idx];
if (oldPromise !== NO_PROMISE) {
const oldPromiseId = promiseId - RING_SIZE;
- promiseMap.set(oldPromiseId, oldPromise);
+ MapPrototypeSet(promiseMap, oldPromiseId, oldPromise);
}
// Set new promise
return promiseRing[idx] = newPromise();
@@ -37,8 +57,8 @@
// Check if out of ring bounds, fallback to map
const outOfBounds = promiseId < nextPromiseId - RING_SIZE;
if (outOfBounds) {
- const promise = promiseMap.get(promiseId);
- promiseMap.delete(promiseId);
+ const promise = MapPrototypeGet(promiseMap, promiseId);
+ MapPrototypeDelete(promiseMap, promiseId);
return promise;
}
// Otherwise take from ring
@@ -65,7 +85,7 @@
function syncOpsCache() {
// op id 0 is a special value to retrieve the map of registered ops.
- opsCache = Object.freeze(Object.fromEntries(opcall(0)));
+ opsCache = ObjectFreeze(ObjectFromEntries(opcall(0)));
}
function handleAsyncMsgFromRust() {
@@ -113,7 +133,7 @@
const maybeError = dispatch(opName, promiseId, arg1, arg2);
// Handle sync error (e.g: error parsing args)
if (maybeError) return unwrapOpResult(maybeError);
- return setPromise(promiseId).then(unwrapOpResult);
+ return PromisePrototypeThen(setPromise(promiseId), unwrapOpResult);
}
function opSync(opName, arg1 = null, arg2 = null) {
@@ -121,7 +141,7 @@
}
function resources() {
- return Object.fromEntries(opSync("op_resources"));
+ return ObjectFromEntries(opSync("op_resources"));
}
function close(rid) {
@@ -149,10 +169,8 @@
}
}
- // Provide bootstrap namespace
- window.__bootstrap = {};
// Extra Deno.core.* exports
- Object.assign(window.Deno.core, {
+ const core = ObjectAssign(globalThis.Deno.core, {
opAsync,
opSync,
ops,
@@ -166,4 +184,7 @@
BadResource,
Interrupted,
});
-})(this);
+
+ ObjectAssign(globalThis.__bootstrap, { core });
+ ObjectAssign(globalThis.Deno, { core });
+})(globalThis);
diff --git a/core/error.js b/core/02_error.js
index cf1bc8b0a..c6f642630 100644
--- a/core/error.js
+++ b/core/02_error.js
@@ -2,6 +2,18 @@
"use strict";
((window) => {
+ const {
+ Error,
+ ObjectFreeze,
+ ObjectAssign,
+ StringPrototypeStartsWith,
+ StringPrototypeEndsWith,
+ ObjectDefineProperties,
+ ArrayPrototypePush,
+ ArrayPrototypeMap,
+ ArrayPrototypeJoin,
+ } = window.__bootstrap.primordials;
+
// Some of the code here is adapted directly from V8 and licensed under a BSD
// style license available here: https://github.com/v8/v8/blob/24886f2d1c565287d33d71e4109a53bf0b54b75c/LICENSE.v8
function patchCallSite(callSite, location) {
@@ -117,13 +129,13 @@
if (functionName) {
if (typeName) {
- if (!functionName.startsWith(typeName)) {
+ if (!StringPrototypeStartsWith(functionName, typeName)) {
result += `${typeName}.`;
}
}
result += functionName;
if (methodName) {
- if (!functionName.endsWith(methodName)) {
+ if (!StringPrototypeEndsWith(functionName, methodName)) {
result += ` [as ${methodName}]`;
}
}
@@ -198,34 +210,32 @@
error,
callSites,
) {
- const mappedCallSites = callSites.map(
- (callSite) => {
- const fileName = callSite.getFileName();
- const lineNumber = callSite.getLineNumber();
- const columnNumber = callSite.getColumnNumber();
- if (
- sourceMappingFn && fileName && lineNumber != null &&
- columnNumber != null
- ) {
- return patchCallSite(
- callSite,
- sourceMappingFn({
- fileName,
- lineNumber,
- columnNumber,
- }),
- );
- }
- return callSite;
- },
- );
- Object.defineProperties(error, {
+ const mappedCallSites = ArrayPrototypeMap(callSites, (callSite) => {
+ const fileName = callSite.getFileName();
+ const lineNumber = callSite.getLineNumber();
+ const columnNumber = callSite.getColumnNumber();
+ if (
+ sourceMappingFn && fileName && lineNumber != null &&
+ columnNumber != null
+ ) {
+ return patchCallSite(
+ callSite,
+ sourceMappingFn({
+ fileName,
+ lineNumber,
+ columnNumber,
+ }),
+ );
+ }
+ return callSite;
+ });
+ ObjectDefineProperties(error, {
__callSiteEvals: { value: [], configurable: true },
});
const formattedCallSites = [];
for (const callSite of mappedCallSites) {
- error.__callSiteEvals.push(evaluateCallSite(callSite));
- formattedCallSites.push(formatCallSite(callSite));
+ ArrayPrototypePush(error.__callSiteEvals, evaluateCallSite(callSite));
+ ArrayPrototypePush(formattedCallSites, formatCallSite(callSite));
}
const message = error.message !== undefined ? error.message : "";
const name = error.name !== undefined ? error.name : "Error";
@@ -238,11 +248,13 @@
messageLine = "";
}
return messageLine +
- formattedCallSites.map((s) => `\n at ${s}`).join("");
+ ArrayPrototypeJoin(
+ ArrayPrototypeMap(formattedCallSites, (s) => `\n at ${s}`),
+ "",
+ );
};
}
- Object.assign(window.Deno.core, {
- createPrepareStackTrace,
- });
+ ObjectAssign(globalThis.__bootstrap.core, { createPrepareStackTrace });
+ ObjectFreeze(globalThis.__bootstrap.core);
})(this);
diff --git a/core/internal.d.ts b/core/internal.d.ts
new file mode 100644
index 000000000..5586ad49b
--- /dev/null
+++ b/core/internal.d.ts
@@ -0,0 +1,902 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+// Based on https://github.com/nodejs/node/blob/889ad35d3d41e376870f785b0c1b669cb732013d/typings/primordials.d.ts
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+// This file subclasses and stores the JS builtins that come from the VM
+// so that Node.js's builtin modules do not need to later look these up from
+// the global proxy, which can be mutated by users.
+
+/// <reference no-default-lib="true" />
+/// <reference lib="esnext" />
+
+declare namespace __bootstrap {
+ /**
+ * Primordials are a way to safely use globals without fear of global mutation
+ * Generally, this means removing `this` parameter usage and instead using
+ * a regular parameter:
+ *
+ * @example
+ *
+ * ```js
+ * 'thing'.startsWith('hello');
+ * ```
+ *
+ * becomes
+ *
+ * ```js
+ * primordials.StringPrototypeStartsWith('thing', 'hello')
+ * ```
+ */
+ declare namespace primordials {
+ type UncurryThis<T extends (this: unknown, ...args: unknown[]) => unknown> =
+ (
+ self: ThisParameterType<T>,
+ ...args: Parameters<T>
+ ) => ReturnType<T>;
+ type UncurryThisStaticApply<
+ T extends (this: unknown, ...args: unknown[]) => unknown,
+ > = (self: ThisParameterType<T>, args: Parameters<T>) => ReturnType<T>;
+ type StaticApply<T extends (this: unknown, ...args: unknown[]) => unknown> =
+ (
+ args: Parameters<T>,
+ ) => ReturnType<T>;
+
+ export function uncurryThis<
+ T extends (...args: unknown[]) => unknown,
+ >(fn: T): (self: ThisType<T>, ...args: Parameters<T>) => ReturnType<T>;
+ export function makeSafe<T extends NewableFunction>(
+ unsafe: NewableFunction,
+ safe: T,
+ ): T;
+
+ export const decodeURI: typeof globalThis.decodeURI;
+ export const decodeURIComponent: typeof globalThis.decodeURIComponent;
+ export const encodeURI: typeof globalThis.encodeURI;
+ export const encodeURIComponent: typeof globalThis.encodeURIComponent;
+ export const JSONParse: typeof JSON.parse;
+ export const JSONStringify: typeof JSON.stringify;
+ export const MathAbs: typeof Math.abs;
+ export const MathAcos: typeof Math.acos;
+ export const MathAcosh: typeof Math.acosh;
+ export const MathAsin: typeof Math.asin;
+ export const MathAsinh: typeof Math.asinh;
+ export const MathAtan: typeof Math.atan;
+ export const MathAtanh: typeof Math.atanh;
+ export const MathAtan2: typeof Math.atan2;
+ export const MathCeil: typeof Math.ceil;
+ export const MathCbrt: typeof Math.cbrt;
+ export const MathExpm1: typeof Math.expm1;
+ export const MathClz32: typeof Math.clz32;
+ export const MathCos: typeof Math.cos;
+ export const MathCosh: typeof Math.cosh;
+ export const MathExp: typeof Math.exp;
+ export const MathFloor: typeof Math.floor;
+ export const MathFround: typeof Math.fround;
+ export const MathHypot: typeof Math.hypot;
+ export const MathImul: typeof Math.imul;
+ export const MathLog: typeof Math.log;
+ export const MathLog1p: typeof Math.log1p;
+ export const MathLog2: typeof Math.log2;
+ export const MathLog10: typeof Math.log10;
+ export const MathMax: typeof Math.max;
+ export const MathMaxApply: StaticApply<typeof Math.max>;
+ export const MathMin: typeof Math.min;
+ export const MathPow: typeof Math.pow;
+ export const MathRandom: typeof Math.random;
+ export const MathRound: typeof Math.round;
+ export const MathSign: typeof Math.sign;
+ export const MathSin: typeof Math.sin;
+ export const MathSinh: typeof Math.sinh;
+ export const MathSqrt: typeof Math.sqrt;
+ export const MathTan: typeof Math.tan;
+ export const MathTanh: typeof Math.tanh;
+ export const MathTrunc: typeof Math.trunc;
+ export const MathE: typeof Math.E;
+ export const MathLN10: typeof Math.LN10;
+ export const MathLN2: typeof Math.LN2;
+ export const MathLOG10E: typeof Math.LOG10E;
+ export const MathLOG2E: typeof Math.LOG2E;
+ export const MathPI: typeof Math.PI;
+ export const MathSQRT1_2: typeof Math.SQRT1_2;
+ export const MathSQRT2: typeof Math.SQRT2;
+ export const ReflectDefineProperty: typeof Reflect.defineProperty;
+ export const ReflectDeleteProperty: typeof Reflect.deleteProperty;
+ export const ReflectApply: typeof Reflect.apply;
+ export const ReflectConstruct: typeof Reflect.construct;
+ export const ReflectGet: typeof Reflect.get;
+ export const ReflectGetOwnPropertyDescriptor:
+ typeof Reflect.getOwnPropertyDescriptor;
+ export const ReflectGetPrototypeOf: typeof Reflect.getPrototypeOf;
+ export const ReflectHas: typeof Reflect.has;
+ export const ReflectIsExtensible: typeof Reflect.isExtensible;
+ export const ReflectOwnKeys: typeof Reflect.ownKeys;
+ export const ReflectPreventExtensions: typeof Reflect.preventExtensions;
+ export const ReflectSet: typeof Reflect.set;
+ export const ReflectSetPrototypeOf: typeof Reflect.setPrototypeOf;
+ export const AggregateError: typeof globalThis.AggregateError;
+ export const AggregateErrorLength: typeof AggregateError.length;
+ export const AggregateErrorName: typeof AggregateError.name;
+ export const AggregateErrorPrototype: typeof AggregateError.prototype;
+ export const Array: typeof globalThis.Array;
+ export const ArrayLength: typeof Array.length;
+ export const ArrayName: typeof Array.name;
+ export const ArrayPrototype: typeof Array.prototype;
+ export const ArrayIsArray: typeof Array.isArray;
+ export const ArrayFrom: typeof Array.from;
+ export const ArrayOf: typeof Array.of;
+ export const ArrayPrototypeConcat: UncurryThis<
+ typeof Array.prototype.concat
+ >;
+ export const ArrayPrototypeCopyWithin: UncurryThis<
+ typeof Array.prototype.copyWithin
+ >;
+ export const ArrayPrototypeFill: UncurryThis<typeof Array.prototype.fill>;
+ export const ArrayPrototypeFind: UncurryThis<typeof Array.prototype.find>;
+ export const ArrayPrototypeFindIndex: UncurryThis<
+ typeof Array.prototype.findIndex
+ >;
+ export const ArrayPrototypeLastIndexOf: UncurryThis<
+ typeof Array.prototype.lastIndexOf
+ >;
+ export const ArrayPrototypePop: UncurryThis<typeof Array.prototype.pop>;
+ export const ArrayPrototypePush: UncurryThis<typeof Array.prototype.push>;
+ export const ArrayPrototypePushApply: UncurryThisStaticApply<
+ typeof Array.prototype.push
+ >;
+ export const ArrayPrototypeReverse: UncurryThis<
+ typeof Array.prototype.reverse
+ >;
+ export const ArrayPrototypeShift: UncurryThis<typeof Array.prototype.shift>;
+ export const ArrayPrototypeUnshift: UncurryThis<
+ typeof Array.prototype.unshift
+ >;
+ export const ArrayPrototypeUnshiftApply: UncurryThisStaticApply<
+ typeof Array.prototype.unshift
+ >;
+ export const ArrayPrototypeSlice: UncurryThis<typeof Array.prototype.slice>;
+ export const ArrayPrototypeSort: UncurryThis<typeof Array.prototype.sort>;
+ export const ArrayPrototypeSplice: UncurryThis<
+ typeof Array.prototype.splice
+ >;
+ export const ArrayPrototypeIncludes: UncurryThis<
+ typeof Array.prototype.includes
+ >;
+ export const ArrayPrototypeIndexOf: UncurryThis<
+ typeof Array.prototype.indexOf
+ >;
+ export const ArrayPrototypeJoin: UncurryThis<typeof Array.prototype.join>;
+ export const ArrayPrototypeKeys: UncurryThis<typeof Array.prototype.keys>;
+ export const ArrayPrototypeEntries: UncurryThis<
+ typeof Array.prototype.entries
+ >;
+ export const ArrayPrototypeValues: UncurryThis<
+ typeof Array.prototype.values
+ >;
+ export const ArrayPrototypeForEach: UncurryThis<
+ typeof Array.prototype.forEach
+ >;
+ export const ArrayPrototypeFilter: UncurryThis<
+ typeof Array.prototype.filter
+ >;
+ export const ArrayPrototypeFlat: UncurryThis<typeof Array.prototype.flat>;
+ export const ArrayPrototypeFlatMap: UncurryThis<
+ typeof Array.prototype.flatMap
+ >;
+ export const ArrayPrototypeMap: UncurryThis<typeof Array.prototype.map>;
+ export const ArrayPrototypeEvery: UncurryThis<typeof Array.prototype.every>;
+ export const ArrayPrototypeSome: UncurryThis<typeof Array.prototype.some>;
+ export const ArrayPrototypeReduce: UncurryThis<
+ typeof Array.prototype.reduce
+ >;
+ export const ArrayPrototypeReduceRight: UncurryThis<
+ typeof Array.prototype.reduceRight
+ >;
+ export const ArrayPrototypeToLocaleString: UncurryThis<
+ typeof Array.prototype.toLocaleString
+ >;
+ export const ArrayPrototypeToString: UncurryThis<
+ typeof Array.prototype.toString
+ >;
+ export const ArrayBuffer: typeof globalThis.ArrayBuffer;
+ export const ArrayBufferLength: typeof ArrayBuffer.length;
+ export const ArrayBufferName: typeof ArrayBuffer.name;
+ export const ArrayBufferPrototype: typeof ArrayBuffer.prototype;
+ export const ArrayBufferIsView: typeof ArrayBuffer.isView;
+ export const ArrayBufferPrototypeSlice: UncurryThis<
+ typeof ArrayBuffer.prototype.slice
+ >;
+ export const BigInt: typeof globalThis.BigInt;
+ export const BigIntLength: typeof BigInt.length;
+ export const BigIntName: typeof BigInt.name;
+ export const BigIntPrototype: typeof BigInt.prototype;
+ export const BigIntAsUintN: typeof BigInt.asUintN;
+ export const BigIntAsIntN: typeof BigInt.asIntN;
+ export const BigIntPrototypeToLocaleString: UncurryThis<
+ typeof BigInt.prototype.toLocaleString
+ >;
+ export const BigIntPrototypeToString: UncurryThis<
+ typeof BigInt.prototype.toString
+ >;
+ export const BigIntPrototypeValueOf: UncurryThis<
+ typeof BigInt.prototype.valueOf
+ >;
+ export const BigInt64Array: typeof globalThis.BigInt64Array;
+ export const BigInt64ArrayLength: typeof BigInt64Array.length;
+ export const BigInt64ArrayName: typeof BigInt64Array.name;
+ export const BigInt64ArrayPrototype: typeof BigInt64Array.prototype;
+ export const BigInt64ArrayBYTES_PER_ELEMENT:
+ typeof BigInt64Array.BYTES_PER_ELEMENT;
+ export const BigUint64Array: typeof globalThis.BigUint64Array;
+ export const BigUint64ArrayLength: typeof BigUint64Array.length;
+ export const BigUint64ArrayName: typeof BigUint64Array.name;
+ export const BigUint64ArrayPrototype: typeof BigUint64Array.prototype;
+ export const BigUint64ArrayBYTES_PER_ELEMENT:
+ typeof BigUint64Array.BYTES_PER_ELEMENT;
+ export const Boolean: typeof globalThis.Boolean;
+ export const BooleanLength: typeof Boolean.length;
+ export const BooleanName: typeof Boolean.name;
+ export const BooleanPrototype: typeof Boolean.prototype;
+ export const BooleanPrototypeToString: UncurryThis<
+ typeof Boolean.prototype.toString
+ >;
+ export const BooleanPrototypeValueOf: UncurryThis<
+ typeof Boolean.prototype.valueOf
+ >;
+ export const DataView: typeof globalThis.DataView;
+ export const DataViewLength: typeof DataView.length;
+ export const DataViewName: typeof DataView.name;
+ export const DataViewPrototype: typeof DataView.prototype;
+ export const DataViewPrototypeGetInt8: UncurryThis<
+ typeof DataView.prototype.getInt8
+ >;
+ export const DataViewPrototypeSetInt8: UncurryThis<
+ typeof DataView.prototype.setInt8
+ >;
+ export const DataViewPrototypeGetUint8: UncurryThis<
+ typeof DataView.prototype.getUint8
+ >;
+ export const DataViewPrototypeSetUint8: UncurryThis<
+ typeof DataView.prototype.setUint8
+ >;
+ export const DataViewPrototypeGetInt16: UncurryThis<
+ typeof DataView.prototype.getInt16
+ >;
+ export const DataViewPrototypeSetInt16: UncurryThis<
+ typeof DataView.prototype.setInt16
+ >;
+ export const DataViewPrototypeGetUint16: UncurryThis<
+ typeof DataView.prototype.getUint16
+ >;
+ export const DataViewPrototypeSetUint16: UncurryThis<
+ typeof DataView.prototype.setUint16
+ >;
+ export const DataViewPrototypeGetInt32: UncurryThis<
+ typeof DataView.prototype.getInt32
+ >;
+ export const DataViewPrototypeSetInt32: UncurryThis<
+ typeof DataView.prototype.setInt32
+ >;
+ export const DataViewPrototypeGetUint32: UncurryThis<
+ typeof DataView.prototype.getUint32
+ >;
+ export const DataViewPrototypeSetUint32: UncurryThis<
+ typeof DataView.prototype.setUint32
+ >;
+ export const DataViewPrototypeGetFloat32: UncurryThis<
+ typeof DataView.prototype.getFloat32
+ >;
+ export const DataViewPrototypeSetFloat32: UncurryThis<
+ typeof DataView.prototype.setFloat32
+ >;
+ export const DataViewPrototypeGetFloat64: UncurryThis<
+ typeof DataView.prototype.getFloat64
+ >;
+ export const DataViewPrototypeSetFloat64: UncurryThis<
+ typeof DataView.prototype.setFloat64
+ >;
+ export const DataViewPrototypeGetBigInt64: UncurryThis<
+ typeof DataView.prototype.getBigInt64
+ >;
+ export const DataViewPrototypeSetBigInt64: UncurryThis<
+ typeof DataView.prototype.setBigInt64
+ >;
+ export const DataViewPrototypeGetBigUint64: UncurryThis<
+ typeof DataView.prototype.getBigUint64
+ >;
+ export const DataViewPrototypeSetBigUint64: UncurryThis<
+ typeof DataView.prototype.setBigUint64
+ >;
+ export const Date: typeof globalThis.Date;
+ export const DateLength: typeof Date.length;
+ export const DateName: typeof Date.name;
+ export const DatePrototype: typeof Date.prototype;
+ export const DateNow: typeof Date.now;
+ export const DateParse: typeof Date.parse;
+ export const DateUTC: typeof Date.UTC;
+ export const DatePrototypeToString: UncurryThis<
+ typeof Date.prototype.toString
+ >;
+ export const DatePrototypeToDateString: UncurryThis<
+ typeof Date.prototype.toDateString
+ >;
+ export const DatePrototypeToTimeString: UncurryThis<
+ typeof Date.prototype.toTimeString
+ >;
+ export const DatePrototypeToISOString: UncurryThis<
+ typeof Date.prototype.toISOString
+ >;
+ export const DatePrototypeToUTCString: UncurryThis<
+ typeof Date.prototype.toUTCString
+ >;
+ export const DatePrototypeToGMTString: UncurryThis<
+ typeof Date.prototype.toGMTString
+ >;
+ export const DatePrototypeGetDate: UncurryThis<
+ typeof Date.prototype.getDate
+ >;
+ export const DatePrototypeSetDate: UncurryThis<
+ typeof Date.prototype.setDate
+ >;
+ export const DatePrototypeGetDay: UncurryThis<typeof Date.prototype.getDay>;
+ export const DatePrototypeGetFullYear: UncurryThis<
+ typeof Date.prototype.getFullYear
+ >;
+ export const DatePrototypeSetFullYear: UncurryThis<
+ typeof Date.prototype.setFullYear
+ >;
+ export const DatePrototypeGetHours: UncurryThis<
+ typeof Date.prototype.getHours
+ >;
+ export const DatePrototypeSetHours: UncurryThis<
+ typeof Date.prototype.setHours
+ >;
+ export const DatePrototypeGetMilliseconds: UncurryThis<
+ typeof Date.prototype.getMilliseconds
+ >;
+ export const DatePrototypeSetMilliseconds: UncurryThis<
+ typeof Date.prototype.setMilliseconds
+ >;
+ export const DatePrototypeGetMinutes: UncurryThis<
+ typeof Date.prototype.getMinutes
+ >;
+ export const DatePrototypeSetMinutes: UncurryThis<
+ typeof Date.prototype.setMinutes
+ >;
+ export const DatePrototypeGetMonth: UncurryThis<
+ typeof Date.prototype.getMonth
+ >;
+ export const DatePrototypeSetMonth: UncurryThis<
+ typeof Date.prototype.setMonth
+ >;
+ export const DatePrototypeGetSeconds: UncurryThis<
+ typeof Date.prototype.getSeconds
+ >;
+ export const DatePrototypeSetSeconds: UncurryThis<
+ typeof Date.prototype.setSeconds
+ >;
+ export const DatePrototypeGetTime: UncurryThis<
+ typeof Date.prototype.getTime
+ >;
+ export const DatePrototypeSetTime: UncurryThis<
+ typeof Date.prototype.setTime
+ >;
+ export const DatePrototypeGetTimezoneOffset: UncurryThis<
+ typeof Date.prototype.getTimezoneOffset
+ >;
+ export const DatePrototypeGetUTCDate: UncurryThis<
+ typeof Date.prototype.getUTCDate
+ >;
+ export const DatePrototypeSetUTCDate: UncurryThis<
+ typeof Date.prototype.setUTCDate
+ >;
+ export const DatePrototypeGetUTCDay: UncurryThis<
+ typeof Date.prototype.getUTCDay
+ >;
+ export const DatePrototypeGetUTCFullYear: UncurryThis<
+ typeof Date.prototype.getUTCFullYear
+ >;
+ export const DatePrototypeSetUTCFullYear: UncurryThis<
+ typeof Date.prototype.setUTCFullYear
+ >;
+ export const DatePrototypeGetUTCHours: UncurryThis<
+ typeof Date.prototype.getUTCHours
+ >;
+ export const DatePrototypeSetUTCHours: UncurryThis<
+ typeof Date.prototype.setUTCHours
+ >;
+ export const DatePrototypeGetUTCMilliseconds: UncurryThis<
+ typeof Date.prototype.getUTCMilliseconds
+ >;
+ export const DatePrototypeSetUTCMilliseconds: UncurryThis<
+ typeof Date.prototype.setUTCMilliseconds
+ >;
+ export const DatePrototypeGetUTCMinutes: UncurryThis<
+ typeof Date.prototype.getUTCMinutes
+ >;
+ export const DatePrototypeSetUTCMinutes: UncurryThis<
+ typeof Date.prototype.setUTCMinutes
+ >;
+ export const DatePrototypeGetUTCMonth: UncurryThis<
+ typeof Date.prototype.getUTCMonth
+ >;
+ export const DatePrototypeSetUTCMonth: UncurryThis<
+ typeof Date.prototype.setUTCMonth
+ >;
+ export const DatePrototypeGetUTCSeconds: UncurryThis<
+ typeof Date.prototype.getUTCSeconds
+ >;
+ export const DatePrototypeSetUTCSeconds: UncurryThis<
+ typeof Date.prototype.setUTCSeconds
+ >;
+ export const DatePrototypeValueOf: UncurryThis<
+ typeof Date.prototype.valueOf
+ >;
+ export const DatePrototypeGetYear: UncurryThis<
+ typeof Date.prototype.getYear
+ >;
+ export const DatePrototypeSetYear: UncurryThis<
+ typeof Date.prototype.setYear
+ >;
+ export const DatePrototypeToJSON: UncurryThis<typeof Date.prototype.toJSON>;
+ export const DatePrototypeToLocaleString: UncurryThis<
+ typeof Date.prototype.toLocaleString
+ >;
+ export const DatePrototypeToLocaleDateString: UncurryThis<
+ typeof Date.prototype.toLocaleDateString
+ >;
+ export const DatePrototypeToLocaleTimeString: UncurryThis<
+ typeof Date.prototype.toLocaleTimeString
+ >;
+ export const Error: typeof globalThis.Error;
+ export const ErrorLength: typeof Error.length;
+ export const ErrorName: typeof Error.name;
+ export const ErrorPrototype: typeof Error.prototype;
+ export const ErrorCaptureStackTrace: typeof Error.captureStackTrace;
+ export const ErrorStackTraceLimit: typeof Error.stackTraceLimit;
+ export const ErrorPrototypeToString: UncurryThis<
+ typeof Error.prototype.toString
+ >;
+ export const EvalError: typeof globalThis.EvalError;
+ export const EvalErrorLength: typeof EvalError.length;
+ export const EvalErrorName: typeof EvalError.name;
+ export const EvalErrorPrototype: typeof EvalError.prototype;
+ export const Float32Array: typeof globalThis.Float32Array;
+ export const Float32ArrayLength: typeof Float32Array.length;
+ export const Float32ArrayName: typeof Float32Array.name;
+ export const Float32ArrayPrototype: typeof Float32Array.prototype;
+ export const Float32ArrayBYTES_PER_ELEMENT:
+ typeof Float32Array.BYTES_PER_ELEMENT;
+ export const Float64Array: typeof globalThis.Float64Array;
+ export const Float64ArrayLength: typeof Float64Array.length;
+ export const Float64ArrayName: typeof Float64Array.name;
+ export const Float64ArrayPrototype: typeof Float64Array.prototype;
+ export const Float64ArrayBYTES_PER_ELEMENT:
+ typeof Float64Array.BYTES_PER_ELEMENT;
+ export const Function: typeof globalThis.Function;
+ export const FunctionLength: typeof Function.length;
+ export const FunctionName: typeof Function.name;
+ export const FunctionPrototype: typeof Function.prototype;
+ export const FunctionPrototypeApply: UncurryThis<
+ typeof Function.prototype.apply
+ >;
+ export const FunctionPrototypeBind: UncurryThis<
+ typeof Function.prototype.bind
+ >;
+ export const FunctionPrototypeCall: UncurryThis<
+ typeof Function.prototype.call
+ >;
+ export const FunctionPrototypeToString: UncurryThis<
+ typeof Function.prototype.toString
+ >;
+ export const Int16Array: typeof globalThis.Int16Array;
+ export const Int16ArrayLength: typeof Int16Array.length;
+ export const Int16ArrayName: typeof Int16Array.name;
+ export const Int16ArrayPrototype: typeof Int16Array.prototype;
+ export const Int16ArrayBYTES_PER_ELEMENT:
+ typeof Int16Array.BYTES_PER_ELEMENT;
+ export const Int32Array: typeof globalThis.Int32Array;
+ export const Int32ArrayLength: typeof Int32Array.length;
+ export const Int32ArrayName: typeof Int32Array.name;
+ export const Int32ArrayPrototype: typeof Int32Array.prototype;
+ export const Int32ArrayBYTES_PER_ELEMENT:
+ typeof Int32Array.BYTES_PER_ELEMENT;
+ export const Int8Array: typeof globalThis.Int8Array;
+ export const Int8ArrayLength: typeof Int8Array.length;
+ export const Int8ArrayName: typeof Int8Array.name;
+ export const Int8ArrayPrototype: typeof Int8Array.prototype;
+ export const Int8ArrayBYTES_PER_ELEMENT: typeof Int8Array.BYTES_PER_ELEMENT;
+ export const Map: typeof globalThis.Map;
+ export const MapLength: typeof Map.length;
+ export const MapName: typeof Map.name;
+ export const MapPrototype: typeof Map.prototype;
+ export const MapPrototypeGet: UncurryThis<typeof Map.prototype.get>;
+ export const MapPrototypeSet: UncurryThis<typeof Map.prototype.set>;
+ export const MapPrototypeHas: UncurryThis<typeof Map.prototype.has>;
+ export const MapPrototypeDelete: UncurryThis<typeof Map.prototype.delete>;
+ export const MapPrototypeClear: UncurryThis<typeof Map.prototype.clear>;
+ export const MapPrototypeEntries: UncurryThis<typeof Map.prototype.entries>;
+ export const MapPrototypeForEach: UncurryThis<typeof Map.prototype.forEach>;
+ export const MapPrototypeKeys: UncurryThis<typeof Map.prototype.keys>;
+ export const MapPrototypeValues: UncurryThis<typeof Map.prototype.values>;
+ export const Number: typeof globalThis.Number;
+ export const NumberLength: typeof Number.length;
+ export const NumberName: typeof Number.name;
+ export const NumberPrototype: typeof Number.prototype;
+ export const NumberIsFinite: typeof Number.isFinite;
+ export const NumberIsInteger: typeof Number.isInteger;
+ export const NumberIsNaN: typeof Number.isNaN;
+ export const NumberIsSafeInteger: typeof Number.isSafeInteger;
+ export const NumberParseFloat: typeof Number.parseFloat;
+ export const NumberParseInt: typeof Number.parseInt;
+ export const NumberMAX_VALUE: typeof Number.MAX_VALUE;
+ export const NumberMIN_VALUE: typeof Number.MIN_VALUE;
+ export const NumberNaN: typeof Number.NaN;
+ export const NumberNEGATIVE_INFINITY: typeof Number.NEGATIVE_INFINITY;
+ export const NumberPOSITIVE_INFINITY: typeof Number.POSITIVE_INFINITY;
+ export const NumberMAX_SAFE_INTEGER: typeof Number.MAX_SAFE_INTEGER;
+ export const NumberMIN_SAFE_INTEGER: typeof Number.MIN_SAFE_INTEGER;
+ export const NumberEPSILON: typeof Number.EPSILON;
+ export const NumberPrototypeToExponential: UncurryThis<
+ typeof Number.prototype.toExponential
+ >;
+ export const NumberPrototypeToFixed: UncurryThis<
+ typeof Number.prototype.toFixed
+ >;
+ export const NumberPrototypeToPrecision: UncurryThis<
+ typeof Number.prototype.toPrecision
+ >;
+ export const NumberPrototypeToString: UncurryThis<
+ typeof Number.prototype.toString
+ >;
+ export const NumberPrototypeValueOf: UncurryThis<
+ typeof Number.prototype.valueOf
+ >;
+ export const NumberPrototypeToLocaleString: UncurryThis<
+ typeof Number.prototype.toLocaleString
+ >;
+ export const Object: typeof globalThis.Object;
+ export const ObjectLength: typeof Object.length;
+ export const ObjectName: typeof Object.name;
+ export const ObjectPrototype: typeof Object.prototype;
+ export const ObjectAssign: typeof Object.assign;
+ export const ObjectGetOwnPropertyDescriptor:
+ typeof Object.getOwnPropertyDescriptor;
+ export const ObjectGetOwnPropertyDescriptors:
+ typeof Object.getOwnPropertyDescriptors;
+ export const ObjectGetOwnPropertyNames: typeof Object.getOwnPropertyNames;
+ export const ObjectGetOwnPropertySymbols:
+ typeof Object.getOwnPropertySymbols;
+ export const ObjectIs: typeof Object.is;
+ export const ObjectPreventExtensions: typeof Object.preventExtensions;
+ export const ObjectSeal: typeof Object.seal;
+ export const ObjectCreate: typeof Object.create;
+ export const ObjectDefineProperties: typeof Object.defineProperties;
+ export const ObjectDefineProperty: typeof Object.defineProperty;
+ export const ObjectFreeze: typeof Object.freeze;
+ export const ObjectGetPrototypeOf: typeof Object.getPrototypeOf;
+ export const ObjectSetPrototypeOf: typeof Object.setPrototypeOf;
+ export const ObjectIsExtensible: typeof Object.isExtensible;
+ export const ObjectIsFrozen: typeof Object.isFrozen;
+ export const ObjectIsSealed: typeof Object.isSealed;
+ export const ObjectKeys: typeof Object.keys;
+ export const ObjectEntries: typeof Object.entries;
+ export const ObjectFromEntries: typeof Object.fromEntries;
+ export const ObjectValues: typeof Object.values;
+ export const ObjectPrototype__defineGetter__: UncurryThis<
+ typeof Object.prototype.__defineGetter__
+ >;
+ export const ObjectPrototype__defineSetter__: UncurryThis<
+ typeof Object.prototype.__defineSetter__
+ >;
+ export const ObjectPrototypeHasOwnProperty: UncurryThis<
+ typeof Object.prototype.hasOwnProperty
+ >;
+ export const ObjectPrototype__lookupGetter__: UncurryThis<
+ typeof Object.prototype.__lookupGetter__
+ >;
+ export const ObjectPrototype__lookupSetter__: UncurryThis<
+ typeof Object.prototype.__lookupSetter__
+ >;
+ export const ObjectPrototypeIsPrototypeOf: UncurryThis<
+ typeof Object.prototype.isPrototypeOf
+ >;
+ export const ObjectPrototypePropertyIsEnumerable: UncurryThis<
+ typeof Object.prototype.propertyIsEnumerable
+ >;
+ export const ObjectPrototypeToString: UncurryThis<
+ typeof Object.prototype.toString
+ >;
+ export const ObjectPrototypeValueOf: UncurryThis<
+ typeof Object.prototype.valueOf
+ >;
+ export const ObjectPrototypeToLocaleString: UncurryThis<
+ typeof Object.prototype.toLocaleString
+ >;
+ export const RangeError: typeof globalThis.RangeError;
+ export const RangeErrorLength: typeof RangeError.length;
+ export const RangeErrorName: typeof RangeError.name;
+ export const RangeErrorPrototype: typeof RangeError.prototype;
+ export const ReferenceError: typeof globalThis.ReferenceError;
+ export const ReferenceErrorLength: typeof ReferenceError.length;
+ export const ReferenceErrorName: typeof ReferenceError.name;
+ export const ReferenceErrorPrototype: typeof ReferenceError.prototype;
+ export const RegExp: typeof globalThis.RegExp;
+ export const RegExpLength: typeof RegExp.length;
+ export const RegExpName: typeof RegExp.name;
+ export const RegExpPrototype: typeof RegExp.prototype;
+ export const RegExpPrototypeExec: UncurryThis<typeof RegExp.prototype.exec>;
+ export const RegExpPrototypeCompile: UncurryThis<
+ typeof RegExp.prototype.compile
+ >;
+ export const RegExpPrototypeToString: UncurryThis<
+ typeof RegExp.prototype.toString
+ >;
+ export const RegExpPrototypeTest: UncurryThis<typeof RegExp.prototype.test>;
+ export const Set: typeof globalThis.Set;
+ export const SetLength: typeof Set.length;
+ export const SetName: typeof Set.name;
+ export const SetPrototype: typeof Set.prototype;
+ export const SetPrototypeHas: UncurryThis<typeof Set.prototype.has>;
+ export const SetPrototypeAdd: UncurryThis<typeof Set.prototype.add>;
+ export const SetPrototypeDelete: UncurryThis<typeof Set.prototype.delete>;
+ export const SetPrototypeClear: UncurryThis<typeof Set.prototype.clear>;
+ export const SetPrototypeEntries: UncurryThis<typeof Set.prototype.entries>;
+ export const SetPrototypeForEach: UncurryThis<typeof Set.prototype.forEach>;
+ export const SetPrototypeValues: UncurryThis<typeof Set.prototype.values>;
+ export const SetPrototypeKeys: UncurryThis<typeof Set.prototype.keys>;
+ export const String: typeof globalThis.String;
+ export const StringLength: typeof String.length;
+ export const StringName: typeof String.name;
+ export const StringPrototype: typeof String.prototype;
+ export const StringFromCharCode: typeof String.fromCharCode;
+ export const StringFromCodePoint: typeof String.fromCodePoint;
+ export const StringRaw: typeof String.raw;
+ export const StringPrototypeAnchor: UncurryThis<
+ typeof String.prototype.anchor
+ >;
+ export const StringPrototypeBig: UncurryThis<typeof String.prototype.big>;
+ export const StringPrototypeBlink: UncurryThis<
+ typeof String.prototype.blink
+ >;
+ export const StringPrototypeBold: UncurryThis<typeof String.prototype.bold>;
+ export const StringPrototypeCharAt: UncurryThis<
+ typeof String.prototype.charAt
+ >;
+ export const StringPrototypeCharCodeAt: UncurryThis<
+ typeof String.prototype.charCodeAt
+ >;
+ export const StringPrototypeCodePointAt: UncurryThis<
+ typeof String.prototype.codePointAt
+ >;
+ export const StringPrototypeConcat: UncurryThis<
+ typeof String.prototype.concat
+ >;
+ export const StringPrototypeEndsWith: UncurryThis<
+ typeof String.prototype.endsWith
+ >;
+ export const StringPrototypeFontcolor: UncurryThis<
+ typeof String.prototype.fontcolor
+ >;
+ export const StringPrototypeFontsize: UncurryThis<
+ typeof String.prototype.fontsize
+ >;
+ export const StringPrototypeFixed: UncurryThis<
+ typeof String.prototype.fixed
+ >;
+ export const StringPrototypeIncludes: UncurryThis<
+ typeof String.prototype.includes
+ >;
+ export const StringPrototypeIndexOf: UncurryThis<
+ typeof String.prototype.indexOf
+ >;
+ export const StringPrototypeItalics: UncurryThis<
+ typeof String.prototype.italics
+ >;
+ export const StringPrototypeLastIndexOf: UncurryThis<
+ typeof String.prototype.lastIndexOf
+ >;
+ export const StringPrototypeLink: UncurryThis<typeof String.prototype.link>;
+ export const StringPrototypeLocaleCompare: UncurryThis<
+ typeof String.prototype.localeCompare
+ >;
+ export const StringPrototypeMatch: UncurryThis<
+ typeof String.prototype.match
+ >;
+ export const StringPrototypeMatchAll: UncurryThis<
+ typeof String.prototype.matchAll
+ >;
+ export const StringPrototypeNormalize: UncurryThis<
+ typeof String.prototype.normalize
+ >;
+ export const StringPrototypePadEnd: UncurryThis<
+ typeof String.prototype.padEnd
+ >;
+ export const StringPrototypePadStart: UncurryThis<
+ typeof String.prototype.padStart
+ >;
+ export const StringPrototypeRepeat: UncurryThis<
+ typeof String.prototype.repeat
+ >;
+ export const StringPrototypeReplace: UncurryThis<
+ typeof String.prototype.replace
+ >;
+ export const StringPrototypeSearch: UncurryThis<
+ typeof String.prototype.search
+ >;
+ export const StringPrototypeSlice: UncurryThis<
+ typeof String.prototype.slice
+ >;
+ export const StringPrototypeSmall: UncurryThis<
+ typeof String.prototype.small
+ >;
+ export const StringPrototypeSplit: UncurryThis<
+ typeof String.prototype.split
+ >;
+ export const StringPrototypeStrike: UncurryThis<
+ typeof String.prototype.strike
+ >;
+ export const StringPrototypeSub: UncurryThis<typeof String.prototype.sub>;
+ export const StringPrototypeSubstr: UncurryThis<
+ typeof String.prototype.substr
+ >;
+ export const StringPrototypeSubstring: UncurryThis<
+ typeof String.prototype.substring
+ >;
+ export const StringPrototypeSup: UncurryThis<typeof String.prototype.sup>;
+ export const StringPrototypeStartsWith: UncurryThis<
+ typeof String.prototype.startsWith
+ >;
+ export const StringPrototypeToString: UncurryThis<
+ typeof String.prototype.toString
+ >;
+ export const StringPrototypeTrim: UncurryThis<typeof String.prototype.trim>;
+ export const StringPrototypeTrimStart: UncurryThis<
+ typeof String.prototype.trimStart
+ >;
+ export const StringPrototypeTrimLeft: UncurryThis<
+ typeof String.prototype.trimLeft
+ >;
+ export const StringPrototypeTrimEnd: UncurryThis<
+ typeof String.prototype.trimEnd
+ >;
+ export const StringPrototypeTrimRight: UncurryThis<
+ typeof String.prototype.trimRight
+ >;
+ export const StringPrototypeToLocaleLowerCase: UncurryThis<
+ typeof String.prototype.toLocaleLowerCase
+ >;
+ export const StringPrototypeToLocaleUpperCase: UncurryThis<
+ typeof String.prototype.toLocaleUpperCase
+ >;
+ export const StringPrototypeToLowerCase: UncurryThis<
+ typeof String.prototype.toLowerCase
+ >;
+ export const StringPrototypeToUpperCase: UncurryThis<
+ typeof String.prototype.toUpperCase
+ >;
+ export const StringPrototypeValueOf: UncurryThis<
+ typeof String.prototype.valueOf
+ >;
+ export const StringPrototypeReplaceAll: UncurryThis<
+ typeof String.prototype.replaceAll
+ >;
+ export const Symbol: typeof globalThis.Symbol;
+ export const SymbolLength: typeof Symbol.length;
+ export const SymbolName: typeof Symbol.name;
+ export const SymbolPrototype: typeof Symbol.prototype;
+ export const SymbolFor: typeof Symbol.for;
+ export const SymbolKeyFor: typeof Symbol.keyFor;
+ export const SymbolAsyncIterator: typeof Symbol.asyncIterator;
+ export const SymbolHasInstance: typeof Symbol.hasInstance;
+ export const SymbolIsConcatSpreadable: typeof Symbol.isConcatSpreadable;
+ export const SymbolIterator: typeof Symbol.iterator;
+ export const SymbolMatch: typeof Symbol.match;
+ export const SymbolMatchAll: typeof Symbol.matchAll;
+ export const SymbolReplace: typeof Symbol.replace;
+ export const SymbolSearch: typeof Symbol.search;
+ export const SymbolSpecies: typeof Symbol.species;
+ export const SymbolSplit: typeof Symbol.split;
+ export const SymbolToPrimitive: typeof Symbol.toPrimitive;
+ export const SymbolToStringTag: typeof Symbol.toStringTag;
+ export const SymbolUnscopables: typeof Symbol.unscopables;
+ export const SymbolPrototypeToString: UncurryThis<
+ typeof Symbol.prototype.toString
+ >;
+ export const SymbolPrototypeValueOf: UncurryThis<
+ typeof Symbol.prototype.valueOf
+ >;
+ export const SyntaxError: typeof globalThis.SyntaxError;
+ export const SyntaxErrorLength: typeof SyntaxError.length;
+ export const SyntaxErrorName: typeof SyntaxError.name;
+ export const SyntaxErrorPrototype: typeof SyntaxError.prototype;
+ export const TypeError: typeof globalThis.TypeError;
+ export const TypeErrorLength: typeof TypeError.length;
+ export const TypeErrorName: typeof TypeError.name;
+ export const TypeErrorPrototype: typeof TypeError.prototype;
+ export const URIError: typeof globalThis.URIError;
+ export const URIErrorLength: typeof URIError.length;
+ export const URIErrorName: typeof URIError.name;
+ export const URIErrorPrototype: typeof URIError.prototype;
+ export const Uint16Array: typeof globalThis.Uint16Array;
+ export const Uint16ArrayLength: typeof Uint16Array.length;
+ export const Uint16ArrayName: typeof Uint16Array.name;
+ export const Uint16ArrayPrototype: typeof Uint16Array.prototype;
+ export const Uint16ArrayBYTES_PER_ELEMENT:
+ typeof Uint16Array.BYTES_PER_ELEMENT;
+ export const Uint32Array: typeof globalThis.Uint32Array;
+ export const Uint32ArrayLength: typeof Uint32Array.length;
+ export const Uint32ArrayName: typeof Uint32Array.name;
+ export const Uint32ArrayPrototype: typeof Uint32Array.prototype;
+ export const Uint32ArrayBYTES_PER_ELEMENT:
+ typeof Uint32Array.BYTES_PER_ELEMENT;
+ export const Uint8Array: typeof globalThis.Uint8Array;
+ export const Uint8ArrayLength: typeof Uint8Array.length;
+ export const Uint8ArrayName: typeof Uint8Array.name;
+ export const Uint8ArrayPrototype: typeof Uint8Array.prototype;
+ export const Uint8ArrayBYTES_PER_ELEMENT:
+ typeof Uint8Array.BYTES_PER_ELEMENT;
+ export const Uint8ClampedArray: typeof globalThis.Uint8ClampedArray;
+ export const Uint8ClampedArrayLength: typeof Uint8ClampedArray.length;
+ export const Uint8ClampedArrayName: typeof Uint8ClampedArray.name;
+ export const Uint8ClampedArrayPrototype: typeof Uint8ClampedArray.prototype;
+ export const Uint8ClampedArrayBYTES_PER_ELEMENT:
+ typeof Uint8ClampedArray.BYTES_PER_ELEMENT;
+ export const WeakMap: typeof globalThis.WeakMap;
+ export const WeakMapLength: typeof WeakMap.length;
+ export const WeakMapName: typeof WeakMap.name;
+ export const WeakMapPrototype: typeof WeakMap.prototype;
+ export const WeakMapPrototypeDelete: UncurryThis<
+ typeof WeakMap.prototype.delete
+ >;
+ export const WeakMapPrototypeGet: UncurryThis<typeof WeakMap.prototype.get>;
+ export const WeakMapPrototypeSet: UncurryThis<typeof WeakMap.prototype.set>;
+ export const WeakMapPrototypeHas: UncurryThis<typeof WeakMap.prototype.has>;
+ export const WeakSet: typeof globalThis.WeakSet;
+ export const WeakSetLength: typeof WeakSet.length;
+ export const WeakSetName: typeof WeakSet.name;
+ export const WeakSetPrototype: typeof WeakSet.prototype;
+ export const WeakSetPrototypeDelete: UncurryThis<
+ typeof WeakSet.prototype.delete
+ >;
+ export const WeakSetPrototypeHas: UncurryThis<typeof WeakSet.prototype.has>;
+ export const WeakSetPrototypeAdd: UncurryThis<typeof WeakSet.prototype.add>;
+ export const Promise: typeof globalThis.Promise;
+ export const PromiseLength: typeof Promise.length;
+ export const PromiseName: typeof Promise.name;
+ export const PromisePrototype: typeof Promise.prototype;
+ export const PromiseAll: typeof Promise.all;
+ export const PromiseRace: typeof Promise.race;
+ export const PromiseResolve: typeof Promise.resolve;
+ export const PromiseReject: typeof Promise.reject;
+ export const PromiseAllSettled: typeof Promise.allSettled;
+ export const PromiseAny: typeof Promise.any;
+ export const PromisePrototypeThen: UncurryThis<
+ typeof Promise.prototype.then
+ >;
+ export const PromisePrototypeCatch: UncurryThis<
+ typeof Promise.prototype.catch
+ >;
+ export const PromisePrototypeFinally: UncurryThis<
+ typeof Promise.prototype.finally
+ >;
+ }
+}
diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs
index 96ee4ff5e..b00bb9c28 100644
--- a/core/ops_builtin.rs
+++ b/core/ops_builtin.rs
@@ -12,8 +12,9 @@ pub(crate) fn init_builtins() -> Extension {
Extension::builder()
.js(include_js_files!(
prefix "deno:core",
- "core.js",
- "error.js",
+ "00_primordials.js",
+ "01_core.js",
+ "02_error.js",
))
.ops(vec![
("op_close", op_sync(op_close)),
diff --git a/core/runtime.rs b/core/runtime.rs
index c2dc09f82..42651a5ef 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -1750,7 +1750,8 @@ pub mod tests {
#[test]
fn test_heap_limits() {
- let create_params = v8::Isolate::create_params().heap_limits(0, 20 * 1024);
+ let create_params =
+ v8::Isolate::create_params().heap_limits(0, 3 * 1024 * 1024);
let mut runtime = JsRuntime::new(RuntimeOptions {
create_params: Some(create_params),
..Default::default()
@@ -1787,13 +1788,14 @@ pub mod tests {
runtime.add_near_heap_limit_callback(|current_limit, _initial_limit| {
current_limit * 2
});
- runtime.remove_near_heap_limit_callback(20 * 1024);
+ runtime.remove_near_heap_limit_callback(3 * 1024 * 1024);
assert!(runtime.allocations.near_heap_limit_callback_data.is_none());
}
#[test]
fn test_heap_limit_cb_multiple() {
- let create_params = v8::Isolate::create_params().heap_limits(0, 20 * 1024);
+ let create_params =
+ v8::Isolate::create_params().heap_limits(0, 3 * 1024 * 1024);
let mut runtime = JsRuntime::new(RuntimeOptions {
create_params: Some(create_params),
..Default::default()
@@ -2029,7 +2031,7 @@ assertEquals(1, notify_return_value);
.unwrap_err();
let error_string = error.to_string();
// Test that the script specifier is a URL: `deno:<repo-relative path>`.
- assert!(error_string.contains("deno:core/core.js"));
+ assert!(error_string.contains("deno:core/01_core.js"));
}
#[test]