@poe-platform/safe-js 0.1.306 → 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-ZSYBRZU6.js → chunk-V6LQP64H.js} +308 -134
- package/dist/safe-js/chunks/chunk-V6LQP64H.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-BYRLOIR7.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-ZSYBRZU6.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-BYRLOIR7.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;
|
|
@@ -14613,7 +14622,7 @@ var errorNames = [
|
|
|
14613
14622
|
];
|
|
14614
14623
|
function createErrorGlobals(options) {
|
|
14615
14624
|
return Object.fromEntries(
|
|
14616
|
-
errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
|
|
14625
|
+
errorNames.map((name) => [name, createErrorConstructor(name, options.budget, options.errorPrototypes === true)])
|
|
14617
14626
|
);
|
|
14618
14627
|
}
|
|
14619
14628
|
function isSandboxErrorConstructorInstance2(value, constructor) {
|
|
@@ -14626,12 +14635,100 @@ function isSandboxErrorConstructorInstance2(value, constructor) {
|
|
|
14626
14635
|
}
|
|
14627
14636
|
return isSandboxErrorConstructorInstance(value, name);
|
|
14628
14637
|
}
|
|
14629
|
-
function createErrorConstructor(name, budget) {
|
|
14630
|
-
const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
|
|
14631
|
-
const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
|
|
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 });
|
|
14632
14641
|
errorConstructorNames.set(closure, name);
|
|
14633
14642
|
return closure;
|
|
14634
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
|
+
}
|
|
14635
14732
|
function createSubsetError(name, args, stackFrames, budget) {
|
|
14636
14733
|
const message = name === "AggregateError" ? args[1] : args[0];
|
|
14637
14734
|
const options = name === "AggregateError" ? args[2] : args[1];
|
|
@@ -14670,7 +14767,7 @@ async function ordinaryHasInstance(value, constructor, budget, context) {
|
|
|
14670
14767
|
return evaluateInstanceof(value, constructor.boundTarget, budget, context);
|
|
14671
14768
|
}
|
|
14672
14769
|
if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
|
|
14673
|
-
if (isSandboxErrorConstructorInstance2(value, constructor)) return true;
|
|
14770
|
+
if ((!isGuestClosure(constructor) || value !== null && typeof value === "object" && !hasExplicitSandboxPrototype(value)) && isSandboxErrorConstructorInstance2(value, constructor)) return true;
|
|
14674
14771
|
if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
|
|
14675
14772
|
const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
|
|
14676
14773
|
if (typeof prototype !== "object" || prototype === null)
|
|
@@ -18869,11 +18966,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18869
18966
|
throw reason;
|
|
18870
18967
|
}
|
|
18871
18968
|
if (isSubsetErrorValue(reason)) {
|
|
18872
|
-
normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
|
|
18873
|
-
return reason;
|
|
18969
|
+
return normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
|
|
18874
18970
|
}
|
|
18875
18971
|
if (reason instanceof Error) {
|
|
18876
|
-
const
|
|
18972
|
+
const error2 = createSubsetErrorValue(
|
|
18877
18973
|
reason.name || "Error",
|
|
18878
18974
|
reason.message,
|
|
18879
18975
|
stackFrames,
|
|
@@ -18884,11 +18980,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18884
18980
|
span
|
|
18885
18981
|
}
|
|
18886
18982
|
);
|
|
18887
|
-
normalizeSurfacedSubsetError(
|
|
18888
|
-
return error;
|
|
18983
|
+
return normalizeSurfacedSubsetError(error2, budget, stackFrames, span);
|
|
18889
18984
|
}
|
|
18890
18985
|
if (isErrorLikeValue(reason)) {
|
|
18891
|
-
const
|
|
18986
|
+
const error2 = createSubsetErrorValue(
|
|
18892
18987
|
reason.name || "Error",
|
|
18893
18988
|
reason.message,
|
|
18894
18989
|
stackFrames,
|
|
@@ -18899,13 +18994,13 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18899
18994
|
span
|
|
18900
18995
|
}
|
|
18901
18996
|
);
|
|
18902
|
-
normalizeSurfacedSubsetError(
|
|
18903
|
-
return error;
|
|
18997
|
+
return normalizeSurfacedSubsetError(error2, budget, stackFrames, span);
|
|
18904
18998
|
}
|
|
18905
|
-
|
|
18999
|
+
const error = createSubsetErrorValue("Error", describeThrownValue(reason), stackFrames, budget, {
|
|
18906
19000
|
chargeBudget: false,
|
|
18907
19001
|
span
|
|
18908
19002
|
});
|
|
19003
|
+
return normalizeSurfacedSubsetError(error, budget, stackFrames, span);
|
|
18909
19004
|
}
|
|
18910
19005
|
function createSubsetErrorValue(name, message, stackFrames, budget, options = {}) {
|
|
18911
19006
|
const resumeChecks = options.chargeBudget === false ? budget.suspendChecks() : void 0;
|
|
@@ -18914,11 +19009,15 @@ function createSubsetErrorValue(name, message, stackFrames, budget, options = {}
|
|
|
18914
19009
|
const errorMessage = budget.allocateString(coerceErrorMessage(message));
|
|
18915
19010
|
const header = errorMessage === "" ? errorName : `${errorName}: ${errorMessage}`;
|
|
18916
19011
|
const stack = budget.allocateString([header, ...[...stackFrames].reverse()].join("\n"));
|
|
18917
|
-
const
|
|
18918
|
-
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
|
|
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
|
+
}
|
|
18922
19021
|
sandboxErrorTypes.set(error, toSandboxErrorName(errorName));
|
|
18923
19022
|
attachErrorSpan(error, options.span);
|
|
18924
19023
|
attachWrappedErrorCause(error, options.cause);
|
|
@@ -18939,6 +19038,7 @@ function isSubsetErrorValue(value) {
|
|
|
18939
19038
|
if (typeof value !== "object" || value === null) {
|
|
18940
19039
|
return false;
|
|
18941
19040
|
}
|
|
19041
|
+
if (sandboxErrorTypes.has(value)) return true;
|
|
18942
19042
|
const prototype = Object.getPrototypeOf(value);
|
|
18943
19043
|
return (prototype === Object.prototype || prototype === null) && typeof value.name === "string" && typeof value.message === "string" && typeof value.stack === "string";
|
|
18944
19044
|
}
|
|
@@ -18948,21 +19048,37 @@ function normalizeSurfacedSubsetError(error, budget, stackFrames, span) {
|
|
|
18948
19048
|
const name = budget.allocateString(toSandboxErrorName(readErrorName(error)));
|
|
18949
19049
|
const message = budget.allocateString(readSurfacedErrorMessage(error, name));
|
|
18950
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
|
+
}
|
|
18951
19064
|
error.name = name;
|
|
18952
19065
|
error.message = message;
|
|
18953
19066
|
error.stack = budget.allocateString(
|
|
18954
19067
|
formatErrorStack(name, message, frames.length > 0 ? frames : [...stackFrames].reverse())
|
|
18955
19068
|
);
|
|
18956
19069
|
attachErrorSpan(error, readErrorSpan(error) ?? span);
|
|
19070
|
+
return error;
|
|
18957
19071
|
} finally {
|
|
18958
19072
|
resumeChecks();
|
|
18959
19073
|
}
|
|
18960
19074
|
}
|
|
18961
19075
|
function readErrorName(error) {
|
|
18962
|
-
|
|
19076
|
+
const name = getSandboxDataProperty(error, "name");
|
|
19077
|
+
return typeof name === "string" && name.length > 0 ? name : sandboxErrorTypes.get(error) ?? "Error";
|
|
18963
19078
|
}
|
|
18964
19079
|
function readSurfacedErrorMessage(error, name) {
|
|
18965
|
-
const
|
|
19080
|
+
const value = getSandboxDataProperty(error, "message");
|
|
19081
|
+
const message = typeof value === "string" ? value : "";
|
|
18966
19082
|
if (message === "") {
|
|
18967
19083
|
return `${name} thrown`;
|
|
18968
19084
|
}
|
|
@@ -20472,8 +20588,14 @@ function captureGuestHeapNode(value, encode) {
|
|
|
20472
20588
|
}
|
|
20473
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;
|
|
20474
20590
|
const prototype = Object.getPrototypeOf(value);
|
|
20475
|
-
if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value))
|
|
20476
|
-
|
|
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
|
+
}
|
|
20477
20599
|
return void 0;
|
|
20478
20600
|
}
|
|
20479
20601
|
if (origin.node.nodeId === void 0) throw new TypeError("Guest closures require an AST node identity.");
|
|
@@ -22065,9 +22187,11 @@ function createHostErrorValue(reason, stackFrames, budget, span, state = { seen:
|
|
|
22065
22187
|
}
|
|
22066
22188
|
const error = reason instanceof Error ? createSubsetErrorValue(reason.name, reason.message, stackFrames, budget, {
|
|
22067
22189
|
cause: reason,
|
|
22068
|
-
chargeBudget
|
|
22190
|
+
chargeBudget,
|
|
22191
|
+
transport: true
|
|
22069
22192
|
}) : createSubsetErrorValue("Error", describeThrownReason(reason), stackFrames, budget, {
|
|
22070
|
-
chargeBudget: false
|
|
22193
|
+
chargeBudget: false,
|
|
22194
|
+
transport: true
|
|
22071
22195
|
});
|
|
22072
22196
|
if (reason instanceof Error) {
|
|
22073
22197
|
state.seen.set(reason, error);
|
|
@@ -24398,7 +24522,7 @@ function createBuiltinBindings(options) {
|
|
|
24398
24522
|
Date: createDateGlobal(options),
|
|
24399
24523
|
Symbol: createSymbolGlobal(options.budget),
|
|
24400
24524
|
BigInt: createBigIntGlobal(options.budget),
|
|
24401
|
-
...createErrorGlobals(options),
|
|
24525
|
+
...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
|
|
24402
24526
|
...createMathGlobals({ random: options.random, budget: options.budget }),
|
|
24403
24527
|
...createObjectArrayGlobals(options),
|
|
24404
24528
|
...createMiscGlobals(options),
|
|
@@ -24407,6 +24531,7 @@ function createBuiltinBindings(options) {
|
|
|
24407
24531
|
...createRegexGlobals(options)
|
|
24408
24532
|
};
|
|
24409
24533
|
createFunctionPrototype(options.budget, options.functionHasInstance);
|
|
24534
|
+
if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
|
|
24410
24535
|
createGeneratorPrototypes(options.budget);
|
|
24411
24536
|
registerBuiltinIdentities(options.budget, bindings);
|
|
24412
24537
|
return bindings;
|
|
@@ -24526,7 +24651,9 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24526
24651
|
}
|
|
24527
24652
|
state(node.state);
|
|
24528
24653
|
} else if (node.kind === "guest-object" || node.kind === "guest-array") {
|
|
24529
|
-
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.");
|
|
24530
24657
|
if (Object.hasOwn(node, "templateOwner")) reference(node.templateOwner, ["guest-array"]);
|
|
24531
24658
|
if (Object.hasOwn(node, "templateNodeId") && integer(node.templateNodeId) < 1)
|
|
24532
24659
|
throw new TypeError("Invalid template source identity.");
|
|
@@ -25496,7 +25623,7 @@ function validateArrayHeap(record4, path, state) {
|
|
|
25496
25623
|
}
|
|
25497
25624
|
function validateErrorType(record4, path) {
|
|
25498
25625
|
if (!Object.hasOwn(record4, "errorType")) return;
|
|
25499
|
-
if (record4.kind !== "object" || !sandboxErrorNames.includes(record4.errorType)) {
|
|
25626
|
+
if (record4.kind !== "object" && record4.kind !== "guest-object" || !sandboxErrorNames.includes(record4.errorType)) {
|
|
25500
25627
|
fail("invalidValue", `${path}.errorType`, "invalid error metadata");
|
|
25501
25628
|
}
|
|
25502
25629
|
}
|
|
@@ -26493,7 +26620,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
26493
26620
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
26494
26621
|
if (descriptor !== void 0) descriptors2.push([key, descriptor]);
|
|
26495
26622
|
}
|
|
26496
|
-
const includeNonEnumerable = isSandboxDate(value) || hasManagedDescriptors(value);
|
|
26623
|
+
const includeNonEnumerable = isSandboxDate(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
|
|
26497
26624
|
for (const [key, descriptor] of descriptors2) {
|
|
26498
26625
|
if (!descriptor.enumerable && !includeNonEnumerable) continue;
|
|
26499
26626
|
usage += 1 + key.length;
|
|
@@ -26826,6 +26953,53 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
|
|
|
26826
26953
|
return options.unwrapHostObject(value);
|
|
26827
26954
|
}
|
|
26828
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
|
+
}
|
|
26829
27003
|
if (!isSandboxClosure(value) && hasGuestObjectState(value)) {
|
|
26830
27004
|
throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
|
|
26831
27005
|
}
|
|
@@ -41274,4 +41448,4 @@ export {
|
|
|
41274
41448
|
FileSnapshotBackend,
|
|
41275
41449
|
run
|
|
41276
41450
|
};
|
|
41277
|
-
//# sourceMappingURL=chunk-
|
|
41451
|
+
//# sourceMappingURL=chunk-V6LQP64H.js.map
|