poe-code 14.0.81 → 14.0.83
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/index.js +933 -353
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-2LNBLFJ3.js → chunk-37V6Q4K3.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-ZSYBRZU6.js → chunk-PT7PBLVT.js} +764 -224
- package/packages/safe-js/dist/chunks/chunk-PT7PBLVT.js.map +7 -0
- package/packages/safe-js/dist/cli.js +2 -2
- package/packages/safe-js/dist/core.js +1 -1
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/interp/error-prototypes.d.ts +3 -0
- package/packages/safe-js/dist/interp/error-prototypes.js +1 -0
- package/packages/safe-js/dist/interp/exceptions.d.ts +1 -0
- package/packages/safe-js/dist/interp/exceptions.js +39 -15
- package/packages/safe-js/dist/interp/float32-prototypes.d.ts +3 -0
- package/packages/safe-js/dist/interp/float32-prototypes.js +1 -0
- package/packages/safe-js/dist/interp/float32.d.ts +1 -0
- package/packages/safe-js/dist/interp/float32.js +12 -4
- package/packages/safe-js/dist/interp/globals/error.d.ts +2 -0
- package/packages/safe-js/dist/interp/globals/error.js +104 -4
- package/packages/safe-js/dist/interp/globals/float32array.d.ts +3 -2
- package/packages/safe-js/dist/interp/globals/float32array.js +371 -65
- package/packages/safe-js/dist/interp/globals/object-array.js +3 -3
- package/packages/safe-js/dist/interp/globals.d.ts +2 -0
- package/packages/safe-js/dist/interp/globals.js +8 -4
- package/packages/safe-js/dist/interp/host-bridge.js +4 -2
- package/packages/safe-js/dist/interp/instanceof.js +4 -3
- package/packages/safe-js/dist/interp/interpreter.js +2 -4
- package/packages/safe-js/dist/interp/iteration.js +15 -6
- package/packages/safe-js/dist/interp/object-model.js +27 -1
- package/packages/safe-js/dist/interp/values.js +59 -6
- package/packages/safe-js/dist/parse/parser.js +8 -3
- package/packages/safe-js/dist/parse/tokenizer.js +45 -3
- package/packages/safe-js/dist/snapshot/float32array.d.ts +3 -0
- package/packages/safe-js/dist/snapshot/float32array.js +20 -1
- package/packages/safe-js/dist/snapshot/guest-heap-validation.js +4 -1
- package/packages/safe-js/dist/snapshot/guest-heap.d.ts +2 -0
- package/packages/safe-js/dist/snapshot/guest-heap.js +6 -2
- package/packages/safe-js/dist/snapshot/restore.js +33 -3
- package/packages/safe-js/dist/snapshot/serialize.d.ts +2 -1
- package/packages/safe-js/dist/snapshot/serialize.js +10 -9
- package/packages/safe-js/dist/snapshot/validation.js +11 -1
- package/packages/safe-js/dist/chunks/chunk-ZSYBRZU6.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-2LNBLFJ3.js.map → chunk-37V6Q4K3.js.map} +0 -0
|
@@ -1175,7 +1175,7 @@ var Lexer = class {
|
|
|
1175
1175
|
lastClosedControlParenthesis = false;
|
|
1176
1176
|
continue;
|
|
1177
1177
|
}
|
|
1178
|
-
if (char === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(tokens[tokens.length - 1], lastClosedControlParenthesis)) {
|
|
1178
|
+
if (char === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(tokens[tokens.length - 1], lastClosedControlParenthesis, tokens)) {
|
|
1179
1179
|
if (!this.options.allowRegexLiterals) {
|
|
1180
1180
|
this.syntaxError("Regular expression literals are not supported", this.position());
|
|
1181
1181
|
}
|
|
@@ -1444,7 +1444,7 @@ var Lexer = class {
|
|
|
1444
1444
|
}
|
|
1445
1445
|
}
|
|
1446
1446
|
readSlashOrPunctuator(start) {
|
|
1447
|
-
if (this.currentChar() === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(this.lastSignificantToken(), this.lastClosedControlParenthesis)) {
|
|
1447
|
+
if (this.currentChar() === "/" && this.peekChar(1) !== "=" && shouldRejectRegexLiteral(this.lastSignificantToken(), this.lastClosedControlParenthesis, this.tokens)) {
|
|
1448
1448
|
if (!this.options.allowRegexLiterals) {
|
|
1449
1449
|
this.syntaxError("Regular expression literals are not supported", start);
|
|
1450
1450
|
}
|
|
@@ -1728,7 +1728,7 @@ function matchPunctuator(source, index) {
|
|
|
1728
1728
|
(punctuator) => source.startsWith(punctuator, index) && (punctuator !== "?." || !isDecimalDigit(source[index + 2] ?? ""))
|
|
1729
1729
|
);
|
|
1730
1730
|
}
|
|
1731
|
-
function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
|
|
1731
|
+
function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis, tokens) {
|
|
1732
1732
|
if (previousToken === void 0) {
|
|
1733
1733
|
return true;
|
|
1734
1734
|
}
|
|
@@ -1736,6 +1736,7 @@ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
|
|
|
1736
1736
|
return false;
|
|
1737
1737
|
}
|
|
1738
1738
|
if (previousToken.type === "keyword") {
|
|
1739
|
+
if (previousToken.value === "of") return endsWithForOfSeparator(tokens);
|
|
1739
1740
|
return !EXPRESSION_ENDING_KEYWORDS.has(previousToken.value);
|
|
1740
1741
|
}
|
|
1741
1742
|
if (previousToken.value === ")") {
|
|
@@ -1743,6 +1744,35 @@ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
|
|
|
1743
1744
|
}
|
|
1744
1745
|
return !isExpressionEndingPunctuator(previousToken.value);
|
|
1745
1746
|
}
|
|
1747
|
+
function endsWithForOfSeparator(tokens) {
|
|
1748
|
+
let depth = 0;
|
|
1749
|
+
let start = -1;
|
|
1750
|
+
for (let index = tokens.length - 2; index >= 0; index--) {
|
|
1751
|
+
const token = tokens[index];
|
|
1752
|
+
if (token.type !== "punctuator") continue;
|
|
1753
|
+
if ([")", "]", "}"].includes(token.value)) depth++;
|
|
1754
|
+
else if (["(", "[", "{"].includes(token.value)) {
|
|
1755
|
+
if (depth > 0) {
|
|
1756
|
+
depth--;
|
|
1757
|
+
continue;
|
|
1758
|
+
}
|
|
1759
|
+
if (token.value === "(" && (tokens[index - 1]?.value === "for" || tokens[index - 1]?.value === "await" && tokens[index - 2]?.value === "for")) start = index + 1;
|
|
1760
|
+
break;
|
|
1761
|
+
} else if (depth === 0 && token.value === ";") break;
|
|
1762
|
+
}
|
|
1763
|
+
if (start < 0) return false;
|
|
1764
|
+
depth = 0;
|
|
1765
|
+
for (let index = start; index < tokens.length; index++) {
|
|
1766
|
+
const token = tokens[index];
|
|
1767
|
+
if (token.type === "punctuator") {
|
|
1768
|
+
if (["(", "[", "{"].includes(token.value)) depth++;
|
|
1769
|
+
else if ([")", "]", "}"].includes(token.value)) depth--;
|
|
1770
|
+
}
|
|
1771
|
+
if (depth === 0 && token.type === "keyword" && token.value === "of" && index !== start && tokens[index - 1]?.value !== "." && tokens[index - 1]?.value !== "?." && !(index === start + 1 && ["const", "let", "var"].includes(tokens[start].value)))
|
|
1772
|
+
return index === tokens.length - 1;
|
|
1773
|
+
}
|
|
1774
|
+
return false;
|
|
1775
|
+
}
|
|
1746
1776
|
function updateGroupingState(groupingStack, previousToken, punctuator) {
|
|
1747
1777
|
if (punctuator === "(") {
|
|
1748
1778
|
groupingStack.push({
|
|
@@ -5532,6 +5562,7 @@ var Parser = class {
|
|
|
5532
5562
|
return void 0;
|
|
5533
5563
|
}
|
|
5534
5564
|
findTopLevelForIterationOperator(startIndex) {
|
|
5565
|
+
let operator;
|
|
5535
5566
|
let depth = 0;
|
|
5536
5567
|
let previousToken;
|
|
5537
5568
|
for (let index = startIndex; index < this.tokens.length; index += 1) {
|
|
@@ -5541,15 +5572,15 @@ var Parser = class {
|
|
|
5541
5572
|
depth += 1;
|
|
5542
5573
|
} else if (token.value === ")" || token.value === "]" || token.value === "}") {
|
|
5543
5574
|
if (depth === 0 && token.value === ")") {
|
|
5544
|
-
return
|
|
5575
|
+
return operator;
|
|
5545
5576
|
}
|
|
5546
5577
|
depth -= 1;
|
|
5547
5578
|
} else if (depth === 0 && token.value === ";") {
|
|
5548
5579
|
return void 0;
|
|
5549
5580
|
}
|
|
5550
5581
|
}
|
|
5551
|
-
if (depth === 0 && token.type === "keyword" && (token.value === "of" || token.value === "in") && previousToken?.value !== "." && previousToken?.value !== "?.") {
|
|
5552
|
-
|
|
5582
|
+
if (depth === 0 && token.type === "keyword" && (token.value === "of" || token.value === "in") && index !== startIndex && !(token.value === "of" && index === startIndex + 1 && ["const", "let", "var"].includes(previousToken?.value ?? "")) && previousToken?.value !== "." && previousToken?.value !== "?.") {
|
|
5583
|
+
operator ??= token;
|
|
5553
5584
|
}
|
|
5554
5585
|
previousToken = token;
|
|
5555
5586
|
}
|
|
@@ -6542,7 +6573,7 @@ function isLiteralPropertyKey(token) {
|
|
|
6542
6573
|
return token.type === "numeric" || token.type === "string";
|
|
6543
6574
|
}
|
|
6544
6575
|
function isIdentifierLikeToken(token) {
|
|
6545
|
-
return token.type === "identifier" || token.type === "keyword" && token.value === "async";
|
|
6576
|
+
return token.type === "identifier" || token.type === "keyword" && (token.value === "async" || token.value === "of");
|
|
6546
6577
|
}
|
|
6547
6578
|
function isNewToken(token) {
|
|
6548
6579
|
return token.value === "new";
|
|
@@ -6835,13 +6866,20 @@ function float32Storage(value) {
|
|
|
6835
6866
|
byteLength: Reflect.apply(bufferLength, buffer, [])
|
|
6836
6867
|
};
|
|
6837
6868
|
}
|
|
6869
|
+
function float32Properties(value) {
|
|
6870
|
+
const properties = [];
|
|
6871
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
6872
|
+
if (typeof key === "string" && isFloat32Index(key)) continue;
|
|
6873
|
+
properties.push([key, Object.getOwnPropertyDescriptor(value, key)]);
|
|
6874
|
+
}
|
|
6875
|
+
return properties;
|
|
6876
|
+
}
|
|
6838
6877
|
function float32DataProperties(value) {
|
|
6839
6878
|
if (Object.getOwnPropertySymbols(value).length > 0)
|
|
6840
6879
|
throw new TypeError("Float32Array symbol properties are not supported.");
|
|
6841
6880
|
const properties = [];
|
|
6842
|
-
for (const key of
|
|
6843
|
-
if (
|
|
6844
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
6881
|
+
for (const [key, descriptor] of float32Properties(value)) {
|
|
6882
|
+
if (typeof key !== "string") throw new TypeError("Float32Array symbol properties are not supported.");
|
|
6845
6883
|
if (!("value" in descriptor))
|
|
6846
6884
|
throw new TypeError(`Float32Array accessor property '${key}' is not supported.`);
|
|
6847
6885
|
properties.push([key, descriptor]);
|
|
@@ -7013,42 +7051,6 @@ function serializedDateTime(value) {
|
|
|
7013
7051
|
// packages/safe-js/src/interp/internal-symbols.ts
|
|
7014
7052
|
var internalSymbols = /* @__PURE__ */ new Set();
|
|
7015
7053
|
|
|
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
7054
|
// packages/safe-js/src/interp/accessors.ts
|
|
7053
7055
|
var accessorClosures = /* @__PURE__ */ new WeakMap();
|
|
7054
7056
|
var getterAdapters = /* @__PURE__ */ new WeakMap();
|
|
@@ -7107,6 +7109,110 @@ function writePropertyDescriptor(descriptor, receiver, value, context) {
|
|
|
7107
7109
|
return context.invokeClosure(setter, [value], receiver).then(() => void 0);
|
|
7108
7110
|
}
|
|
7109
7111
|
|
|
7112
|
+
// packages/safe-js/src/interp/symbols.ts
|
|
7113
|
+
var wellKnownSymbols = Object.freeze({
|
|
7114
|
+
iterator: Symbol.iterator,
|
|
7115
|
+
asyncIterator: Symbol.asyncIterator,
|
|
7116
|
+
hasInstance: Symbol.hasInstance,
|
|
7117
|
+
isConcatSpreadable: Symbol.isConcatSpreadable,
|
|
7118
|
+
match: Symbol.match,
|
|
7119
|
+
matchAll: Symbol.matchAll,
|
|
7120
|
+
replace: Symbol.replace,
|
|
7121
|
+
search: Symbol.search,
|
|
7122
|
+
species: Symbol.species,
|
|
7123
|
+
split: Symbol.split,
|
|
7124
|
+
toPrimitive: Symbol.toPrimitive,
|
|
7125
|
+
toStringTag: Symbol.toStringTag,
|
|
7126
|
+
unscopables: Symbol.unscopables
|
|
7127
|
+
});
|
|
7128
|
+
|
|
7129
|
+
// packages/safe-js/src/interp/intrinsics.ts
|
|
7130
|
+
var identities = /* @__PURE__ */ new WeakMap();
|
|
7131
|
+
var realms2 = /* @__PURE__ */ new WeakMap();
|
|
7132
|
+
function registerBuiltinIdentities(budget, bindings) {
|
|
7133
|
+
let realm = realms2.get(budget);
|
|
7134
|
+
if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
|
|
7135
|
+
const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
|
|
7136
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
7137
|
+
for (let index = 0; index < pending.length; index++) {
|
|
7138
|
+
const [path, value] = pending[index];
|
|
7139
|
+
if (value === null || typeof value !== "object") continue;
|
|
7140
|
+
const id = JSON.stringify(path);
|
|
7141
|
+
const previous = realm.get(id);
|
|
7142
|
+
if (previous !== void 0 && previous !== value)
|
|
7143
|
+
throw new TypeError(`Duplicate intrinsic identity: ${id}`);
|
|
7144
|
+
realm.set(id, value);
|
|
7145
|
+
if (!identities.has(value)) identities.set(value, id);
|
|
7146
|
+
if (visited.has(value)) continue;
|
|
7147
|
+
visited.add(value);
|
|
7148
|
+
const owner = isSandboxClosure(value) ? value.properties : value;
|
|
7149
|
+
if (owner === void 0) continue;
|
|
7150
|
+
for (const key of Reflect.ownKeys(owner)) {
|
|
7151
|
+
if (typeof key === "symbol" && internalSymbols.has(key)) continue;
|
|
7152
|
+
const descriptor = Object.getOwnPropertyDescriptor(owner, key);
|
|
7153
|
+
const symbolName = typeof key === "symbol" ? Object.entries(wellKnownSymbols).find(([, symbol]) => symbol === key)?.[0] : void 0;
|
|
7154
|
+
if (typeof key === "symbol" && symbolName === void 0)
|
|
7155
|
+
throw new TypeError("Intrinsic symbol keys must be well-known symbols.");
|
|
7156
|
+
const member = [...path, typeof key === "string" ? key : { symbol: symbolName }];
|
|
7157
|
+
if ("value" in descriptor) pending.push([member, descriptor.value]);
|
|
7158
|
+
for (const kind of ["get", "set"]) {
|
|
7159
|
+
const closure = accessorClosure(descriptor[kind]);
|
|
7160
|
+
if (closure !== void 0) pending.push([[...member, kind], closure]);
|
|
7161
|
+
}
|
|
7162
|
+
}
|
|
7163
|
+
}
|
|
7164
|
+
}
|
|
7165
|
+
function getIntrinsicIdentity(value) {
|
|
7166
|
+
return identities.get(value);
|
|
7167
|
+
}
|
|
7168
|
+
function resolveIntrinsicIdentity(budget, id) {
|
|
7169
|
+
const value = realms2.get(budget)?.get(id);
|
|
7170
|
+
if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
|
|
7171
|
+
return value;
|
|
7172
|
+
}
|
|
7173
|
+
function listIntrinsicIdentities(budget) {
|
|
7174
|
+
return [...realms2.get(budget)?.keys() ?? []];
|
|
7175
|
+
}
|
|
7176
|
+
function releaseIntrinsicIdentities(budget) {
|
|
7177
|
+
realms2.delete(budget);
|
|
7178
|
+
}
|
|
7179
|
+
|
|
7180
|
+
// packages/safe-js/src/interp/generator-properties.ts
|
|
7181
|
+
var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7182
|
+
function getGeneratorProperties(value) {
|
|
7183
|
+
let properties = generatorGuestProperties.get(value);
|
|
7184
|
+
if (properties === void 0) {
|
|
7185
|
+
properties = /* @__PURE__ */ Object.create(null);
|
|
7186
|
+
generatorGuestProperties.set(value, properties);
|
|
7187
|
+
}
|
|
7188
|
+
return properties;
|
|
7189
|
+
}
|
|
7190
|
+
|
|
7191
|
+
// packages/safe-js/src/interp/regexp-properties.ts
|
|
7192
|
+
var regexGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7193
|
+
function getRegexProperties(value) {
|
|
7194
|
+
const properties = regexGuestProperties.get(value);
|
|
7195
|
+
if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
|
|
7196
|
+
return properties;
|
|
7197
|
+
}
|
|
7198
|
+
|
|
7199
|
+
// packages/safe-js/src/interp/collection-properties.ts
|
|
7200
|
+
var collectionGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7201
|
+
function getCollectionProperties(value) {
|
|
7202
|
+
const properties = collectionGuestProperties.get(value);
|
|
7203
|
+
if (properties === void 0) throw new TypeError("Invalid sandbox collection storage.");
|
|
7204
|
+
return properties;
|
|
7205
|
+
}
|
|
7206
|
+
function copyCollectionProperties(source, target, encode) {
|
|
7207
|
+
const properties = collectionGuestProperties.get(source) ?? source;
|
|
7208
|
+
for (const key of Reflect.ownKeys(properties)) {
|
|
7209
|
+
const descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
7210
|
+
if (!("value" in descriptor)) throw new TypeError("Collection accessor properties cannot be copied as data.");
|
|
7211
|
+
Object.defineProperty(target, key, { ...descriptor, value: encode(descriptor.value) });
|
|
7212
|
+
}
|
|
7213
|
+
if (!Object.isExtensible(properties)) Object.preventExtensions(target);
|
|
7214
|
+
}
|
|
7215
|
+
|
|
7110
7216
|
// packages/safe-js/src/interp/collection-brands.ts
|
|
7111
7217
|
var sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
|
|
7112
7218
|
var sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
|
|
@@ -7450,74 +7556,6 @@ async function withRunResources(signal, execute) {
|
|
|
7450
7556
|
return result;
|
|
7451
7557
|
}
|
|
7452
7558
|
|
|
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
7559
|
// packages/safe-js/src/interp/host-capabilities.ts
|
|
7522
7560
|
import { types as types4 } from "node:util";
|
|
7523
7561
|
var MAX_INDEXED_LENGTH = 65536;
|
|
@@ -7862,6 +7900,12 @@ function namedKeys(state) {
|
|
|
7862
7900
|
});
|
|
7863
7901
|
}
|
|
7864
7902
|
|
|
7903
|
+
// packages/safe-js/src/interp/error-prototypes.ts
|
|
7904
|
+
var errorPrototypes = /* @__PURE__ */ new WeakMap();
|
|
7905
|
+
|
|
7906
|
+
// packages/safe-js/src/interp/float32-prototypes.ts
|
|
7907
|
+
var float32Prototypes = /* @__PURE__ */ new WeakMap();
|
|
7908
|
+
|
|
7865
7909
|
// packages/safe-js/src/interp/object-model.ts
|
|
7866
7910
|
var guestClosures = /* @__PURE__ */ new WeakSet();
|
|
7867
7911
|
var functionProperties = /* @__PURE__ */ new WeakMap();
|
|
@@ -8086,11 +8130,19 @@ function releaseObjectPrototype(budget) {
|
|
|
8086
8130
|
arrayPrototypes.delete(budget);
|
|
8087
8131
|
functionPrototypes.delete(budget);
|
|
8088
8132
|
generatorPrototypes.delete(budget);
|
|
8133
|
+
errorPrototypes.delete(budget);
|
|
8134
|
+
float32Prototypes.delete(budget);
|
|
8089
8135
|
initialRegexDescriptors.delete(budget);
|
|
8090
8136
|
intrinsicPrototypes.delete(budget);
|
|
8091
8137
|
}
|
|
8092
8138
|
function getSandboxPrototype(value, budget) {
|
|
8093
8139
|
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
8140
|
+
if (isFloat32Array(value)) return budget === void 0 ? null : float32Prototypes.get(budget) ?? null;
|
|
8141
|
+
const errorType = sandboxErrorTypes.get(value);
|
|
8142
|
+
if (budget !== void 0 && errorType !== void 0) {
|
|
8143
|
+
const prototype = errorPrototypes.get(budget)?.get(errorType);
|
|
8144
|
+
if (prototype !== void 0) return prototype;
|
|
8145
|
+
}
|
|
8094
8146
|
if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
|
|
8095
8147
|
return functionPrototypes.get(budget) ?? null;
|
|
8096
8148
|
if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
|
|
@@ -8118,6 +8170,8 @@ function getSandboxPropertyDescriptor(value, key, budget) {
|
|
|
8118
8170
|
let current = value;
|
|
8119
8171
|
let depth = 0;
|
|
8120
8172
|
while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
|
|
8173
|
+
if (isFloat32Array(current) && typeof key !== "symbol" && isFloat32Index(String(key)))
|
|
8174
|
+
return Object.getOwnPropertyDescriptor(current, key);
|
|
8121
8175
|
const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
8122
8176
|
if (properties === void 0 && isGuestClosure(current) && (key === "name" || key === "length"))
|
|
8123
8177
|
return {
|
|
@@ -8140,6 +8194,8 @@ function getSandboxDataProperty(value, key, budget) {
|
|
|
8140
8194
|
let current = value;
|
|
8141
8195
|
let depth = 0;
|
|
8142
8196
|
while (typeof current === "object" && current !== null) {
|
|
8197
|
+
if (isFloat32Array(current) && typeof key !== "symbol" && isFloat32Index(String(key)))
|
|
8198
|
+
return Object.getOwnPropertyDescriptor(current, key)?.value;
|
|
8143
8199
|
if (isGuestHostObject(current)) return typeof key === "symbol" ? void 0 : getHostObjectMember(current, String(key));
|
|
8144
8200
|
if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key)?.value;
|
|
8145
8201
|
if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key)?.value;
|
|
@@ -8191,6 +8247,7 @@ function setSandboxPrototype(value, prototype, budget) {
|
|
|
8191
8247
|
prototypes.set(value, prototype);
|
|
8192
8248
|
}
|
|
8193
8249
|
function isPrototypeRecord(value) {
|
|
8250
|
+
if (isFloat32Array(value)) return true;
|
|
8194
8251
|
if (isGuestClosure(value)) return true;
|
|
8195
8252
|
if (isGuestHostObject(value)) return false;
|
|
8196
8253
|
if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxSet(value))
|
|
@@ -8210,7 +8267,7 @@ function hasGuestObjectState(value) {
|
|
|
8210
8267
|
if (isLiveCapability(value)) return true;
|
|
8211
8268
|
if (functionProperties.has(value) || prototypes.has(value) && !hasNullObjectPrototype(value)) return true;
|
|
8212
8269
|
if (isSandboxBox(value) || isSandboxDate(value)) return false;
|
|
8213
|
-
return descriptorObjects.has(value) && Object.values(Object.getOwnPropertyDescriptors(value)).some(
|
|
8270
|
+
return descriptorObjects.has(value) && (isFloat32Array(value) ? float32Properties(value).map(([, descriptor]) => descriptor) : Object.values(Object.getOwnPropertyDescriptors(value))).some(
|
|
8214
8271
|
(descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
|
|
8215
8272
|
);
|
|
8216
8273
|
}
|
|
@@ -9494,6 +9551,8 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
|
|
|
9494
9551
|
const iterator = await invokeBuiltinClosure(factory, [], budget, context, value);
|
|
9495
9552
|
if (typeof iterator !== "object" && typeof iterator !== "function" || iterator === null)
|
|
9496
9553
|
throw new TypeError("Iterator must be an object.");
|
|
9554
|
+
if (!asyncProtocol && isSandboxGenerator(iterator) && !iterator.async && !hasExplicitSandboxPrototype(iterator) && getSandboxPropertyDescriptor(iterator, "next", budget) === void 0)
|
|
9555
|
+
return getSandboxIterator(iterator, budget, context);
|
|
9497
9556
|
const next = await context.getProperty(iterator, "next");
|
|
9498
9557
|
return guestIterator(iterator, next, asyncProtocol, budget, context, signal);
|
|
9499
9558
|
}
|
|
@@ -9526,7 +9585,7 @@ async function readIteratorResult(iterator, result, property) {
|
|
|
9526
9585
|
}
|
|
9527
9586
|
function getSandboxAsyncIterator(value, budget, context, signal) {
|
|
9528
9587
|
if (isSandboxGenerator(value) && value.async) {
|
|
9529
|
-
return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ?
|
|
9588
|
+
return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? guestProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
|
|
9530
9589
|
}
|
|
9531
9590
|
if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
|
|
9532
9591
|
const method = value[Symbol.asyncIterator];
|
|
@@ -9673,11 +9732,15 @@ function getSandboxIterator(value, budget, context) {
|
|
|
9673
9732
|
}
|
|
9674
9733
|
if (isGuestHostObject(value)) return getHostObjectIterator(value);
|
|
9675
9734
|
if (isFloat32Array(value)) {
|
|
9735
|
+
if (hasExplicitSandboxPrototype(value) || budget !== void 0 && float32Prototypes.has(budget)) {
|
|
9736
|
+
if (getSandboxPropertyDescriptor(value, Symbol.iterator, budget) === void 0) return void 0;
|
|
9737
|
+
return guestProtocolAdapter(value, budget ?? new Budget(), context, false);
|
|
9738
|
+
}
|
|
9676
9739
|
return syncIterator(Float32Array.prototype.values.call(value));
|
|
9677
9740
|
}
|
|
9678
9741
|
if (isSandboxGenerator(value)) {
|
|
9679
9742
|
if (value.async) return void 0;
|
|
9680
|
-
if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ?
|
|
9743
|
+
if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? guestProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
|
|
9681
9744
|
return generatorObjectIterator(value, budget, context);
|
|
9682
9745
|
}
|
|
9683
9746
|
if (typeof value === "string") {
|
|
@@ -9755,7 +9818,7 @@ function collectionIterator(collection, value) {
|
|
|
9755
9818
|
return adapter;
|
|
9756
9819
|
}
|
|
9757
9820
|
var asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
|
|
9758
|
-
function
|
|
9821
|
+
function guestProtocolAdapter(value, budget, context, asyncProtocol, signal) {
|
|
9759
9822
|
const bridge = {
|
|
9760
9823
|
...context,
|
|
9761
9824
|
stack: context?.stack ?? [],
|
|
@@ -9769,7 +9832,7 @@ function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal)
|
|
|
9769
9832
|
let resolved;
|
|
9770
9833
|
let pending;
|
|
9771
9834
|
const initialize = () => pending ??= acquireSandboxIterator(value, budget, bridge, asyncProtocol, signal).then((iterator) => {
|
|
9772
|
-
if (iterator === void 0) throw new TypeError("
|
|
9835
|
+
if (iterator === void 0) throw new TypeError("Value does not provide an iterator protocol.");
|
|
9773
9836
|
return resolved = iterator;
|
|
9774
9837
|
});
|
|
9775
9838
|
return {
|
|
@@ -13640,8 +13703,8 @@ async function definePropertiesFromObject(target, descriptors2, budget, context)
|
|
|
13640
13703
|
}
|
|
13641
13704
|
function defineDataProperty(target, key, descriptor, budget) {
|
|
13642
13705
|
budget.visitNode();
|
|
13643
|
-
if (isFloat32Array(target))
|
|
13644
|
-
|
|
13706
|
+
if (isFloat32Array(target) && typeof key !== "symbol" && isFloat32Index(String(key)) && "value" in descriptor)
|
|
13707
|
+
descriptor = { ...descriptor, value: float32Number(descriptor.value) };
|
|
13645
13708
|
const properties = objectProperties(target, true);
|
|
13646
13709
|
if (Array.isArray(properties)) {
|
|
13647
13710
|
if (key === "length" && "value" in descriptor)
|
|
@@ -14476,8 +14539,9 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
|
|
|
14476
14539
|
|
|
14477
14540
|
// packages/safe-js/src/interp/globals/float32array.ts
|
|
14478
14541
|
var constructors = /* @__PURE__ */ new WeakSet();
|
|
14479
|
-
function createFloat32ArrayGlobal(budget) {
|
|
14542
|
+
function createFloat32ArrayGlobal(budget, nativePrototype = false) {
|
|
14480
14543
|
const constructor = createSandboxClosure({
|
|
14544
|
+
guest: nativePrototype,
|
|
14481
14545
|
sandbox: true,
|
|
14482
14546
|
name: "Float32Array",
|
|
14483
14547
|
length: 3,
|
|
@@ -14485,32 +14549,307 @@ function createFloat32ArrayGlobal(budget) {
|
|
|
14485
14549
|
call: () => {
|
|
14486
14550
|
throw new TypeError("Constructor Float32Array requires 'new'.");
|
|
14487
14551
|
},
|
|
14488
|
-
construct: (
|
|
14489
|
-
if (
|
|
14490
|
-
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
const
|
|
14494
|
-
|
|
14495
|
-
|
|
14496
|
-
const
|
|
14497
|
-
|
|
14498
|
-
|
|
14499
|
-
|
|
14552
|
+
construct: (args, context) => {
|
|
14553
|
+
if (!nativePrototype) return allocateFloat32Array(args[0], budget);
|
|
14554
|
+
return (async () => {
|
|
14555
|
+
const newTarget = context?.newTarget ?? constructor;
|
|
14556
|
+
const candidate = context?.getProperty === void 0 ? getSandboxDataProperty(newTarget, "prototype", budget) : await context.getProperty(newTarget, "prototype");
|
|
14557
|
+
const prototype = candidate !== null && typeof candidate === "object" ? candidate : float32Prototypes.get(budget);
|
|
14558
|
+
const release = retainValues(budget, () => [prototype, ...args]);
|
|
14559
|
+
try {
|
|
14560
|
+
const result = args[0] !== null && typeof args[0] === "object" && !isFloat32Array(args[0]) ? await allocateFloat32Input(args[0], budget, context) : allocateFloat32Array(args[0], budget);
|
|
14561
|
+
setSandboxPrototype(result, prototype, budget);
|
|
14562
|
+
return result;
|
|
14563
|
+
} finally {
|
|
14564
|
+
release();
|
|
14500
14565
|
}
|
|
14501
|
-
|
|
14502
|
-
}
|
|
14503
|
-
const number = float32Number(source);
|
|
14504
|
-
const length = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
14505
|
-
if (length < 0 || !Number.isSafeInteger(length))
|
|
14506
|
-
throw new RangeError("Invalid typed array length.");
|
|
14507
|
-
checkFloat32Allocation(length, budget);
|
|
14508
|
-
return new Float32Array(length);
|
|
14566
|
+
})();
|
|
14509
14567
|
}
|
|
14510
14568
|
});
|
|
14511
14569
|
constructors.add(constructor);
|
|
14512
14570
|
return constructor;
|
|
14513
14571
|
}
|
|
14572
|
+
async function allocateFloat32Input(source, budget, context) {
|
|
14573
|
+
const callerContext = context;
|
|
14574
|
+
const bridge = {
|
|
14575
|
+
...callerContext,
|
|
14576
|
+
stack: callerContext?.stack ?? [],
|
|
14577
|
+
thisValue: void 0,
|
|
14578
|
+
getProperty: callerContext?.getProperty ?? ((value, key) => {
|
|
14579
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
14580
|
+
return descriptor === void 0 ? getSandboxDataProperty(value, key, budget) : readPropertyDescriptor(descriptor, value, bridge);
|
|
14581
|
+
}),
|
|
14582
|
+
invokeClosure: callerContext?.invokeClosure ?? ((callee, values2, receiver, construct) => invokeBuiltinClosure(callee, values2, budget, callerContext, receiver, construct))
|
|
14583
|
+
};
|
|
14584
|
+
const values = [];
|
|
14585
|
+
let iterator;
|
|
14586
|
+
let current;
|
|
14587
|
+
let result;
|
|
14588
|
+
const release = retainValues(budget, () => [source, values, iterator?.retainedValue, current, result]);
|
|
14589
|
+
const checkData = createDataCheckpoint(budget, bridge);
|
|
14590
|
+
try {
|
|
14591
|
+
iterator = await acquireSandboxIterator(source, budget, bridge);
|
|
14592
|
+
let length;
|
|
14593
|
+
if (iterator !== void 0) {
|
|
14594
|
+
while (true) {
|
|
14595
|
+
budget.visitNode();
|
|
14596
|
+
const next = await iterator.next();
|
|
14597
|
+
if (typeof next !== "object" || next === null) throw new TypeError("Iterator result must be an object.");
|
|
14598
|
+
if ((await readIteratorResult(iterator, next, "done")).value) break;
|
|
14599
|
+
current = (await readIteratorResult(iterator, next, "value")).value;
|
|
14600
|
+
budget.allocateArrayLength(values.length + 1);
|
|
14601
|
+
values.push(current);
|
|
14602
|
+
checkData(values, 1 + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([current])));
|
|
14603
|
+
}
|
|
14604
|
+
length = values.length;
|
|
14605
|
+
} else {
|
|
14606
|
+
current = await bridge.getProperty(source, "length");
|
|
14607
|
+
const number = await sandboxNumber(current, budget, bridge);
|
|
14608
|
+
length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
|
|
14609
|
+
}
|
|
14610
|
+
checkFloat32Allocation(length, budget);
|
|
14611
|
+
result = new Float32Array(length);
|
|
14612
|
+
checkData(result, 0, true);
|
|
14613
|
+
for (let index = 0; index < length; index++) {
|
|
14614
|
+
budget.visitNode();
|
|
14615
|
+
current = iterator === void 0 ? await bridge.getProperty(source, String(index)) : values[index];
|
|
14616
|
+
result[index] = await sandboxNumber(current, budget, bridge);
|
|
14617
|
+
}
|
|
14618
|
+
return result;
|
|
14619
|
+
} finally {
|
|
14620
|
+
release();
|
|
14621
|
+
}
|
|
14622
|
+
}
|
|
14623
|
+
function allocateFloat32Array(source, budget) {
|
|
14624
|
+
if (Array.isArray(source) || isFloat32Array(source)) {
|
|
14625
|
+
const length2 = isFloat32Array(source) ? float32Storage(source).length : source.length;
|
|
14626
|
+
checkFloat32Allocation(length2, budget);
|
|
14627
|
+
if (isFloat32Array(source)) return new Float32Array(source);
|
|
14628
|
+
const result = new Float32Array(length2);
|
|
14629
|
+
for (let index = 0; index < length2; index += 1) {
|
|
14630
|
+
budget.visitNode();
|
|
14631
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, index);
|
|
14632
|
+
if (descriptor !== void 0 && !("value" in descriptor))
|
|
14633
|
+
throw new TypeError("Float32Array input accessors are not supported.");
|
|
14634
|
+
result[index] = float32Number(descriptor?.value);
|
|
14635
|
+
}
|
|
14636
|
+
return result;
|
|
14637
|
+
}
|
|
14638
|
+
const number = float32Number(source);
|
|
14639
|
+
const length = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
14640
|
+
if (length < 0 || !Number.isSafeInteger(length))
|
|
14641
|
+
throw new RangeError("Invalid typed array length.");
|
|
14642
|
+
checkFloat32Allocation(length, budget);
|
|
14643
|
+
return new Float32Array(length);
|
|
14644
|
+
}
|
|
14645
|
+
function createFloat32ArrayPrototypes(budget, constructor) {
|
|
14646
|
+
const prototype = /* @__PURE__ */ Object.create(null);
|
|
14647
|
+
const shared = /* @__PURE__ */ Object.create(null);
|
|
14648
|
+
const abstractCall = () => {
|
|
14649
|
+
throw new TypeError("Abstract TypedArray constructor cannot be called.");
|
|
14650
|
+
};
|
|
14651
|
+
const typedArray = createSandboxClosure({
|
|
14652
|
+
guest: true,
|
|
14653
|
+
sandbox: true,
|
|
14654
|
+
name: "TypedArray",
|
|
14655
|
+
length: 0,
|
|
14656
|
+
call: abstractCall,
|
|
14657
|
+
construct: abstractCall
|
|
14658
|
+
});
|
|
14659
|
+
Object.defineProperty(materializeFunctionProperties(typedArray), "prototype", { value: shared, writable: false });
|
|
14660
|
+
Object.defineProperty(materializeFunctionProperties(typedArray), "from", {
|
|
14661
|
+
writable: true,
|
|
14662
|
+
configurable: true,
|
|
14663
|
+
value: createSandboxClosure({
|
|
14664
|
+
guest: true,
|
|
14665
|
+
sandbox: true,
|
|
14666
|
+
name: "from",
|
|
14667
|
+
length: 1,
|
|
14668
|
+
call: async (args, context) => {
|
|
14669
|
+
const target = context?.thisValue;
|
|
14670
|
+
const [source, mapper, receiver] = args;
|
|
14671
|
+
if (!isSandboxClosure(target) || target.construct === void 0)
|
|
14672
|
+
throw new TypeError("TypedArray.from requires a constructor receiver.");
|
|
14673
|
+
if (mapper !== void 0 && !isSandboxClosure(mapper))
|
|
14674
|
+
throw new TypeError("TypedArray.from mapper must be callable.");
|
|
14675
|
+
if (source === null || source === void 0)
|
|
14676
|
+
throw new TypeError("TypedArray.from requires a non-null source.");
|
|
14677
|
+
const callerContext = context;
|
|
14678
|
+
context = {
|
|
14679
|
+
...callerContext,
|
|
14680
|
+
stack: callerContext?.stack ?? [],
|
|
14681
|
+
thisValue: target,
|
|
14682
|
+
getProperty: callerContext?.getProperty ?? ((value, key) => {
|
|
14683
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
14684
|
+
return descriptor === void 0 ? getSandboxDataProperty(value, key, budget) : readPropertyDescriptor(descriptor, value, context);
|
|
14685
|
+
}),
|
|
14686
|
+
invokeClosure: callerContext?.invokeClosure ?? ((callee, values2, thisValue, construct) => invokeBuiltinClosure(callee, values2, budget, callerContext, thisValue, construct))
|
|
14687
|
+
};
|
|
14688
|
+
let result;
|
|
14689
|
+
let current;
|
|
14690
|
+
let iterator;
|
|
14691
|
+
const values = [];
|
|
14692
|
+
const release = retainValues(budget, () => [target, result, current, iterator?.retainedValue, values, ...args]);
|
|
14693
|
+
const checkData = createDataCheckpoint(budget, context);
|
|
14694
|
+
const read = (key) => context?.getProperty === void 0 ? getSandboxDataProperty(source, key, budget) : context.getProperty(source, key);
|
|
14695
|
+
try {
|
|
14696
|
+
iterator = await acquireSandboxIterator(source, budget, context);
|
|
14697
|
+
let length;
|
|
14698
|
+
if (iterator !== void 0) {
|
|
14699
|
+
while (true) {
|
|
14700
|
+
budget.visitNode();
|
|
14701
|
+
const next = await iterator.next();
|
|
14702
|
+
if (typeof next !== "object" || next === null) throw new TypeError("Iterator result must be an object.");
|
|
14703
|
+
if ((await readIteratorResult(iterator, next, "done")).value) break;
|
|
14704
|
+
current = (await readIteratorResult(iterator, next, "value")).value;
|
|
14705
|
+
budget.allocateArrayLength(values.length + 1);
|
|
14706
|
+
values.push(current);
|
|
14707
|
+
checkData(values, 1 + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([current])));
|
|
14708
|
+
}
|
|
14709
|
+
length = values.length;
|
|
14710
|
+
} else {
|
|
14711
|
+
const number = await sandboxNumber(await read("length"), budget, context);
|
|
14712
|
+
length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
|
|
14713
|
+
}
|
|
14714
|
+
result = await invokeBuiltinClosure(target, [length], budget, context, void 0, true);
|
|
14715
|
+
if (!isFloat32Array(result) || float32Storage(result).length < length)
|
|
14716
|
+
throw new TypeError("TypedArray.from constructor must return sufficient typed storage.");
|
|
14717
|
+
checkData(result, 0, true);
|
|
14718
|
+
for (let index = 0; index < length; index++) {
|
|
14719
|
+
budget.visitNode();
|
|
14720
|
+
current = iterator === void 0 ? await read(String(index)) : values[index];
|
|
14721
|
+
if (mapper !== void 0)
|
|
14722
|
+
current = await invokeBuiltinClosure(mapper, [current, index], budget, context, receiver);
|
|
14723
|
+
result[index] = await sandboxNumber(current, budget, context);
|
|
14724
|
+
}
|
|
14725
|
+
return result;
|
|
14726
|
+
} finally {
|
|
14727
|
+
release();
|
|
14728
|
+
}
|
|
14729
|
+
}
|
|
14730
|
+
})
|
|
14731
|
+
});
|
|
14732
|
+
Object.defineProperty(materializeFunctionProperties(typedArray), "of", {
|
|
14733
|
+
writable: true,
|
|
14734
|
+
configurable: true,
|
|
14735
|
+
value: createSandboxClosure({
|
|
14736
|
+
guest: true,
|
|
14737
|
+
sandbox: true,
|
|
14738
|
+
name: "of",
|
|
14739
|
+
length: 0,
|
|
14740
|
+
call: async (args, context) => {
|
|
14741
|
+
const target = context?.thisValue;
|
|
14742
|
+
if (!isSandboxClosure(target) || target.construct === void 0)
|
|
14743
|
+
throw new TypeError("TypedArray.of requires a constructor receiver.");
|
|
14744
|
+
let result;
|
|
14745
|
+
const release = retainValues(budget, () => [target, result, ...args]);
|
|
14746
|
+
try {
|
|
14747
|
+
result = await invokeBuiltinClosure(target, [args.length], budget, context, void 0, true);
|
|
14748
|
+
if (!isFloat32Array(result) || float32Storage(result).length < args.length)
|
|
14749
|
+
throw new TypeError("TypedArray.of constructor must return sufficient typed storage.");
|
|
14750
|
+
for (let index = 0; index < args.length; index++) {
|
|
14751
|
+
budget.visitNode();
|
|
14752
|
+
result[index] = await sandboxNumber(args[index], budget, context);
|
|
14753
|
+
}
|
|
14754
|
+
return result;
|
|
14755
|
+
} finally {
|
|
14756
|
+
release();
|
|
14757
|
+
}
|
|
14758
|
+
}
|
|
14759
|
+
})
|
|
14760
|
+
});
|
|
14761
|
+
Object.defineProperties(materializeFunctionProperties(constructor), {
|
|
14762
|
+
prototype: { value: prototype, writable: false },
|
|
14763
|
+
BYTES_PER_ELEMENT: { value: 4, writable: false, enumerable: false, configurable: false }
|
|
14764
|
+
});
|
|
14765
|
+
Object.defineProperties(prototype, {
|
|
14766
|
+
constructor: { value: constructor, writable: true, configurable: true },
|
|
14767
|
+
BYTES_PER_ELEMENT: { value: 4 }
|
|
14768
|
+
});
|
|
14769
|
+
Object.defineProperty(shared, "constructor", { value: typedArray, writable: true, configurable: true });
|
|
14770
|
+
setSandboxPrototype(constructor, typedArray);
|
|
14771
|
+
setSandboxPrototype(prototype, shared);
|
|
14772
|
+
setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
14773
|
+
const getters = [];
|
|
14774
|
+
for (const key of ["length", "byteLength", "byteOffset"]) {
|
|
14775
|
+
const getter = createSandboxClosure({
|
|
14776
|
+
guest: true,
|
|
14777
|
+
sandbox: true,
|
|
14778
|
+
name: `get ${key}`,
|
|
14779
|
+
length: 0,
|
|
14780
|
+
call: (_args, context) => {
|
|
14781
|
+
if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
|
|
14782
|
+
const storage = float32Storage(context.thisValue);
|
|
14783
|
+
return key === "byteLength" ? storage.length * 4 : storage[key];
|
|
14784
|
+
}
|
|
14785
|
+
});
|
|
14786
|
+
getters.push(getter);
|
|
14787
|
+
Object.defineProperty(shared, key, { get: accessorAdapter(getter, "get"), configurable: true });
|
|
14788
|
+
}
|
|
14789
|
+
for (const key of ["set", "slice", "subarray"])
|
|
14790
|
+
Object.defineProperty(shared, key, { value: getFloat32Member(new Float32Array(0), key, budget), writable: true, configurable: true });
|
|
14791
|
+
const arrayPrototype = resolveIntrinsicIdentity(budget, '["Array","prototype"]');
|
|
14792
|
+
Object.defineProperty(shared, "toString", { value: getSandboxDataProperty(arrayPrototype, "toString", budget), writable: true, configurable: true });
|
|
14793
|
+
Object.defineProperty(shared, "join", {
|
|
14794
|
+
writable: true,
|
|
14795
|
+
configurable: true,
|
|
14796
|
+
value: createSandboxClosure({
|
|
14797
|
+
guest: true,
|
|
14798
|
+
sandbox: true,
|
|
14799
|
+
name: "join",
|
|
14800
|
+
length: 1,
|
|
14801
|
+
call: async (args, context) => {
|
|
14802
|
+
if (!isFloat32Array(context?.thisValue)) throw new TypeError("TypedArray join requires a typed array receiver.");
|
|
14803
|
+
const receiver = context.thisValue;
|
|
14804
|
+
const length = float32Storage(receiver).length;
|
|
14805
|
+
let separator = ",";
|
|
14806
|
+
let text = "";
|
|
14807
|
+
const release = retainValues(budget, () => [receiver, separator, text, ...args]);
|
|
14808
|
+
try {
|
|
14809
|
+
if (args[0] !== void 0) separator = await sandboxString(args[0], budget, context);
|
|
14810
|
+
for (let index = 0; index < length; index++) {
|
|
14811
|
+
budget.visitNode();
|
|
14812
|
+
text = budget.allocateString(text + (index === 0 ? "" : separator) + String(receiver[index]));
|
|
14813
|
+
}
|
|
14814
|
+
return text;
|
|
14815
|
+
} finally {
|
|
14816
|
+
release();
|
|
14817
|
+
}
|
|
14818
|
+
}
|
|
14819
|
+
})
|
|
14820
|
+
});
|
|
14821
|
+
const tagGetter = createSandboxClosure({
|
|
14822
|
+
guest: true,
|
|
14823
|
+
sandbox: true,
|
|
14824
|
+
name: "get [Symbol.toStringTag]",
|
|
14825
|
+
length: 0,
|
|
14826
|
+
call: (_args, context) => isFloat32Array(context?.thisValue) ? "Float32Array" : void 0
|
|
14827
|
+
});
|
|
14828
|
+
getters.push(tagGetter);
|
|
14829
|
+
Object.defineProperty(shared, Symbol.toStringTag, { get: accessorAdapter(tagGetter, "get"), configurable: true });
|
|
14830
|
+
for (const key of ["values", "keys", "entries"]) {
|
|
14831
|
+
const method = getSandboxDataProperty(arrayPrototype, key, budget);
|
|
14832
|
+
const closure = createSandboxClosure({
|
|
14833
|
+
guest: true,
|
|
14834
|
+
sandbox: true,
|
|
14835
|
+
name: key,
|
|
14836
|
+
length: 0,
|
|
14837
|
+
call: (args, context) => {
|
|
14838
|
+
if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
|
|
14839
|
+
return invokeBuiltinClosure(method, args, budget, context, context.thisValue);
|
|
14840
|
+
}
|
|
14841
|
+
});
|
|
14842
|
+
Object.defineProperty(shared, key, { value: closure, writable: true, configurable: true });
|
|
14843
|
+
if (key === "values") Object.defineProperty(shared, Symbol.iterator, { value: closure, writable: true, configurable: true });
|
|
14844
|
+
}
|
|
14845
|
+
float32Prototypes.set(budget, prototype);
|
|
14846
|
+
registerBuiltinIdentities(budget, { Float32Array: constructor, "%TypedArray%": typedArray });
|
|
14847
|
+
registerIntrinsicFunction(budget, constructor);
|
|
14848
|
+
registerIntrinsicFunction(budget, typedArray);
|
|
14849
|
+
registerIntrinsicObject(budget, prototype);
|
|
14850
|
+
registerIntrinsicObject(budget, shared);
|
|
14851
|
+
for (const getter of getters) registerIntrinsicFunction(budget, getter);
|
|
14852
|
+
}
|
|
14514
14853
|
function isFloat32ArrayConstructor(value) {
|
|
14515
14854
|
return typeof value === "object" && value !== null && constructors.has(value);
|
|
14516
14855
|
}
|
|
@@ -14521,6 +14860,7 @@ function getFloat32Member(value, property, budget) {
|
|
|
14521
14860
|
if (!("value" in descriptor)) throw new TypeError("Float32Array accessors are not supported.");
|
|
14522
14861
|
return descriptor.value;
|
|
14523
14862
|
}
|
|
14863
|
+
if (float32Prototypes.has(budget)) return void 0;
|
|
14524
14864
|
const storage = float32Storage(value);
|
|
14525
14865
|
if (key === "length") return storage.length;
|
|
14526
14866
|
if (key === "byteLength") return storage.length * 4;
|
|
@@ -14528,6 +14868,7 @@ function getFloat32Member(value, property, budget) {
|
|
|
14528
14868
|
if (key === "BYTES_PER_ELEMENT") return 4;
|
|
14529
14869
|
if (!["set", "slice", "subarray"].includes(key)) return void 0;
|
|
14530
14870
|
return createSandboxClosure({
|
|
14871
|
+
guest: true,
|
|
14531
14872
|
sandbox: true,
|
|
14532
14873
|
name: key,
|
|
14533
14874
|
length: key === "set" ? 1 : 2,
|
|
@@ -14536,65 +14877,88 @@ function getFloat32Member(value, property, budget) {
|
|
|
14536
14877
|
if (!isFloat32Array(receiver))
|
|
14537
14878
|
throw new TypeError(`Float32Array#${key} requires a Float32Array receiver.`);
|
|
14538
14879
|
const storage2 = float32Storage(receiver);
|
|
14880
|
+
const bridge = {
|
|
14881
|
+
...context,
|
|
14882
|
+
stack: context?.stack ?? [],
|
|
14883
|
+
thisValue: receiver,
|
|
14884
|
+
getProperty: context?.getProperty ?? ((value2, property2) => {
|
|
14885
|
+
const descriptor2 = getSandboxPropertyDescriptor(value2, property2, budget);
|
|
14886
|
+
return descriptor2 === void 0 ? getSandboxDataProperty(value2, property2, budget) : readPropertyDescriptor(descriptor2, value2, bridge);
|
|
14887
|
+
}),
|
|
14888
|
+
invokeClosure: context?.invokeClosure ?? ((callee, values, thisValue, construct) => invokeBuiltinClosure(callee, values, budget, context, thisValue, construct))
|
|
14889
|
+
};
|
|
14539
14890
|
if (key === "set") {
|
|
14540
|
-
|
|
14541
|
-
|
|
14542
|
-
|
|
14543
|
-
|
|
14544
|
-
|
|
14545
|
-
|
|
14546
|
-
|
|
14547
|
-
|
|
14548
|
-
|
|
14549
|
-
|
|
14550
|
-
|
|
14551
|
-
|
|
14552
|
-
|
|
14553
|
-
|
|
14554
|
-
|
|
14555
|
-
|
|
14556
|
-
|
|
14557
|
-
|
|
14558
|
-
throw new
|
|
14559
|
-
|
|
14560
|
-
|
|
14561
|
-
|
|
14562
|
-
|
|
14891
|
+
return (async () => {
|
|
14892
|
+
const [source, offsetValue = 0] = args;
|
|
14893
|
+
let current;
|
|
14894
|
+
let sourceObject;
|
|
14895
|
+
const release = retainValues(budget, () => [receiver, sourceObject, current, ...args]);
|
|
14896
|
+
try {
|
|
14897
|
+
const number = await sandboxNumber(offsetValue, budget, bridge);
|
|
14898
|
+
const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
14899
|
+
if (offset < 0) throw new RangeError("Float32Array#set offset is out of bounds.");
|
|
14900
|
+
if (source === null || source === void 0) throw new TypeError("Float32Array#set requires a non-null source.");
|
|
14901
|
+
let length;
|
|
14902
|
+
if (isFloat32Array(source)) length = float32Storage(source).length;
|
|
14903
|
+
else {
|
|
14904
|
+
sourceObject = typeof source === "object" ? source : createSandboxBox(source);
|
|
14905
|
+
current = await bridge.getProperty(sourceObject, "length");
|
|
14906
|
+
const size = await sandboxNumber(current, budget, bridge);
|
|
14907
|
+
length = Number.isNaN(size) || size <= 0 ? 0 : Math.min(Math.trunc(size), Number.MAX_SAFE_INTEGER);
|
|
14908
|
+
}
|
|
14909
|
+
if (offset + length > storage2.length) throw new RangeError("Float32Array#set source is out of bounds.");
|
|
14910
|
+
if (isFloat32Array(source)) Float32Array.prototype.set.call(receiver, source, offset);
|
|
14911
|
+
else for (let index = 0; index < length; index++) {
|
|
14912
|
+
budget.visitNode();
|
|
14913
|
+
current = await bridge.getProperty(sourceObject, String(index));
|
|
14914
|
+
receiver[offset + index] = await sandboxNumber(current, budget, bridge);
|
|
14915
|
+
}
|
|
14916
|
+
return void 0;
|
|
14917
|
+
} finally {
|
|
14918
|
+
release();
|
|
14919
|
+
}
|
|
14920
|
+
})();
|
|
14563
14921
|
}
|
|
14564
|
-
|
|
14565
|
-
|
|
14566
|
-
|
|
14567
|
-
|
|
14568
|
-
|
|
14569
|
-
|
|
14570
|
-
|
|
14571
|
-
|
|
14572
|
-
|
|
14573
|
-
|
|
14574
|
-
|
|
14922
|
+
return (async () => {
|
|
14923
|
+
const release = retainValues(budget, () => [receiver, ...args]);
|
|
14924
|
+
try {
|
|
14925
|
+
const start = relativeIndex(await sandboxNumber(args[0], budget, bridge), storage2.length);
|
|
14926
|
+
const end = args[1] === void 0 ? storage2.length : relativeIndex(await sandboxNumber(args[1], budget, bridge), storage2.length);
|
|
14927
|
+
const length = Math.max(end - start, 0);
|
|
14928
|
+
if (key === "subarray")
|
|
14929
|
+
return new Float32Array(storage2.buffer, storage2.byteOffset + start * 4, length);
|
|
14930
|
+
checkFloat32Allocation(length, budget);
|
|
14931
|
+
const result = new Float32Array(length);
|
|
14932
|
+
new Uint8Array(result.buffer).set(
|
|
14933
|
+
new Uint8Array(storage2.buffer, storage2.byteOffset + start * 4, length * 4)
|
|
14934
|
+
);
|
|
14935
|
+
return result;
|
|
14936
|
+
} finally {
|
|
14937
|
+
release();
|
|
14938
|
+
}
|
|
14939
|
+
})();
|
|
14575
14940
|
}
|
|
14576
14941
|
});
|
|
14577
14942
|
}
|
|
14578
|
-
function setFloat32Member(value, property, entry) {
|
|
14579
|
-
const key = String(property);
|
|
14580
|
-
if (isFloat32Index(key)) {
|
|
14943
|
+
function setFloat32Member(value, property, entry, budget) {
|
|
14944
|
+
const key = typeof property === "symbol" ? property : String(property);
|
|
14945
|
+
if (typeof key !== "symbol" && isFloat32Index(key)) {
|
|
14581
14946
|
Reflect.set(value, key, float32Number(entry));
|
|
14582
14947
|
return;
|
|
14583
14948
|
}
|
|
14584
14949
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
14585
|
-
|
|
14586
|
-
|
|
14587
|
-
|
|
14588
|
-
|
|
14950
|
+
const inherited = descriptor ?? (budget === void 0 ? void 0 : getSandboxPropertyDescriptor(value, key, budget));
|
|
14951
|
+
if (descriptor === void 0 && typeof key === "string" && (budget === void 0 || !float32Prototypes.has(budget)) && ["length", "byteLength", "byteOffset", "buffer", "BYTES_PER_ELEMENT"].includes(key))
|
|
14952
|
+
throw new TypeError(`Cannot assign to read only property '${String(key)}'.`);
|
|
14953
|
+
if (inherited !== void 0 && (!("value" in inherited) || !inherited.writable))
|
|
14954
|
+
throw new TypeError(`Cannot assign to read only property '${String(key)}'.`);
|
|
14589
14955
|
Object.defineProperty(
|
|
14590
14956
|
value,
|
|
14591
14957
|
key,
|
|
14592
14958
|
descriptor === void 0 ? { value: entry, configurable: true, enumerable: true, writable: true } : { value: entry }
|
|
14593
14959
|
);
|
|
14594
14960
|
}
|
|
14595
|
-
function relativeIndex(
|
|
14596
|
-
if (value === void 0) return fallback;
|
|
14597
|
-
const numeric = float32Number(value);
|
|
14961
|
+
function relativeIndex(numeric, length) {
|
|
14598
14962
|
const integer2 = Number.isNaN(numeric) ? 0 : Math.trunc(numeric);
|
|
14599
14963
|
return integer2 < 0 ? Math.max(length + integer2, 0) : Math.min(integer2, length);
|
|
14600
14964
|
}
|
|
@@ -14613,7 +14977,7 @@ var errorNames = [
|
|
|
14613
14977
|
];
|
|
14614
14978
|
function createErrorGlobals(options) {
|
|
14615
14979
|
return Object.fromEntries(
|
|
14616
|
-
errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
|
|
14980
|
+
errorNames.map((name) => [name, createErrorConstructor(name, options.budget, options.errorPrototypes === true)])
|
|
14617
14981
|
);
|
|
14618
14982
|
}
|
|
14619
14983
|
function isSandboxErrorConstructorInstance2(value, constructor) {
|
|
@@ -14626,12 +14990,100 @@ function isSandboxErrorConstructorInstance2(value, constructor) {
|
|
|
14626
14990
|
}
|
|
14627
14991
|
return isSandboxErrorConstructorInstance(value, name);
|
|
14628
14992
|
}
|
|
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 });
|
|
14993
|
+
function createErrorConstructor(name, budget, guest) {
|
|
14994
|
+
const call = (args, context) => errorPrototypes.has(budget) ? createNativeError(name, args, budget, context, closure) : createSubsetError(name, args, context?.stack ?? [], budget);
|
|
14995
|
+
const closure = createSandboxClosure({ guest, sandbox: true, call, construct: call, name, length: name === "AggregateError" ? 2 : 1 });
|
|
14632
14996
|
errorConstructorNames.set(closure, name);
|
|
14633
14997
|
return closure;
|
|
14634
14998
|
}
|
|
14999
|
+
function createErrorPrototypes(budget, constructors2) {
|
|
15000
|
+
const prototypes2 = /* @__PURE__ */ new Map();
|
|
15001
|
+
for (const name of errorNames) prototypes2.set(name, /* @__PURE__ */ Object.create(null));
|
|
15002
|
+
errorPrototypes.set(budget, prototypes2);
|
|
15003
|
+
for (const name of errorNames) {
|
|
15004
|
+
const constructor = constructors2[name];
|
|
15005
|
+
const prototype = prototypes2.get(name);
|
|
15006
|
+
Object.defineProperties(prototype, {
|
|
15007
|
+
name: { value: name, writable: true, configurable: true },
|
|
15008
|
+
message: { value: "", writable: true, configurable: true },
|
|
15009
|
+
constructor: { value: constructor, writable: true, configurable: true }
|
|
15010
|
+
});
|
|
15011
|
+
Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
|
|
15012
|
+
setSandboxPrototype(prototype, name === "Error" ? getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget) : prototypes2.get("Error"));
|
|
15013
|
+
if (name !== "Error") setSandboxPrototype(constructor, constructors2.Error);
|
|
15014
|
+
}
|
|
15015
|
+
Object.defineProperty(prototypes2.get("Error"), "toString", {
|
|
15016
|
+
writable: true,
|
|
15017
|
+
configurable: true,
|
|
15018
|
+
value: createSandboxClosure({
|
|
15019
|
+
guest: true,
|
|
15020
|
+
sandbox: true,
|
|
15021
|
+
name: "toString",
|
|
15022
|
+
length: 0,
|
|
15023
|
+
call: async (_args, context) => {
|
|
15024
|
+
const receiver = context?.thisValue;
|
|
15025
|
+
if (receiver === null || typeof receiver !== "object") throw new TypeError("Error.prototype.toString requires an object.");
|
|
15026
|
+
let name;
|
|
15027
|
+
const release = retainValues(budget, () => [receiver, name]);
|
|
15028
|
+
try {
|
|
15029
|
+
const rawName = await readErrorProperty(receiver, "name", budget, context);
|
|
15030
|
+
name = rawName === void 0 ? "Error" : await sandboxString(rawName, budget, context);
|
|
15031
|
+
const rawMessage = await readErrorProperty(receiver, "message", budget, context);
|
|
15032
|
+
const message = rawMessage === void 0 ? "" : await sandboxString(rawMessage, budget, context);
|
|
15033
|
+
return budget.allocateString(name === "" ? message : message === "" ? name : `${name}: ${message}`);
|
|
15034
|
+
} finally {
|
|
15035
|
+
release();
|
|
15036
|
+
}
|
|
15037
|
+
}
|
|
15038
|
+
})
|
|
15039
|
+
});
|
|
15040
|
+
registerBuiltinIdentities(budget, Object.fromEntries(errorNames.map((name) => [name, constructors2[name]])));
|
|
15041
|
+
for (const name of errorNames) {
|
|
15042
|
+
registerIntrinsicFunction(budget, constructors2[name]);
|
|
15043
|
+
registerIntrinsicObject(budget, prototypes2.get(name));
|
|
15044
|
+
}
|
|
15045
|
+
}
|
|
15046
|
+
async function readErrorProperty(value, key, budget, context) {
|
|
15047
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key);
|
|
15048
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
15049
|
+
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
|
|
15050
|
+
}
|
|
15051
|
+
async function createNativeError(name, args, budget, context, constructor) {
|
|
15052
|
+
const newTarget = context?.newTarget ?? constructor;
|
|
15053
|
+
const candidate = await readErrorProperty(newTarget, "prototype", budget, context);
|
|
15054
|
+
const prototype = candidate !== null && typeof candidate === "object" ? candidate : errorPrototypes.get(budget).get(name);
|
|
15055
|
+
let error;
|
|
15056
|
+
let iterator;
|
|
15057
|
+
const errors = [];
|
|
15058
|
+
const release = retainValues(budget, () => [prototype, error, iterator?.retainedValue, ...errors, ...args]);
|
|
15059
|
+
try {
|
|
15060
|
+
const message = name === "AggregateError" ? args[1] : args[0];
|
|
15061
|
+
const options = name === "AggregateError" ? args[2] : args[1];
|
|
15062
|
+
const text = message === void 0 ? void 0 : await sandboxString(message, budget, context);
|
|
15063
|
+
error = createSubsetErrorValue(name, text, context?.stack ?? [], budget);
|
|
15064
|
+
setSandboxPrototype(error, prototype, budget);
|
|
15065
|
+
if (options !== null && typeof options === "object" && getSandboxPropertyDescriptor(options, "cause", budget) !== void 0) {
|
|
15066
|
+
const cause = await readErrorProperty(options, "cause", budget, context);
|
|
15067
|
+
Object.defineProperty(error, "cause", { value: cause, writable: true, configurable: true });
|
|
15068
|
+
}
|
|
15069
|
+
if (name === "AggregateError") {
|
|
15070
|
+
iterator = context === void 0 ? getSandboxIterator(args[0], budget) : await acquireSandboxIterator(args[0], budget, context);
|
|
15071
|
+
if (iterator === void 0) throw new TypeError("AggregateError errors must be iterable.");
|
|
15072
|
+
while (true) {
|
|
15073
|
+
budget.visitNode();
|
|
15074
|
+
const result = await iterator.next();
|
|
15075
|
+
if (result === null || typeof result !== "object") throw new TypeError("Iterator result must be an object.");
|
|
15076
|
+
if ((await readIteratorResult(iterator, result, "done")).value) break;
|
|
15077
|
+
budget.allocateArrayLength(errors.length + 1);
|
|
15078
|
+
errors.push((await readIteratorResult(iterator, result, "value")).value);
|
|
15079
|
+
}
|
|
15080
|
+
Object.defineProperty(error, "errors", { value: errors, writable: true, configurable: true });
|
|
15081
|
+
}
|
|
15082
|
+
return error;
|
|
15083
|
+
} finally {
|
|
15084
|
+
release();
|
|
15085
|
+
}
|
|
15086
|
+
}
|
|
14635
15087
|
function createSubsetError(name, args, stackFrames, budget) {
|
|
14636
15088
|
const message = name === "AggregateError" ? args[1] : args[0];
|
|
14637
15089
|
const options = name === "AggregateError" ? args[2] : args[1];
|
|
@@ -14669,8 +15121,8 @@ async function ordinaryHasInstance(value, constructor, budget, context) {
|
|
|
14669
15121
|
budget.visitNode();
|
|
14670
15122
|
return evaluateInstanceof(value, constructor.boundTarget, budget, context);
|
|
14671
15123
|
}
|
|
14672
|
-
if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
|
|
14673
|
-
if (isSandboxErrorConstructorInstance2(value, constructor)) return true;
|
|
15124
|
+
if (isFloat32ArrayConstructor(constructor) && !isGuestClosure(constructor)) return isFloat32Array(value);
|
|
15125
|
+
if ((!isGuestClosure(constructor) || value !== null && typeof value === "object" && !hasExplicitSandboxPrototype(value)) && isSandboxErrorConstructorInstance2(value, constructor)) return true;
|
|
14674
15126
|
if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
|
|
14675
15127
|
const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
|
|
14676
15128
|
if (typeof prototype !== "object" || prototype === null)
|
|
@@ -17309,7 +17761,7 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
17309
17761
|
if (isFloat32Array(member.object)) {
|
|
17310
17762
|
return evaluateResolvedCallExpression(
|
|
17311
17763
|
node,
|
|
17312
|
-
|
|
17764
|
+
await getPropertyValue(member.object, member.property, context),
|
|
17313
17765
|
context,
|
|
17314
17766
|
member.object
|
|
17315
17767
|
);
|
|
@@ -17846,8 +18298,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
|
|
|
17846
18298
|
if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
|
|
17847
18299
|
if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
|
|
17848
18300
|
if (isFloat32Array(target)) {
|
|
17849
|
-
|
|
17850
|
-
setFloat32Member(target, property, value);
|
|
18301
|
+
setFloat32Member(target, property, value, budget);
|
|
17851
18302
|
return;
|
|
17852
18303
|
}
|
|
17853
18304
|
if (isSandboxRegex(target)) {
|
|
@@ -18869,11 +19320,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18869
19320
|
throw reason;
|
|
18870
19321
|
}
|
|
18871
19322
|
if (isSubsetErrorValue(reason)) {
|
|
18872
|
-
normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
|
|
18873
|
-
return reason;
|
|
19323
|
+
return normalizeSurfacedSubsetError(reason, budget, stackFrames, span);
|
|
18874
19324
|
}
|
|
18875
19325
|
if (reason instanceof Error) {
|
|
18876
|
-
const
|
|
19326
|
+
const error2 = createSubsetErrorValue(
|
|
18877
19327
|
reason.name || "Error",
|
|
18878
19328
|
reason.message,
|
|
18879
19329
|
stackFrames,
|
|
@@ -18884,11 +19334,10 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18884
19334
|
span
|
|
18885
19335
|
}
|
|
18886
19336
|
);
|
|
18887
|
-
normalizeSurfacedSubsetError(
|
|
18888
|
-
return error;
|
|
19337
|
+
return normalizeSurfacedSubsetError(error2, budget, stackFrames, span);
|
|
18889
19338
|
}
|
|
18890
19339
|
if (isErrorLikeValue(reason)) {
|
|
18891
|
-
const
|
|
19340
|
+
const error2 = createSubsetErrorValue(
|
|
18892
19341
|
reason.name || "Error",
|
|
18893
19342
|
reason.message,
|
|
18894
19343
|
stackFrames,
|
|
@@ -18899,13 +19348,13 @@ function surfaceThrownValue(reason, budget, stackFrames = [], span) {
|
|
|
18899
19348
|
span
|
|
18900
19349
|
}
|
|
18901
19350
|
);
|
|
18902
|
-
normalizeSurfacedSubsetError(
|
|
18903
|
-
return error;
|
|
19351
|
+
return normalizeSurfacedSubsetError(error2, budget, stackFrames, span);
|
|
18904
19352
|
}
|
|
18905
|
-
|
|
19353
|
+
const error = createSubsetErrorValue("Error", describeThrownValue(reason), stackFrames, budget, {
|
|
18906
19354
|
chargeBudget: false,
|
|
18907
19355
|
span
|
|
18908
19356
|
});
|
|
19357
|
+
return normalizeSurfacedSubsetError(error, budget, stackFrames, span);
|
|
18909
19358
|
}
|
|
18910
19359
|
function createSubsetErrorValue(name, message, stackFrames, budget, options = {}) {
|
|
18911
19360
|
const resumeChecks = options.chargeBudget === false ? budget.suspendChecks() : void 0;
|
|
@@ -18914,11 +19363,15 @@ function createSubsetErrorValue(name, message, stackFrames, budget, options = {}
|
|
|
18914
19363
|
const errorMessage = budget.allocateString(coerceErrorMessage(message));
|
|
18915
19364
|
const header = errorMessage === "" ? errorName : `${errorName}: ${errorMessage}`;
|
|
18916
19365
|
const stack = budget.allocateString([header, ...[...stackFrames].reverse()].join("\n"));
|
|
18917
|
-
const
|
|
18918
|
-
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
|
|
19366
|
+
const prototype = options.transport ? void 0 : errorPrototypes.get(budget)?.get(toSandboxErrorName(errorName));
|
|
19367
|
+
const error = prototype === void 0 ? { name: errorName, message: errorMessage, stack } : {};
|
|
19368
|
+
if (prototype !== void 0) {
|
|
19369
|
+
if (message !== void 0) Object.defineProperty(error, "message", { value: errorMessage, writable: true, configurable: true });
|
|
19370
|
+
if (!errorPrototypes.get(budget).has(errorName))
|
|
19371
|
+
Object.defineProperty(error, "name", { value: errorName, writable: true, configurable: true });
|
|
19372
|
+
Object.defineProperty(error, "stack", { value: stack, writable: true, configurable: true });
|
|
19373
|
+
setSandboxPrototype(error, prototype, budget);
|
|
19374
|
+
}
|
|
18922
19375
|
sandboxErrorTypes.set(error, toSandboxErrorName(errorName));
|
|
18923
19376
|
attachErrorSpan(error, options.span);
|
|
18924
19377
|
attachWrappedErrorCause(error, options.cause);
|
|
@@ -18939,6 +19392,7 @@ function isSubsetErrorValue(value) {
|
|
|
18939
19392
|
if (typeof value !== "object" || value === null) {
|
|
18940
19393
|
return false;
|
|
18941
19394
|
}
|
|
19395
|
+
if (sandboxErrorTypes.has(value)) return true;
|
|
18942
19396
|
const prototype = Object.getPrototypeOf(value);
|
|
18943
19397
|
return (prototype === Object.prototype || prototype === null) && typeof value.name === "string" && typeof value.message === "string" && typeof value.stack === "string";
|
|
18944
19398
|
}
|
|
@@ -18948,21 +19402,37 @@ function normalizeSurfacedSubsetError(error, budget, stackFrames, span) {
|
|
|
18948
19402
|
const name = budget.allocateString(toSandboxErrorName(readErrorName(error)));
|
|
18949
19403
|
const message = budget.allocateString(readSurfacedErrorMessage(error, name));
|
|
18950
19404
|
const frames = readSandboxStackFrames(error.stack);
|
|
19405
|
+
if (!Object.isExtensible(error) || ["name", "message", "stack"].some((key) => {
|
|
19406
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, key);
|
|
19407
|
+
return descriptor !== void 0 && (!("value" in descriptor) || !descriptor.writable);
|
|
19408
|
+
})) {
|
|
19409
|
+
const original = error;
|
|
19410
|
+
const descriptors2 = Object.getOwnPropertyDescriptors(original);
|
|
19411
|
+
delete descriptors2.name;
|
|
19412
|
+
delete descriptors2.message;
|
|
19413
|
+
delete descriptors2.stack;
|
|
19414
|
+
error = Object.defineProperties({}, descriptors2);
|
|
19415
|
+
const errorType = sandboxErrorTypes.get(original);
|
|
19416
|
+
if (errorType !== void 0) sandboxErrorTypes.set(error, errorType);
|
|
19417
|
+
}
|
|
18951
19418
|
error.name = name;
|
|
18952
19419
|
error.message = message;
|
|
18953
19420
|
error.stack = budget.allocateString(
|
|
18954
19421
|
formatErrorStack(name, message, frames.length > 0 ? frames : [...stackFrames].reverse())
|
|
18955
19422
|
);
|
|
18956
19423
|
attachErrorSpan(error, readErrorSpan(error) ?? span);
|
|
19424
|
+
return error;
|
|
18957
19425
|
} finally {
|
|
18958
19426
|
resumeChecks();
|
|
18959
19427
|
}
|
|
18960
19428
|
}
|
|
18961
19429
|
function readErrorName(error) {
|
|
18962
|
-
|
|
19430
|
+
const name = getSandboxDataProperty(error, "name");
|
|
19431
|
+
return typeof name === "string" && name.length > 0 ? name : sandboxErrorTypes.get(error) ?? "Error";
|
|
18963
19432
|
}
|
|
18964
19433
|
function readSurfacedErrorMessage(error, name) {
|
|
18965
|
-
const
|
|
19434
|
+
const value = getSandboxDataProperty(error, "message");
|
|
19435
|
+
const message = typeof value === "string" ? value : "";
|
|
18966
19436
|
if (message === "") {
|
|
18967
19437
|
return `${name} thrown`;
|
|
18968
19438
|
}
|
|
@@ -20472,8 +20942,14 @@ function captureGuestHeapNode(value, encode) {
|
|
|
20472
20942
|
}
|
|
20473
20943
|
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
20944
|
const prototype = Object.getPrototypeOf(value);
|
|
20475
|
-
if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value))
|
|
20476
|
-
|
|
20945
|
+
if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value)) {
|
|
20946
|
+
const errorType = sandboxErrorTypes.get(value);
|
|
20947
|
+
return {
|
|
20948
|
+
kind: "guest-object",
|
|
20949
|
+
state: captureObjectState(value, encode),
|
|
20950
|
+
...errorType === void 0 ? {} : { errorType }
|
|
20951
|
+
};
|
|
20952
|
+
}
|
|
20477
20953
|
return void 0;
|
|
20478
20954
|
}
|
|
20479
20955
|
if (origin.node.nodeId === void 0) throw new TypeError("Guest closures require an AST node identity.");
|
|
@@ -22065,9 +22541,11 @@ function createHostErrorValue(reason, stackFrames, budget, span, state = { seen:
|
|
|
22065
22541
|
}
|
|
22066
22542
|
const error = reason instanceof Error ? createSubsetErrorValue(reason.name, reason.message, stackFrames, budget, {
|
|
22067
22543
|
cause: reason,
|
|
22068
|
-
chargeBudget
|
|
22544
|
+
chargeBudget,
|
|
22545
|
+
transport: true
|
|
22069
22546
|
}) : createSubsetErrorValue("Error", describeThrownReason(reason), stackFrames, budget, {
|
|
22070
|
-
chargeBudget: false
|
|
22547
|
+
chargeBudget: false,
|
|
22548
|
+
transport: true
|
|
22071
22549
|
});
|
|
22072
22550
|
if (reason instanceof Error) {
|
|
22073
22551
|
state.seen.set(reason, error);
|
|
@@ -24394,11 +24872,11 @@ function createBuiltinBindings(options) {
|
|
|
24394
24872
|
const bindings = {
|
|
24395
24873
|
...createConsoleJsonGlobals(options),
|
|
24396
24874
|
...createCollectionGlobals(options),
|
|
24397
|
-
Float32Array: createFloat32ArrayGlobal(options.budget),
|
|
24875
|
+
Float32Array: createFloat32ArrayGlobal(options.budget, options.float32Prototypes !== false),
|
|
24398
24876
|
Date: createDateGlobal(options),
|
|
24399
24877
|
Symbol: createSymbolGlobal(options.budget),
|
|
24400
24878
|
BigInt: createBigIntGlobal(options.budget),
|
|
24401
|
-
...createErrorGlobals(options),
|
|
24879
|
+
...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
|
|
24402
24880
|
...createMathGlobals({ random: options.random, budget: options.budget }),
|
|
24403
24881
|
...createObjectArrayGlobals(options),
|
|
24404
24882
|
...createMiscGlobals(options),
|
|
@@ -24407,6 +24885,8 @@ function createBuiltinBindings(options) {
|
|
|
24407
24885
|
...createRegexGlobals(options)
|
|
24408
24886
|
};
|
|
24409
24887
|
createFunctionPrototype(options.budget, options.functionHasInstance);
|
|
24888
|
+
if (options.float32Prototypes !== false) createFloat32ArrayPrototypes(options.budget, bindings.Float32Array);
|
|
24889
|
+
if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
|
|
24410
24890
|
createGeneratorPrototypes(options.budget);
|
|
24411
24891
|
registerBuiltinIdentities(options.budget, bindings);
|
|
24412
24892
|
return bindings;
|
|
@@ -24526,7 +25006,9 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24526
25006
|
}
|
|
24527
25007
|
state(node.state);
|
|
24528
25008
|
} else if (node.kind === "guest-object" || node.kind === "guest-array") {
|
|
24529
|
-
fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : []);
|
|
25009
|
+
fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : ["errorType"]);
|
|
25010
|
+
if (Object.hasOwn(node, "errorType") && !sandboxErrorNames.includes(node.errorType))
|
|
25011
|
+
throw new TypeError("Invalid guest error type.");
|
|
24530
25012
|
if (Object.hasOwn(node, "templateOwner")) reference(node.templateOwner, ["guest-array"]);
|
|
24531
25013
|
if (Object.hasOwn(node, "templateNodeId") && integer(node.templateNodeId) < 1)
|
|
24532
25014
|
throw new TypeError("Invalid template source identity.");
|
|
@@ -25136,6 +25618,10 @@ function validateDumpHeap(root, state) {
|
|
|
25136
25618
|
if (entry.kind === "float32array") {
|
|
25137
25619
|
validateFloat32Storage(entry);
|
|
25138
25620
|
requireRecord(entry.entries, `${path}.entries`);
|
|
25621
|
+
if (Object.hasOwn(entry, "state")) {
|
|
25622
|
+
if (Object.keys(entry.entries).length !== 0) fail("invalidValue", path, "ambiguous Float32Array property state");
|
|
25623
|
+
validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
|
|
25624
|
+
}
|
|
25139
25625
|
continue;
|
|
25140
25626
|
}
|
|
25141
25627
|
if (entry.kind === "arguments") {
|
|
@@ -25364,6 +25850,10 @@ function validateHeapValue(value, path, state, heap) {
|
|
|
25364
25850
|
if (record4.kind === "float32array") {
|
|
25365
25851
|
validateFloat32Storage(record4);
|
|
25366
25852
|
requireRecord(record4.entries, `${path}.entries`);
|
|
25853
|
+
if (Object.hasOwn(record4, "state")) {
|
|
25854
|
+
if (Object.keys(record4.entries).length !== 0) fail("invalidValue", path, "ambiguous Float32Array property state");
|
|
25855
|
+
validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
|
|
25856
|
+
}
|
|
25367
25857
|
}
|
|
25368
25858
|
if (record4.kind === "map") {
|
|
25369
25859
|
const entries = requireArray(record4.entries, `${path}.entries`, state);
|
|
@@ -25496,7 +25986,7 @@ function validateArrayHeap(record4, path, state) {
|
|
|
25496
25986
|
}
|
|
25497
25987
|
function validateErrorType(record4, path) {
|
|
25498
25988
|
if (!Object.hasOwn(record4, "errorType")) return;
|
|
25499
|
-
if (record4.kind !== "object" || !sandboxErrorNames.includes(record4.errorType)) {
|
|
25989
|
+
if (record4.kind !== "object" && record4.kind !== "guest-object" || !sandboxErrorNames.includes(record4.errorType)) {
|
|
25500
25990
|
fail("invalidValue", `${path}.errorType`, "invalid error metadata");
|
|
25501
25991
|
}
|
|
25502
25992
|
}
|
|
@@ -26358,9 +26848,12 @@ function measureSandboxData(values, options = {}) {
|
|
|
26358
26848
|
seen.add(storage.buffer);
|
|
26359
26849
|
usage += storage.byteLength;
|
|
26360
26850
|
}
|
|
26361
|
-
for (const [key, descriptor] of
|
|
26362
|
-
usage +=
|
|
26363
|
-
|
|
26851
|
+
for (const [key, descriptor] of float32Properties(value)) {
|
|
26852
|
+
usage += 1;
|
|
26853
|
+
if (typeof key === "string") usage += key.length;
|
|
26854
|
+
else visit(key, depth + 1);
|
|
26855
|
+
if ("value" in descriptor) visit(descriptor.value, depth + 1);
|
|
26856
|
+
else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
|
|
26364
26857
|
}
|
|
26365
26858
|
return;
|
|
26366
26859
|
}
|
|
@@ -26493,7 +26986,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
26493
26986
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
26494
26987
|
if (descriptor !== void 0) descriptors2.push([key, descriptor]);
|
|
26495
26988
|
}
|
|
26496
|
-
const includeNonEnumerable = isSandboxDate(value) || hasManagedDescriptors(value);
|
|
26989
|
+
const includeNonEnumerable = isSandboxDate(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
|
|
26497
26990
|
for (const [key, descriptor] of descriptors2) {
|
|
26498
26991
|
if (!descriptor.enumerable && !includeNonEnumerable) continue;
|
|
26499
26992
|
usage += 1 + key.length;
|
|
@@ -26826,6 +27319,53 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
|
|
|
26826
27319
|
return options.unwrapHostObject(value);
|
|
26827
27320
|
}
|
|
26828
27321
|
if (nodeTypes.isProxy(value)) throw new TypeError("Unsupported proxy sandbox value.");
|
|
27322
|
+
if (sandboxErrorTypes.has(value) && hasExplicitSandboxPrototype(value)) {
|
|
27323
|
+
const prototype = getSandboxPrototype(value);
|
|
27324
|
+
let nativePrototype = null;
|
|
27325
|
+
if (prototype !== null) {
|
|
27326
|
+
const identity = getIntrinsicIdentity(prototype);
|
|
27327
|
+
const nativePrototypes = {
|
|
27328
|
+
Error: Error.prototype,
|
|
27329
|
+
TypeError: TypeError.prototype,
|
|
27330
|
+
RangeError: RangeError.prototype,
|
|
27331
|
+
ReferenceError: ReferenceError.prototype,
|
|
27332
|
+
SyntaxError: SyntaxError.prototype,
|
|
27333
|
+
URIError: URIError.prototype,
|
|
27334
|
+
EvalError: EvalError.prototype,
|
|
27335
|
+
AggregateError: AggregateError.prototype
|
|
27336
|
+
};
|
|
27337
|
+
const path2 = identity === void 0 ? [] : JSON.parse(identity);
|
|
27338
|
+
if (path2.length !== 2 || typeof path2[0] !== "string" || path2[1] !== "prototype" || !Object.hasOwn(nativePrototypes, path2[0]))
|
|
27339
|
+
throw new TypeError("Custom Error prototype links cannot be copied as data.");
|
|
27340
|
+
nativePrototype = nativePrototypes[path2[0]];
|
|
27341
|
+
let current = prototype;
|
|
27342
|
+
let prototypeDepth = 0;
|
|
27343
|
+
while (current !== null) {
|
|
27344
|
+
assertSandboxDataDepth(++prototypeDepth);
|
|
27345
|
+
const objectPrototype = getIntrinsicIdentity(current) === '["Object","prototype"]';
|
|
27346
|
+
const owner = objectPrototype ? Object.getOwnPropertyDescriptor(current, "constructor")?.value : current;
|
|
27347
|
+
if (owner === null || typeof owner !== "object" || objectPrototype && getIntrinsicIdentity(owner) !== '["Object"]' || hasGuestObjectState(owner))
|
|
27348
|
+
throw new TypeError("Modified Error prototype links cannot be copied as data.");
|
|
27349
|
+
current = getSandboxPrototype(current);
|
|
27350
|
+
}
|
|
27351
|
+
}
|
|
27352
|
+
const existing = state.seen.get(value);
|
|
27353
|
+
if (existing !== void 0) return existing;
|
|
27354
|
+
const descriptors2 = Reflect.ownKeys(value).filter((key) => typeof key !== "symbol" || !internalSymbols.has(key)).map((key) => [key, Object.getOwnPropertyDescriptor(value, key)]);
|
|
27355
|
+
if (descriptors2.some(([, descriptor]) => !("value" in descriptor)))
|
|
27356
|
+
throw new TypeError("Error accessor properties cannot be copied as data.");
|
|
27357
|
+
const copy = new Error();
|
|
27358
|
+
delete copy.stack;
|
|
27359
|
+
Object.setPrototypeOf(copy, nativePrototype);
|
|
27360
|
+
state.seen.set(value, copy);
|
|
27361
|
+
for (const [key, descriptor] of descriptors2)
|
|
27362
|
+
Object.defineProperty(copy, key, {
|
|
27363
|
+
...descriptor,
|
|
27364
|
+
value: copyFromSandbox(descriptor.value, state, joinPath2(path, key), options, depth + 1)
|
|
27365
|
+
});
|
|
27366
|
+
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
27367
|
+
return copy;
|
|
27368
|
+
}
|
|
26829
27369
|
if (!isSandboxClosure(value) && hasGuestObjectState(value)) {
|
|
26830
27370
|
throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
|
|
26831
27371
|
}
|
|
@@ -41274,4 +41814,4 @@ export {
|
|
|
41274
41814
|
FileSnapshotBackend,
|
|
41275
41815
|
run
|
|
41276
41816
|
};
|
|
41277
|
-
//# sourceMappingURL=chunk-
|
|
41817
|
+
//# sourceMappingURL=chunk-PT7PBLVT.js.map
|