@poe-platform/safe-js 0.1.305 → 0.1.307
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/safe-js/chunks/{chunk-JIC2DHRN.js → chunk-V6LQP64H.js} +428 -231
- package/dist/safe-js/chunks/chunk-V6LQP64H.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-OENI52IW.js → chunk-W623YLMU.js} +2 -2
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/dist/safe-js/interp/exceptions.d.ts +1 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-JIC2DHRN.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-OENI52IW.js.map → chunk-W623YLMU.js.map} +0 -0
|
@@ -7013,42 +7013,6 @@ function serializedDateTime(value) {
|
|
|
7013
7013
|
// packages/safe-js/src/interp/internal-symbols.ts
|
|
7014
7014
|
var internalSymbols = /* @__PURE__ */ new Set();
|
|
7015
7015
|
|
|
7016
|
-
// packages/safe-js/src/interp/generator-properties.ts
|
|
7017
|
-
var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7018
|
-
function getGeneratorProperties(value) {
|
|
7019
|
-
let properties = generatorGuestProperties.get(value);
|
|
7020
|
-
if (properties === void 0) {
|
|
7021
|
-
properties = /* @__PURE__ */ Object.create(null);
|
|
7022
|
-
generatorGuestProperties.set(value, properties);
|
|
7023
|
-
}
|
|
7024
|
-
return properties;
|
|
7025
|
-
}
|
|
7026
|
-
|
|
7027
|
-
// packages/safe-js/src/interp/regexp-properties.ts
|
|
7028
|
-
var regexGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7029
|
-
function getRegexProperties(value) {
|
|
7030
|
-
const properties = regexGuestProperties.get(value);
|
|
7031
|
-
if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
|
|
7032
|
-
return properties;
|
|
7033
|
-
}
|
|
7034
|
-
|
|
7035
|
-
// packages/safe-js/src/interp/collection-properties.ts
|
|
7036
|
-
var collectionGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7037
|
-
function getCollectionProperties(value) {
|
|
7038
|
-
const properties = collectionGuestProperties.get(value);
|
|
7039
|
-
if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
|
|
7040
|
-
return properties;
|
|
7041
|
-
}
|
|
7042
|
-
function copyCollectionProperties(source, target, encode) {
|
|
7043
|
-
const properties = collectionGuestProperties.get(source) ?? source;
|
|
7044
|
-
for (const key of Reflect.ownKeys(properties)) {
|
|
7045
|
-
const descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
7046
|
-
if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
|
|
7047
|
-
Object.defineProperty(target, key, { ...descriptor, value: encode(descriptor.value) });
|
|
7048
|
-
}
|
|
7049
|
-
if (!Object.isExtensible(properties)) Object.preventExtensions(target);
|
|
7050
|
-
}
|
|
7051
|
-
|
|
7052
7016
|
// packages/safe-js/src/interp/accessors.ts
|
|
7053
7017
|
var accessorClosures = /* @__PURE__ */ new WeakMap();
|
|
7054
7018
|
var getterAdapters = /* @__PURE__ */ new WeakMap();
|
|
@@ -7107,6 +7071,110 @@ function writePropertyDescriptor(descriptor, receiver, value, context) {
|
|
|
7107
7071
|
return context.invokeClosure(setter, [value], receiver).then(() => void 0);
|
|
7108
7072
|
}
|
|
7109
7073
|
|
|
7074
|
+
// packages/safe-js/src/interp/symbols.ts
|
|
7075
|
+
var wellKnownSymbols = Object.freeze({
|
|
7076
|
+
iterator: Symbol.iterator,
|
|
7077
|
+
asyncIterator: Symbol.asyncIterator,
|
|
7078
|
+
hasInstance: Symbol.hasInstance,
|
|
7079
|
+
isConcatSpreadable: Symbol.isConcatSpreadable,
|
|
7080
|
+
match: Symbol.match,
|
|
7081
|
+
matchAll: Symbol.matchAll,
|
|
7082
|
+
replace: Symbol.replace,
|
|
7083
|
+
search: Symbol.search,
|
|
7084
|
+
species: Symbol.species,
|
|
7085
|
+
split: Symbol.split,
|
|
7086
|
+
toPrimitive: Symbol.toPrimitive,
|
|
7087
|
+
toStringTag: Symbol.toStringTag,
|
|
7088
|
+
unscopables: Symbol.unscopables
|
|
7089
|
+
});
|
|
7090
|
+
|
|
7091
|
+
// packages/safe-js/src/interp/intrinsics.ts
|
|
7092
|
+
var identities = /* @__PURE__ */ new WeakMap();
|
|
7093
|
+
var realms2 = /* @__PURE__ */ new WeakMap();
|
|
7094
|
+
function registerBuiltinIdentities(budget, bindings) {
|
|
7095
|
+
let realm = realms2.get(budget);
|
|
7096
|
+
if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
|
|
7097
|
+
const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
|
|
7098
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
7099
|
+
for (let index = 0; index < pending.length; index++) {
|
|
7100
|
+
const [path, value] = pending[index];
|
|
7101
|
+
if (value === null || typeof value !== "object") continue;
|
|
7102
|
+
const id = JSON.stringify(path);
|
|
7103
|
+
const previous = realm.get(id);
|
|
7104
|
+
if (previous !== void 0 && previous !== value)
|
|
7105
|
+
throw new TypeError(`Duplicate intrinsic identity: ${id}`);
|
|
7106
|
+
realm.set(id, value);
|
|
7107
|
+
if (!identities.has(value)) identities.set(value, id);
|
|
7108
|
+
if (visited.has(value)) continue;
|
|
7109
|
+
visited.add(value);
|
|
7110
|
+
const owner = isSandboxClosure(value) ? value.properties : value;
|
|
7111
|
+
if (owner === void 0) continue;
|
|
7112
|
+
for (const key of Reflect.ownKeys(owner)) {
|
|
7113
|
+
if (typeof key === "symbol" && internalSymbols.has(key)) continue;
|
|
7114
|
+
const descriptor = Object.getOwnPropertyDescriptor(owner, key);
|
|
7115
|
+
const symbolName = typeof key === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol]) => symbol === key)?.[0] : void 0;
|
|
7116
|
+
if (typeof key === "symbol" && symbolName === void 0)
|
|
7117
|
+
throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
|
|
7118
|
+
const member = [...path, typeof key === "string" ? key : { symbol: symbolName }];
|
|
7119
|
+
if ("value" in descriptor) pending.push([member, descriptor.value]);
|
|
7120
|
+
for (const kind of ["get", "set"]) {
|
|
7121
|
+
const closure = accessorClosure(descriptor[kind]);
|
|
7122
|
+
if (closure !== void 0) pending.push([[...member, kind], closure]);
|
|
7123
|
+
}
|
|
7124
|
+
}
|
|
7125
|
+
}
|
|
7126
|
+
}
|
|
7127
|
+
function getIntrinsicIdentity(value) {
|
|
7128
|
+
return identities.get(value);
|
|
7129
|
+
}
|
|
7130
|
+
function resolveIntrinsicIdentity(budget, id) {
|
|
7131
|
+
const value = realms2.get(budget)?.get(id);
|
|
7132
|
+
if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
|
|
7133
|
+
return value;
|
|
7134
|
+
}
|
|
7135
|
+
function listIntrinsicIdentities(budget) {
|
|
7136
|
+
return [...realms2.get(budget)?.keys() ?? []];
|
|
7137
|
+
}
|
|
7138
|
+
function releaseIntrinsicIdentities(budget) {
|
|
7139
|
+
realms2.delete(budget);
|
|
7140
|
+
}
|
|
7141
|
+
|
|
7142
|
+
// packages/safe-js/src/interp/generator-properties.ts
|
|
7143
|
+
var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7144
|
+
function getGeneratorProperties(value) {
|
|
7145
|
+
let properties = generatorGuestProperties.get(value);
|
|
7146
|
+
if (properties === void 0) {
|
|
7147
|
+
properties = /* @__PURE__ */ Object.create(null);
|
|
7148
|
+
generatorGuestProperties.set(value, properties);
|
|
7149
|
+
}
|
|
7150
|
+
return properties;
|
|
7151
|
+
}
|
|
7152
|
+
|
|
7153
|
+
// packages/safe-js/src/interp/regexp-properties.ts
|
|
7154
|
+
var regexGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7155
|
+
function getRegexProperties(value) {
|
|
7156
|
+
const properties = regexGuestProperties.get(value);
|
|
7157
|
+
if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
|
|
7158
|
+
return properties;
|
|
7159
|
+
}
|
|
7160
|
+
|
|
7161
|
+
// packages/safe-js/src/interp/collection-properties.ts
|
|
7162
|
+
var collectionGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7163
|
+
function getCollectionProperties(value) {
|
|
7164
|
+
const properties = collectionGuestProperties.get(value);
|
|
7165
|
+
if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
|
|
7166
|
+
return properties;
|
|
7167
|
+
}
|
|
7168
|
+
function copyCollectionProperties(source, target, encode) {
|
|
7169
|
+
const properties = collectionGuestProperties.get(source) ?? source;
|
|
7170
|
+
for (const key of Reflect.ownKeys(properties)) {
|
|
7171
|
+
const descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
7172
|
+
if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
|
|
7173
|
+
Object.defineProperty(target, key, { ...descriptor, value: encode(descriptor.value) });
|
|
7174
|
+
}
|
|
7175
|
+
if (!Object.isExtensible(properties)) Object.preventExtensions(target);
|
|
7176
|
+
}
|
|
7177
|
+
|
|
7110
7178
|
// packages/safe-js/src/interp/collection-brands.ts
|
|
7111
7179
|
var sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
|
|
7112
7180
|
var sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
|
|
@@ -7450,74 +7518,6 @@ async function withRunResources(signal, execute) {
|
|
|
7450
7518
|
return result;
|
|
7451
7519
|
}
|
|
7452
7520
|
|
|
7453
|
-
// packages/safe-js/src/interp/symbols.ts
|
|
7454
|
-
var wellKnownSymbols = Object.freeze({
|
|
7455
|
-
iterator: Symbol.iterator,
|
|
7456
|
-
asyncIterator: Symbol.asyncIterator,
|
|
7457
|
-
hasInstance: Symbol.hasInstance,
|
|
7458
|
-
isConcatSpreadable: Symbol.isConcatSpreadable,
|
|
7459
|
-
match: Symbol.match,
|
|
7460
|
-
matchAll: Symbol.matchAll,
|
|
7461
|
-
replace: Symbol.replace,
|
|
7462
|
-
search: Symbol.search,
|
|
7463
|
-
species: Symbol.species,
|
|
7464
|
-
split: Symbol.split,
|
|
7465
|
-
toPrimitive: Symbol.toPrimitive,
|
|
7466
|
-
toStringTag: Symbol.toStringTag,
|
|
7467
|
-
unscopables: Symbol.unscopables
|
|
7468
|
-
});
|
|
7469
|
-
|
|
7470
|
-
// packages/safe-js/src/interp/intrinsics.ts
|
|
7471
|
-
var identities = /* @__PURE__ */ new WeakMap();
|
|
7472
|
-
var realms2 = /* @__PURE__ */ new WeakMap();
|
|
7473
|
-
function registerBuiltinIdentities(budget, bindings) {
|
|
7474
|
-
let realm = realms2.get(budget);
|
|
7475
|
-
if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
|
|
7476
|
-
const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
|
|
7477
|
-
const visited = /* @__PURE__ */ new WeakSet();
|
|
7478
|
-
for (let index = 0; index < pending.length; index++) {
|
|
7479
|
-
const [path, value] = pending[index];
|
|
7480
|
-
if (value === null || typeof value !== "object") continue;
|
|
7481
|
-
const id = JSON.stringify(path);
|
|
7482
|
-
const previous = realm.get(id);
|
|
7483
|
-
if (previous !== void 0 && previous !== value)
|
|
7484
|
-
throw new TypeError(`Duplicate intrinsic identity: ${id}`);
|
|
7485
|
-
realm.set(id, value);
|
|
7486
|
-
if (!identities.has(value)) identities.set(value, id);
|
|
7487
|
-
if (visited.has(value)) continue;
|
|
7488
|
-
visited.add(value);
|
|
7489
|
-
const owner = isSandboxClosure(value) ? value.properties : value;
|
|
7490
|
-
if (owner === void 0) continue;
|
|
7491
|
-
for (const key of Reflect.ownKeys(owner)) {
|
|
7492
|
-
if (typeof key === "symbol" && internalSymbols.has(key)) continue;
|
|
7493
|
-
const descriptor = Object.getOwnPropertyDescriptor(owner, key);
|
|
7494
|
-
const symbolName = typeof key === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol]) => symbol === key)?.[0] : void 0;
|
|
7495
|
-
if (typeof key === "symbol" && symbolName === void 0)
|
|
7496
|
-
throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
|
|
7497
|
-
const member = [...path, typeof key === "string" ? key : { symbol: symbolName }];
|
|
7498
|
-
if ("value" in descriptor) pending.push([member, descriptor.value]);
|
|
7499
|
-
for (const kind of ["get", "set"]) {
|
|
7500
|
-
const closure = accessorClosure(descriptor[kind]);
|
|
7501
|
-
if (closure !== void 0) pending.push([[...member, kind], closure]);
|
|
7502
|
-
}
|
|
7503
|
-
}
|
|
7504
|
-
}
|
|
7505
|
-
}
|
|
7506
|
-
function getIntrinsicIdentity(value) {
|
|
7507
|
-
return identities.get(value);
|
|
7508
|
-
}
|
|
7509
|
-
function resolveIntrinsicIdentity(budget, id) {
|
|
7510
|
-
const value = realms2.get(budget)?.get(id);
|
|
7511
|
-
if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
|
|
7512
|
-
return value;
|
|
7513
|
-
}
|
|
7514
|
-
function listIntrinsicIdentities(budget) {
|
|
7515
|
-
return [...realms2.get(budget)?.keys() ?? []];
|
|
7516
|
-
}
|
|
7517
|
-
function releaseIntrinsicIdentities(budget) {
|
|
7518
|
-
realms2.delete(budget);
|
|
7519
|
-
}
|
|
7520
|
-
|
|
7521
7521
|
// packages/safe-js/src/interp/host-capabilities.ts
|
|
7522
7522
|
import { types as types4 } from "node:util";
|
|
7523
7523
|
var MAX_INDEXED_LENGTH = 65536;
|
|
@@ -7862,6 +7862,9 @@ function namedKeys(state) {
|
|
|
7862
7862
|
});
|
|
7863
7863
|
}
|
|
7864
7864
|
|
|
7865
|
+
// packages/safe-js/src/interp/error-prototypes.ts
|
|
7866
|
+
var errorPrototypes = /* @__PURE__ */ new WeakMap();
|
|
7867
|
+
|
|
7865
7868
|
// packages/safe-js/src/interp/object-model.ts
|
|
7866
7869
|
var guestClosures = /* @__PURE__ */ new WeakSet();
|
|
7867
7870
|
var functionProperties = /* @__PURE__ */ new WeakMap();
|
|
@@ -8086,11 +8089,17 @@ function releaseObjectPrototype(budget) {
|
|
|
8086
8089
|
arrayPrototypes.delete(budget);
|
|
8087
8090
|
functionPrototypes.delete(budget);
|
|
8088
8091
|
generatorPrototypes.delete(budget);
|
|
8092
|
+
errorPrototypes.delete(budget);
|
|
8089
8093
|
initialRegexDescriptors.delete(budget);
|
|
8090
8094
|
intrinsicPrototypes.delete(budget);
|
|
8091
8095
|
}
|
|
8092
8096
|
function getSandboxPrototype(value, budget) {
|
|
8093
8097
|
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
8098
|
+
const errorType = sandboxErrorTypes.get(value);
|
|
8099
|
+
if (budget !== void 0 && errorType !== void 0) {
|
|
8100
|
+
const prototype = errorPrototypes.get(budget)?.get(errorType);
|
|
8101
|
+
if (prototype !== void 0) return prototype;
|
|
8102
|
+
}
|
|
8094
8103
|
if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
|
|
8095
8104
|
return functionPrototypes.get(budget) ?? null;
|
|
8096
8105
|
if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
|
|
@@ -14474,74 +14483,6 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
|
|
|
14474
14483
|
}
|
|
14475
14484
|
}
|
|
14476
14485
|
|
|
14477
|
-
// packages/safe-js/src/interp/globals/error.ts
|
|
14478
|
-
var errorConstructorNames = /* @__PURE__ */ new WeakMap();
|
|
14479
|
-
var errorNames = [
|
|
14480
|
-
"Error",
|
|
14481
|
-
"TypeError",
|
|
14482
|
-
"RangeError",
|
|
14483
|
-
"ReferenceError",
|
|
14484
|
-
"SyntaxError",
|
|
14485
|
-
"URIError",
|
|
14486
|
-
"EvalError",
|
|
14487
|
-
"AggregateError"
|
|
14488
|
-
];
|
|
14489
|
-
function createErrorGlobals(options) {
|
|
14490
|
-
return Object.fromEntries(
|
|
14491
|
-
errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
|
|
14492
|
-
);
|
|
14493
|
-
}
|
|
14494
|
-
function isSandboxErrorConstructorInstance2(value, constructor) {
|
|
14495
|
-
if (!isSandboxClosure(constructor)) {
|
|
14496
|
-
throw new TypeError("Right-hand side of 'instanceof' is not a function.");
|
|
14497
|
-
}
|
|
14498
|
-
const name = errorConstructorNames.get(constructor);
|
|
14499
|
-
if (name === void 0) {
|
|
14500
|
-
return false;
|
|
14501
|
-
}
|
|
14502
|
-
return isSandboxErrorConstructorInstance(value, name);
|
|
14503
|
-
}
|
|
14504
|
-
function createErrorConstructor(name, budget) {
|
|
14505
|
-
const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
|
|
14506
|
-
const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
|
|
14507
|
-
errorConstructorNames.set(closure, name);
|
|
14508
|
-
return closure;
|
|
14509
|
-
}
|
|
14510
|
-
function createSubsetError(name, args, stackFrames, budget) {
|
|
14511
|
-
const message = name === "AggregateError" ? args[1] : args[0];
|
|
14512
|
-
const options = name === "AggregateError" ? args[2] : args[1];
|
|
14513
|
-
const error = createSubsetErrorValue(name, message, stackFrames, budget);
|
|
14514
|
-
if (name === "AggregateError") {
|
|
14515
|
-
const errors = Array.isArray(args[0]) ? [...args[0]] : [];
|
|
14516
|
-
budget.allocateArrayLength(errors.length);
|
|
14517
|
-
error.errors = errors;
|
|
14518
|
-
}
|
|
14519
|
-
if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
|
|
14520
|
-
error.cause = options.cause;
|
|
14521
|
-
}
|
|
14522
|
-
return error;
|
|
14523
|
-
}
|
|
14524
|
-
function isObjectLike(value) {
|
|
14525
|
-
return typeof value === "object" && value !== null;
|
|
14526
|
-
}
|
|
14527
|
-
|
|
14528
|
-
// packages/safe-js/src/interp/methods/collection-iterator.ts
|
|
14529
|
-
function getCollectionIteratorMember(target, property, budget) {
|
|
14530
|
-
if (Object.hasOwn(target, property)) return target[property];
|
|
14531
|
-
if (property !== "next") return void 0;
|
|
14532
|
-
const { collectionKind } = collectionIteratorState(target);
|
|
14533
|
-
return createSandboxClosure({
|
|
14534
|
-
sandbox: true,
|
|
14535
|
-
name: "next",
|
|
14536
|
-
call: (_args, context) => {
|
|
14537
|
-
const receiver = context?.thisValue;
|
|
14538
|
-
if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
|
|
14539
|
-
throw new TypeError("Iterator next requires a matching collection iterator receiver.");
|
|
14540
|
-
return nextCollectionIterator(receiver, budget);
|
|
14541
|
-
}
|
|
14542
|
-
});
|
|
14543
|
-
}
|
|
14544
|
-
|
|
14545
14486
|
// packages/safe-js/src/interp/globals/float32array.ts
|
|
14546
14487
|
var constructors = /* @__PURE__ */ new WeakSet();
|
|
14547
14488
|
function createFloat32ArrayGlobal(budget) {
|
|
@@ -14667,6 +14608,207 @@ function relativeIndex(value, length, fallback) {
|
|
|
14667
14608
|
return integer2 < 0 ? Math.max(length + integer2, 0) : Math.min(integer2, length);
|
|
14668
14609
|
}
|
|
14669
14610
|
|
|
14611
|
+
// packages/safe-js/src/interp/globals/error.ts
|
|
14612
|
+
var errorConstructorNames = /* @__PURE__ */ new WeakMap();
|
|
14613
|
+
var errorNames = [
|
|
14614
|
+
"Error",
|
|
14615
|
+
"TypeError",
|
|
14616
|
+
"RangeError",
|
|
14617
|
+
"ReferenceError",
|
|
14618
|
+
"SyntaxError",
|
|
14619
|
+
"URIError",
|
|
14620
|
+
"EvalError",
|
|
14621
|
+
"AggregateError"
|
|
14622
|
+
];
|
|
14623
|
+
function createErrorGlobals(options) {
|
|
14624
|
+
return Object.fromEntries(
|
|
14625
|
+
errorNames.map((name) => [name, createErrorConstructor(name, options.budget, options.errorPrototypes === true)])
|
|
14626
|
+
);
|
|
14627
|
+
}
|
|
14628
|
+
function isSandboxErrorConstructorInstance2(value, constructor) {
|
|
14629
|
+
if (!isSandboxClosure(constructor)) {
|
|
14630
|
+
throw new TypeError("Right-hand side of 'instanceof' is not a function.");
|
|
14631
|
+
}
|
|
14632
|
+
const name = errorConstructorNames.get(constructor);
|
|
14633
|
+
if (name === void 0) {
|
|
14634
|
+
return false;
|
|
14635
|
+
}
|
|
14636
|
+
return isSandboxErrorConstructorInstance(value, name);
|
|
14637
|
+
}
|
|
14638
|
+
function createErrorConstructor(name, budget, guest) {
|
|
14639
|
+
const call = (args, context) => errorPrototypes.has(budget) ? createNativeError(name, args, budget, context, closure) : createSubsetError(name, args, context?.stack ?? [], budget);
|
|
14640
|
+
const closure = createSandboxClosure({ guest, sandbox: true, call, construct: call, name, length: name === "AggregateError" ? 2 : 1 });
|
|
14641
|
+
errorConstructorNames.set(closure, name);
|
|
14642
|
+
return closure;
|
|
14643
|
+
}
|
|
14644
|
+
function createErrorPrototypes(budget, constructors2) {
|
|
14645
|
+
const prototypes2 = /* @__PURE__ */ new Map();
|
|
14646
|
+
for (const name of errorNames) prototypes2.set(name, /* @__PURE__ */ Object.create(null));
|
|
14647
|
+
errorPrototypes.set(budget, prototypes2);
|
|
14648
|
+
for (const name of errorNames) {
|
|
14649
|
+
const constructor = constructors2[name];
|
|
14650
|
+
const prototype = prototypes2.get(name);
|
|
14651
|
+
Object.defineProperties(prototype, {
|
|
14652
|
+
name: { value: name, writable: true, configurable: true },
|
|
14653
|
+
message: { value: "", writable: true, configurable: true },
|
|
14654
|
+
constructor: { value: constructor, writable: true, configurable: true }
|
|
14655
|
+
});
|
|
14656
|
+
Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
|
|
14657
|
+
setSandboxPrototype(prototype, name === "Error" ? getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget) : prototypes2.get("Error"));
|
|
14658
|
+
if (name !== "Error") setSandboxPrototype(constructor, constructors2.Error);
|
|
14659
|
+
}
|
|
14660
|
+
Object.defineProperty(prototypes2.get("Error"), "toString", {
|
|
14661
|
+
writable: true,
|
|
14662
|
+
configurable: true,
|
|
14663
|
+
value: createSandboxClosure({
|
|
14664
|
+
guest: true,
|
|
14665
|
+
sandbox: true,
|
|
14666
|
+
name: "toString",
|
|
14667
|
+
length: 0,
|
|
14668
|
+
call: async (_args, context) => {
|
|
14669
|
+
const receiver = context?.thisValue;
|
|
14670
|
+
if (receiver === null || typeof receiver !== "object") throw new TypeError("Error.prototype.toString requires an object.");
|
|
14671
|
+
let name;
|
|
14672
|
+
const release = retainValues(budget, () => [receiver, name]);
|
|
14673
|
+
try {
|
|
14674
|
+
const rawName = await readErrorProperty(receiver, "name", budget, context);
|
|
14675
|
+
name = rawName === void 0 ? "Error" : await sandboxString(rawName, budget, context);
|
|
14676
|
+
const rawMessage = await readErrorProperty(receiver, "message", budget, context);
|
|
14677
|
+
const message = rawMessage === void 0 ? "" : await sandboxString(rawMessage, budget, context);
|
|
14678
|
+
return budget.allocateString(name === "" ? message : message === "" ? name : `${name}: ${message}`);
|
|
14679
|
+
} finally {
|
|
14680
|
+
release();
|
|
14681
|
+
}
|
|
14682
|
+
}
|
|
14683
|
+
})
|
|
14684
|
+
});
|
|
14685
|
+
registerBuiltinIdentities(budget, Object.fromEntries(errorNames.map((name) => [name, constructors2[name]])));
|
|
14686
|
+
for (const name of errorNames) {
|
|
14687
|
+
registerIntrinsicFunction(budget, constructors2[name]);
|
|
14688
|
+
registerIntrinsicObject(budget, prototypes2.get(name));
|
|
14689
|
+
}
|
|
14690
|
+
}
|
|
14691
|
+
async function readErrorProperty(value, key, budget, context) {
|
|
14692
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key);
|
|
14693
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
14694
|
+
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
|
|
14695
|
+
}
|
|
14696
|
+
async function createNativeError(name, args, budget, context, constructor) {
|
|
14697
|
+
const newTarget = context?.newTarget ?? constructor;
|
|
14698
|
+
const candidate = await readErrorProperty(newTarget, "prototype", budget, context);
|
|
14699
|
+
const prototype = candidate !== null && typeof candidate === "object" ? candidate : errorPrototypes.get(budget).get(name);
|
|
14700
|
+
let error;
|
|
14701
|
+
let iterator;
|
|
14702
|
+
const errors = [];
|
|
14703
|
+
const release = retainValues(budget, () => [prototype, error, iterator?.retainedValue, ...errors, ...args]);
|
|
14704
|
+
try {
|
|
14705
|
+
const message = name === "AggregateError" ? args[1] : args[0];
|
|
14706
|
+
const options = name === "AggregateError" ? args[2] : args[1];
|
|
14707
|
+
const text = message === void 0 ? void 0 : await sandboxString(message, budget, context);
|
|
14708
|
+
error = createSubsetErrorValue(name, text, context?.stack ?? [], budget);
|
|
14709
|
+
setSandboxPrototype(error, prototype, budget);
|
|
14710
|
+
if (options !== null && typeof options === "object" && getSandboxPropertyDescriptor(options, "cause", budget) !== void 0) {
|
|
14711
|
+
const cause = await readErrorProperty(options, "cause", budget, context);
|
|
14712
|
+
Object.defineProperty(error, "cause", { value: cause, writable: true, configurable: true });
|
|
14713
|
+
}
|
|
14714
|
+
if (name === "AggregateError") {
|
|
14715
|
+
iterator = context === void 0 ? getSandboxIterator(args[0], budget) : await acquireSandboxIterator(args[0], budget, context);
|
|
14716
|
+
if (iterator === void 0) throw new TypeError("AggregateError errors must be iterable.");
|
|
14717
|
+
while (true) {
|
|
14718
|
+
budget.visitNode();
|
|
14719
|
+
const result = await iterator.next();
|
|
14720
|
+
if (result === null || typeof result !== "object") throw new TypeError("Iterator result must be an object.");
|
|
14721
|
+
if ((await readIteratorResult(iterator, result, "done")).value) break;
|
|
14722
|
+
budget.allocateArrayLength(errors.length + 1);
|
|
14723
|
+
errors.push((await readIteratorResult(iterator, result, "value")).value);
|
|
14724
|
+
}
|
|
14725
|
+
Object.defineProperty(error, "errors", { value: errors, writable: true, configurable: true });
|
|
14726
|
+
}
|
|
14727
|
+
return error;
|
|
14728
|
+
} finally {
|
|
14729
|
+
release();
|
|
14730
|
+
}
|
|
14731
|
+
}
|
|
14732
|
+
function createSubsetError(name, args, stackFrames, budget) {
|
|
14733
|
+
const message = name === "AggregateError" ? args[1] : args[0];
|
|
14734
|
+
const options = name === "AggregateError" ? args[2] : args[1];
|
|
14735
|
+
const error = createSubsetErrorValue(name, message, stackFrames, budget);
|
|
14736
|
+
if (name === "AggregateError") {
|
|
14737
|
+
const errors = Array.isArray(args[0]) ? [...args[0]] : [];
|
|
14738
|
+
budget.allocateArrayLength(errors.length);
|
|
14739
|
+
error.errors = errors;
|
|
14740
|
+
}
|
|
14741
|
+
if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
|
|
14742
|
+
error.cause = options.cause;
|
|
14743
|
+
}
|
|
14744
|
+
return error;
|
|
14745
|
+
}
|
|
14746
|
+
function isObjectLike(value) {
|
|
14747
|
+
return typeof value === "object" && value !== null;
|
|
14748
|
+
}
|
|
14749
|
+
|
|
14750
|
+
// packages/safe-js/src/interp/instanceof.ts
|
|
14751
|
+
async function evaluateInstanceof(value, constructor, budget, context) {
|
|
14752
|
+
if (constructor === null || typeof constructor !== "object")
|
|
14753
|
+
throw new TypeError("Right-hand side of 'instanceof' must be an object.");
|
|
14754
|
+
const method = await readInstanceProperty(constructor, Symbol.hasInstance, budget, context);
|
|
14755
|
+
if (method !== void 0 && method !== null) {
|
|
14756
|
+
if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
|
|
14757
|
+
return Boolean(await invokeBuiltinClosure(method, [value], budget, context, constructor));
|
|
14758
|
+
}
|
|
14759
|
+
if (!isSandboxClosure(constructor))
|
|
14760
|
+
throw new TypeError("Right-hand side of 'instanceof' is not a function.");
|
|
14761
|
+
return ordinaryHasInstance(value, constructor, budget, context);
|
|
14762
|
+
}
|
|
14763
|
+
async function ordinaryHasInstance(value, constructor, budget, context) {
|
|
14764
|
+
if (!isSandboxClosure(constructor)) return false;
|
|
14765
|
+
if (constructor.boundTarget !== void 0) {
|
|
14766
|
+
budget.visitNode();
|
|
14767
|
+
return evaluateInstanceof(value, constructor.boundTarget, budget, context);
|
|
14768
|
+
}
|
|
14769
|
+
if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
|
|
14770
|
+
if ((!isGuestClosure(constructor) || value !== null && typeof value === "object" && !hasExplicitSandboxPrototype(value)) && isSandboxErrorConstructorInstance2(value, constructor)) return true;
|
|
14771
|
+
if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
|
|
14772
|
+
const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
|
|
14773
|
+
if (typeof prototype !== "object" || prototype === null)
|
|
14774
|
+
throw new TypeError("Function has a non-object prototype in instanceof check.");
|
|
14775
|
+
let depth = 0;
|
|
14776
|
+
for (let current = getSandboxPrototype(value, budget); current !== null; current = getSandboxPrototype(current, budget)) {
|
|
14777
|
+
budget.visitNode();
|
|
14778
|
+
assertSandboxDataDepth(depth++);
|
|
14779
|
+
if (current === prototype) return true;
|
|
14780
|
+
}
|
|
14781
|
+
return false;
|
|
14782
|
+
}
|
|
14783
|
+
async function readInstanceProperty(value, key, budget, context) {
|
|
14784
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key);
|
|
14785
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
14786
|
+
if (descriptor === void 0) return void 0;
|
|
14787
|
+
return readPropertyDescriptor(descriptor, value, {
|
|
14788
|
+
...context,
|
|
14789
|
+
stack: context?.stack ?? [],
|
|
14790
|
+
thisValue: value,
|
|
14791
|
+
invokeClosure: context?.invokeClosure ?? ((closure, args, receiver) => invokeBuiltinClosure(closure, args, budget, context, receiver))
|
|
14792
|
+
});
|
|
14793
|
+
}
|
|
14794
|
+
|
|
14795
|
+
// packages/safe-js/src/interp/methods/collection-iterator.ts
|
|
14796
|
+
function getCollectionIteratorMember(target, property, budget) {
|
|
14797
|
+
if (Object.hasOwn(target, property)) return target[property];
|
|
14798
|
+
if (property !== "next") return void 0;
|
|
14799
|
+
const { collectionKind } = collectionIteratorState(target);
|
|
14800
|
+
return createSandboxClosure({
|
|
14801
|
+
sandbox: true,
|
|
14802
|
+
name: "next",
|
|
14803
|
+
call: (_args, context) => {
|
|
14804
|
+
const receiver = context?.thisValue;
|
|
14805
|
+
if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
|
|
14806
|
+
throw new TypeError("Iterator next requires a matching collection iterator receiver.");
|
|
14807
|
+
return nextCollectionIterator(receiver, budget);
|
|
14808
|
+
}
|
|
14809
|
+
});
|
|
14810
|
+
}
|
|
14811
|
+
|
|
14670
14812
|
// packages/safe-js/src/interp/scope.ts
|
|
14671
14813
|
var uninitialized = /* @__PURE__ */ Symbol("uninitialized");
|
|
14672
14814
|
var Scope = class _Scope {
|
|
@@ -17531,42 +17673,11 @@ function applyBinaryOperator(node, left, right, context) {
|
|
|
17531
17673
|
case ">>>":
|
|
17532
17674
|
return toNumber(left) >>> toNumber(right);
|
|
17533
17675
|
case "instanceof":
|
|
17534
|
-
return evaluateInstanceof(left, right, context);
|
|
17676
|
+
return evaluateInstanceof(left, right, context.budget, createCoercionContext(context));
|
|
17535
17677
|
case "in":
|
|
17536
17678
|
return hasSandboxProperty(right, left, context);
|
|
17537
17679
|
}
|
|
17538
17680
|
}
|
|
17539
|
-
async function evaluateInstanceof(left, right, context) {
|
|
17540
|
-
while (true) {
|
|
17541
|
-
if (right === null || typeof right !== "object" && typeof right !== "function")
|
|
17542
|
-
throw new TypeError("Right-hand side of 'instanceof' must be an object.");
|
|
17543
|
-
const method = await getPropertyValue(right, Symbol.hasInstance, context);
|
|
17544
|
-
if (method !== void 0 && method !== null) {
|
|
17545
|
-
if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
|
|
17546
|
-
return Boolean(await invokeSandboxClosure(method, [left], context, context.callStack, void 0, right));
|
|
17547
|
-
}
|
|
17548
|
-
if (!isSandboxClosure(right))
|
|
17549
|
-
throw new TypeError("Right-hand side of 'instanceof' is not a function.");
|
|
17550
|
-
if (right.boundTarget === void 0) break;
|
|
17551
|
-
context.budget.visitNode();
|
|
17552
|
-
right = right.boundTarget;
|
|
17553
|
-
}
|
|
17554
|
-
if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
|
|
17555
|
-
if (isSandboxErrorConstructorInstance2(left, right)) return true;
|
|
17556
|
-
if (isGuestClosure(right)) {
|
|
17557
|
-
if (typeof left !== "object" || left === null) return false;
|
|
17558
|
-
const prototype = await getPropertyValue(right, "prototype", context);
|
|
17559
|
-
if (typeof prototype !== "object" || prototype === null)
|
|
17560
|
-
throw new TypeError("Function has a non-object prototype in instanceof check.");
|
|
17561
|
-
let depth = 0;
|
|
17562
|
-
for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
|
|
17563
|
-
context.budget.visitNode();
|
|
17564
|
-
assertSandboxDataDepth(depth++);
|
|
17565
|
-
if (current === prototype) return true;
|
|
17566
|
-
}
|
|
17567
|
-
}
|
|
17568
|
-
return false;
|
|
17569
|
-
}
|
|
17570
17681
|
function createCoercionContext(context) {
|
|
17571
17682
|
return {
|
|
17572
17683
|
stack: context.callStack,
|
|
@@ -18855,11 +18966,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18855
18966
|
throw reason;
|
|
18856
18967
|
}
|
|
18857
18968
|
if (isSubsetErrorValue(reason)) {
|
|
18858
|
-
normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
|
|
18859
|
-
return reason;
|
|
18969
|
+
return normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
|
|
18860
18970
|
}
|
|
18861
18971
|
if (reason instanceof Error) {
|
|
18862
|
-
const
|
|
18972
|
+
const error2 = createSubsetErrorValue(
|
|
18863
18973
|
reason.name || "Error",
|
|
18864
18974
|
reason.message,
|
|
18865
18975
|
stackFrames,
|
|
@@ -18870,11 +18980,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18870
18980
|
span
|
|
18871
18981
|
}
|
|
18872
18982
|
);
|
|
18873
|
-
normalizeSurfacedSubsetError(
|
|
18874
|
-
return error;
|
|
18983
|
+
return normalizeSurfacedSubsetError(error2, budget, stackFrames, span);
|
|
18875
18984
|
}
|
|
18876
18985
|
if (isErrorLikeValue(reason)) {
|
|
18877
|
-
const
|
|
18986
|
+
const error2 = createSubsetErrorValue(
|
|
18878
18987
|
reason.name || "Error",
|
|
18879
18988
|
reason.message,
|
|
18880
18989
|
stackFrames,
|
|
@@ -18885,13 +18994,13 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18885
18994
|
span
|
|
18886
18995
|
}
|
|
18887
18996
|
);
|
|
18888
|
-
normalizeSurfacedSubsetError(
|
|
18889
|
-
return error;
|
|
18997
|
+
return normalizeSurfacedSubsetError(error2, budget, stackFrames, span);
|
|
18890
18998
|
}
|
|
18891
|
-
|
|
18999
|
+
const error = createSubsetErrorValue("Error", describeThrownValue(reason), stackFrames, budget, {
|
|
18892
19000
|
chargeBudget: false,
|
|
18893
19001
|
span
|
|
18894
19002
|
});
|
|
19003
|
+
return normalizeSurfacedSubsetError(error, budget, stackFrames, span);
|
|
18895
19004
|
}
|
|
18896
19005
|
function createSubsetErrorValue(name, message, stackFrames, budget, options = {}) {
|
|
18897
19006
|
const resumeChecks = options.chargeBudget === false ? budget.suspendChecks() : void 0;
|
|
@@ -18900,11 +19009,15 @@ function createSubsetErrorValue(name, message, stackFrames, budget, options = {}
|
|
|
18900
19009
|
const errorMessage = budget.allocateString(coerceErrorMessage(message));
|
|
18901
19010
|
const header = errorMessage === "" ? errorName : `${errorName}: ${errorMessage}`;
|
|
18902
19011
|
const stack = budget.allocateString([header, ...[...stackFrames].reverse()].join("\n"));
|
|
18903
|
-
const
|
|
18904
|
-
|
|
18905
|
-
|
|
18906
|
-
|
|
18907
|
-
|
|
19012
|
+
const prototype = options.transport ? void 0 : errorPrototypes.get(budget)?.get(toSandboxErrorName(errorName));
|
|
19013
|
+
const error = prototype === void 0 ? { name: errorName, message: errorMessage, stack } : {};
|
|
19014
|
+
if (prototype !== void 0) {
|
|
19015
|
+
if (message !== void 0) Object.defineProperty(error, "message", { value: errorMessage, writable: true, configurable: true });
|
|
19016
|
+
if (!errorPrototypes.get(budget).has(errorName))
|
|
19017
|
+
Object.defineProperty(error, "name", { value: errorName, writable: true, configurable: true });
|
|
19018
|
+
Object.defineProperty(error, "stack", { value: stack, writable: true, configurable: true });
|
|
19019
|
+
setSandboxPrototype(error, prototype, budget);
|
|
19020
|
+
}
|
|
18908
19021
|
sandboxErrorTypes.set(error, toSandboxErrorName(errorName));
|
|
18909
19022
|
attachErrorSpan(error, options.span);
|
|
18910
19023
|
attachWrappedErrorCause(error, options.cause);
|
|
@@ -18925,6 +19038,7 @@ function isSubsetErrorValue(value) {
|
|
|
18925
19038
|
if (typeof value !== "object" || value === null) {
|
|
18926
19039
|
return false;
|
|
18927
19040
|
}
|
|
19041
|
+
if (sandboxErrorTypes.has(value)) return true;
|
|
18928
19042
|
const prototype = Object.getPrototypeOf(value);
|
|
18929
19043
|
return (prototype === Object.prototype || prototype === null) && typeof value.name === "string" && typeof value.message === "string" && typeof value.stack === "string";
|
|
18930
19044
|
}
|
|
@@ -18934,21 +19048,37 @@ function normalizeSurfacedSubsetError(error, budget, stackFrames, span) {
|
|
|
18934
19048
|
const name = budget.allocateString(toSandboxErrorName(readErrorName(error)));
|
|
18935
19049
|
const message = budget.allocateString(readSurfacedErrorMessage(error, name));
|
|
18936
19050
|
const frames = readSandboxStackFrames(error.stack);
|
|
19051
|
+
if (!Object.isExtensible(error) || ["name", "message", "stack"].some((key) => {
|
|
19052
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, key);
|
|
19053
|
+
return descriptor !== void 0 && (!("value" in descriptor) || !descriptor.writable);
|
|
19054
|
+
})) {
|
|
19055
|
+
const original = error;
|
|
19056
|
+
const descriptors2 = Object.getOwnPropertyDescriptors(original);
|
|
19057
|
+
delete descriptors2.name;
|
|
19058
|
+
delete descriptors2.message;
|
|
19059
|
+
delete descriptors2.stack;
|
|
19060
|
+
error = Object.defineProperties({}, descriptors2);
|
|
19061
|
+
const errorType = sandboxErrorTypes.get(original);
|
|
19062
|
+
if (errorType !== void 0) sandboxErrorTypes.set(error, errorType);
|
|
19063
|
+
}
|
|
18937
19064
|
error.name = name;
|
|
18938
19065
|
error.message = message;
|
|
18939
19066
|
error.stack = budget.allocateString(
|
|
18940
19067
|
formatErrorStack(name, message, frames.length > 0 ? frames : [...stackFrames].reverse())
|
|
18941
19068
|
);
|
|
18942
19069
|
attachErrorSpan(error, readErrorSpan(error) ?? span);
|
|
19070
|
+
return error;
|
|
18943
19071
|
} finally {
|
|
18944
19072
|
resumeChecks();
|
|
18945
19073
|
}
|
|
18946
19074
|
}
|
|
18947
19075
|
function readErrorName(error) {
|
|
18948
|
-
|
|
19076
|
+
const name = getSandboxDataProperty(error, "name");
|
|
19077
|
+
return typeof name === "string" && name.length > 0 ? name : sandboxErrorTypes.get(error) ?? "Error";
|
|
18949
19078
|
}
|
|
18950
19079
|
function readSurfacedErrorMessage(error, name) {
|
|
18951
|
-
const
|
|
19080
|
+
const value = getSandboxDataProperty(error, "message");
|
|
19081
|
+
const message = typeof value === "string" ? value : "";
|
|
18952
19082
|
if (message === "") {
|
|
18953
19083
|
return `${name} thrown`;
|
|
18954
19084
|
}
|
|
@@ -20458,8 +20588,14 @@ function captureGuestHeapNode(value, encode) {
|
|
|
20458
20588
|
}
|
|
20459
20589
|
if (isLiveCapability(value) || isSandboxClosure(value) || isSandboxBox(value) || isSandboxDate(value) || isSandboxRegex(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxArguments(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value)) return void 0;
|
|
20460
20590
|
const prototype = Object.getPrototypeOf(value);
|
|
20461
|
-
if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value))
|
|
20462
|
-
|
|
20591
|
+
if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value)) {
|
|
20592
|
+
const errorType = sandboxErrorTypes.get(value);
|
|
20593
|
+
return {
|
|
20594
|
+
kind: "guest-object",
|
|
20595
|
+
state: captureObjectState(value, encode),
|
|
20596
|
+
...errorType === void 0 ? {} : { errorType }
|
|
20597
|
+
};
|
|
20598
|
+
}
|
|
20463
20599
|
return void 0;
|
|
20464
20600
|
}
|
|
20465
20601
|
if (origin.node.nodeId === void 0) throw new TypeError("Guest closures require an AST node identity.");
|
|
@@ -22051,9 +22187,11 @@ function createHostErrorValue(reason, stackFrames, budget, span, state = { seen:
|
|
|
22051
22187
|
}
|
|
22052
22188
|
const error = reason instanceof Error ? createSubsetErrorValue(reason.name, reason.message, stackFrames, budget, {
|
|
22053
22189
|
cause: reason,
|
|
22054
|
-
chargeBudget
|
|
22190
|
+
chargeBudget,
|
|
22191
|
+
transport: true
|
|
22055
22192
|
}) : createSubsetErrorValue("Error", describeThrownReason(reason), stackFrames, budget, {
|
|
22056
|
-
chargeBudget: false
|
|
22193
|
+
chargeBudget: false,
|
|
22194
|
+
transport: true
|
|
22057
22195
|
});
|
|
22058
22196
|
if (reason instanceof Error) {
|
|
22059
22197
|
state.seen.set(reason, error);
|
|
@@ -24069,7 +24207,7 @@ function createUriGlobals(budget) {
|
|
|
24069
24207
|
}
|
|
24070
24208
|
|
|
24071
24209
|
// packages/safe-js/src/interp/globals/function.ts
|
|
24072
|
-
function createFunctionPrototype(budget) {
|
|
24210
|
+
function createFunctionPrototype(budget, installHasInstance = true) {
|
|
24073
24211
|
const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
|
|
24074
24212
|
const properties = materializeFunctionProperties(prototype);
|
|
24075
24213
|
Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
|
|
@@ -24089,8 +24227,17 @@ function createFunctionPrototype(budget) {
|
|
|
24089
24227
|
})
|
|
24090
24228
|
});
|
|
24091
24229
|
}
|
|
24230
|
+
const hasInstance = installHasInstance ? createSandboxClosure({
|
|
24231
|
+
guest: true,
|
|
24232
|
+
sandbox: true,
|
|
24233
|
+
name: "[Symbol.hasInstance]",
|
|
24234
|
+
length: 1,
|
|
24235
|
+
call: ([value], context) => ordinaryHasInstance(value, context?.thisValue, budget, context)
|
|
24236
|
+
}) : void 0;
|
|
24237
|
+
if (hasInstance !== void 0) Object.defineProperty(properties, Symbol.hasInstance, { value: hasInstance });
|
|
24092
24238
|
setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
24093
24239
|
installFunctionPrototype(budget, prototype);
|
|
24240
|
+
if (hasInstance !== void 0) registerIntrinsicFunction(budget, hasInstance);
|
|
24094
24241
|
}
|
|
24095
24242
|
|
|
24096
24243
|
// packages/safe-js/src/interp/globals/generator.ts
|
|
@@ -24375,7 +24522,7 @@ function createBuiltinBindings(options) {
|
|
|
24375
24522
|
Date: createDateGlobal(options),
|
|
24376
24523
|
Symbol: createSymbolGlobal(options.budget),
|
|
24377
24524
|
BigInt: createBigIntGlobal(options.budget),
|
|
24378
|
-
...createErrorGlobals(options),
|
|
24525
|
+
...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
|
|
24379
24526
|
...createMathGlobals({ random: options.random, budget: options.budget }),
|
|
24380
24527
|
...createObjectArrayGlobals(options),
|
|
24381
24528
|
...createMiscGlobals(options),
|
|
@@ -24383,7 +24530,8 @@ function createBuiltinBindings(options) {
|
|
|
24383
24530
|
...createPromiseGlobals(options),
|
|
24384
24531
|
...createRegexGlobals(options)
|
|
24385
24532
|
};
|
|
24386
|
-
createFunctionPrototype(options.budget);
|
|
24533
|
+
createFunctionPrototype(options.budget, options.functionHasInstance);
|
|
24534
|
+
if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
|
|
24387
24535
|
createGeneratorPrototypes(options.budget);
|
|
24388
24536
|
registerBuiltinIdentities(options.budget, bindings);
|
|
24389
24537
|
return bindings;
|
|
@@ -24503,7 +24651,9 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24503
24651
|
}
|
|
24504
24652
|
state(node.state);
|
|
24505
24653
|
} else if (node.kind === "guest-object" || node.kind === "guest-array") {
|
|
24506
|
-
fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : []);
|
|
24654
|
+
fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : ["errorType"]);
|
|
24655
|
+
if (Object.hasOwn(node, "errorType") && !sandboxErrorNames.includes(node.errorType))
|
|
24656
|
+
throw new TypeError("Invalid guest error type.");
|
|
24507
24657
|
if (Object.hasOwn(node, "templateOwner")) reference(node.templateOwner, ["guest-array"]);
|
|
24508
24658
|
if (Object.hasOwn(node, "templateNodeId") && integer(node.templateNodeId) < 1)
|
|
24509
24659
|
throw new TypeError("Invalid template source identity.");
|
|
@@ -25473,7 +25623,7 @@ function validateArrayHeap(record4, path, state) {
|
|
|
25473
25623
|
}
|
|
25474
25624
|
function validateErrorType(record4, path) {
|
|
25475
25625
|
if (!Object.hasOwn(record4, "errorType")) return;
|
|
25476
|
-
if (record4.kind !== "object" || !sandboxErrorNames.includes(record4.errorType)) {
|
|
25626
|
+
if (record4.kind !== "object" && record4.kind !== "guest-object" || !sandboxErrorNames.includes(record4.errorType)) {
|
|
25477
25627
|
fail("invalidValue", `${path}.errorType`, "invalid error metadata");
|
|
25478
25628
|
}
|
|
25479
25629
|
}
|
|
@@ -26470,7 +26620,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
26470
26620
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
26471
26621
|
if (descriptor !== void 0) descriptors2.push([key, descriptor]);
|
|
26472
26622
|
}
|
|
26473
|
-
const includeNonEnumerable = isSandboxDate(value) || hasManagedDescriptors(value);
|
|
26623
|
+
const includeNonEnumerable = isSandboxDate(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
|
|
26474
26624
|
for (const [key, descriptor] of descriptors2) {
|
|
26475
26625
|
if (!descriptor.enumerable && !includeNonEnumerable) continue;
|
|
26476
26626
|
usage += 1 + key.length;
|
|
@@ -26803,6 +26953,53 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
|
|
|
26803
26953
|
return options.unwrapHostObject(value);
|
|
26804
26954
|
}
|
|
26805
26955
|
if (nodeTypes.isProxy(value)) throw new TypeError("Unsupported proxy sandbox value.");
|
|
26956
|
+
if (sandboxErrorTypes.has(value) && hasExplicitSandboxPrototype(value)) {
|
|
26957
|
+
const prototype = getSandboxPrototype(value);
|
|
26958
|
+
let nativePrototype = null;
|
|
26959
|
+
if (prototype !== null) {
|
|
26960
|
+
const identity = getIntrinsicIdentity(prototype);
|
|
26961
|
+
const nativePrototypes = {
|
|
26962
|
+
Error: Error.prototype,
|
|
26963
|
+
TypeError: TypeError.prototype,
|
|
26964
|
+
RangeError: RangeError.prototype,
|
|
26965
|
+
ReferenceError: ReferenceError.prototype,
|
|
26966
|
+
SyntaxError: SyntaxError.prototype,
|
|
26967
|
+
URIError: URIError.prototype,
|
|
26968
|
+
EvalError: EvalError.prototype,
|
|
26969
|
+
AggregateError: AggregateError.prototype
|
|
26970
|
+
};
|
|
26971
|
+
const path2 = identity === void 0 ? [] : JSON.parse(identity);
|
|
26972
|
+
if (path2.length !== 2 || typeof path2[0] !== "string" || path2[1] !== "prototype" || !Object.hasOwn(nativePrototypes, path2[0]))
|
|
26973
|
+
throw new TypeError("Custom Error prototype links cannot be copied as data.");
|
|
26974
|
+
nativePrototype = nativePrototypes[path2[0]];
|
|
26975
|
+
let current = prototype;
|
|
26976
|
+
let prototypeDepth = 0;
|
|
26977
|
+
while (current !== null) {
|
|
26978
|
+
assertSandboxDataDepth(++prototypeDepth);
|
|
26979
|
+
const objectPrototype = getIntrinsicIdentity(current) === '["Object","prototype"]';
|
|
26980
|
+
const owner = objectPrototype ? Object.getOwnPropertyDescriptor(current, "constructor")?.value : current;
|
|
26981
|
+
if (owner === null || typeof owner !== "object" || objectPrototype && getIntrinsicIdentity(owner) !== '["Object"]' || hasGuestObjectState(owner))
|
|
26982
|
+
throw new TypeError("Modified Error prototype links cannot be copied as data.");
|
|
26983
|
+
current = getSandboxPrototype(current);
|
|
26984
|
+
}
|
|
26985
|
+
}
|
|
26986
|
+
const existing = state.seen.get(value);
|
|
26987
|
+
if (existing !== void 0) return existing;
|
|
26988
|
+
const descriptors2 = Reflect.ownKeys(value).filter((key) => typeof key !== "symbol" || !internalSymbols.has(key)).map((key) => [key, Object.getOwnPropertyDescriptor(value, key)]);
|
|
26989
|
+
if (descriptors2.some(([, descriptor]) => !("value" in descriptor)))
|
|
26990
|
+
throw new TypeError("Error accessor properties cannot be copied as data.");
|
|
26991
|
+
const copy = new Error();
|
|
26992
|
+
delete copy.stack;
|
|
26993
|
+
Object.setPrototypeOf(copy, nativePrototype);
|
|
26994
|
+
state.seen.set(value, copy);
|
|
26995
|
+
for (const [key, descriptor] of descriptors2)
|
|
26996
|
+
Object.defineProperty(copy, key, {
|
|
26997
|
+
...descriptor,
|
|
26998
|
+
value: copyFromSandbox(descriptor.value, state, joinPath2(path, key), options, depth + 1)
|
|
26999
|
+
});
|
|
27000
|
+
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
27001
|
+
return copy;
|
|
27002
|
+
}
|
|
26806
27003
|
if (!isSandboxClosure(value) && hasGuestObjectState(value)) {
|
|
26807
27004
|
throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
|
|
26808
27005
|
}
|
|
@@ -41251,4 +41448,4 @@ export {
|
|
|
41251
41448
|
FileSnapshotBackend,
|
|
41252
41449
|
run
|
|
41253
41450
|
};
|
|
41254
|
-
//# sourceMappingURL=chunk-
|
|
41451
|
+
//# sourceMappingURL=chunk-V6LQP64H.js.map
|