poe-code 14.0.75 → 14.0.76
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 +357 -60
- 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-EOTY4PCT.js → chunk-UZYQWFMY.js} +333 -60
- package/packages/safe-js/dist/chunks/chunk-UZYQWFMY.js.map +7 -0
- package/packages/safe-js/dist/chunks/{chunk-BAJI3K4B.js → chunk-VD2AS4E4.js} +2 -2
- 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/index.js.map +1 -1
- package/packages/safe-js/dist/interp/bigint-operators.d.ts +3 -0
- package/packages/safe-js/dist/interp/bigint-operators.js +62 -0
- package/packages/safe-js/dist/interp/boxed.d.ts +2 -2
- package/packages/safe-js/dist/interp/boxed.js +4 -1
- package/packages/safe-js/dist/interp/globals/bigint.d.ts +2 -0
- package/packages/safe-js/dist/interp/globals/bigint.js +85 -0
- package/packages/safe-js/dist/interp/globals/console-json.js +57 -24
- package/packages/safe-js/dist/interp/globals/object-array.js +1 -1
- package/packages/safe-js/dist/interp/globals.d.ts +1 -0
- package/packages/safe-js/dist/interp/globals.js +2 -0
- package/packages/safe-js/dist/interp/host-bridge.js +2 -0
- package/packages/safe-js/dist/interp/interpreter.js +59 -12
- package/packages/safe-js/dist/interp/methods/number.js +1 -1
- package/packages/safe-js/dist/interp/methods/string.js +2 -2
- package/packages/safe-js/dist/interp/string-coercion.d.ts +1 -1
- package/packages/safe-js/dist/interp/string-coercion.js +8 -3
- package/packages/safe-js/dist/interp/values.d.ts +1 -1
- package/packages/safe-js/dist/interp/values.js +5 -0
- package/packages/safe-js/dist/lint/rules/AS-async-not-needed.js +2 -0
- package/packages/safe-js/dist/lint/rules/AS-missing-async.js +2 -0
- package/packages/safe-js/dist/lint/rules/known-globals.d.ts +1 -1
- package/packages/safe-js/dist/lint/rules/known-globals.js +1 -0
- package/packages/safe-js/dist/parse/parser.d.ts +6 -1
- package/packages/safe-js/dist/parse/parser.js +8 -0
- package/packages/safe-js/dist/parse/tokenizer.js +12 -4
- package/packages/safe-js/dist/parse.d.ts +1 -1
- package/packages/safe-js/dist/snapshot/bigint.d.ts +1 -0
- package/packages/safe-js/dist/snapshot/bigint.js +14 -0
- package/packages/safe-js/dist/snapshot/dump-format.js +2 -0
- package/packages/safe-js/dist/snapshot/replay-data.d.ts +3 -0
- package/packages/safe-js/dist/snapshot/replay-data.js +9 -1
- package/packages/safe-js/dist/snapshot/restore.js +2 -0
- package/packages/safe-js/dist/snapshot/serialize.d.ts +1 -1
- package/packages/safe-js/dist/snapshot/serialize.js +2 -0
- package/packages/safe-js/dist/snapshot/validation.js +19 -0
- package/packages/safe-js/dist/chunks/chunk-EOTY4PCT.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-BAJI3K4B.js.map → chunk-VD2AS4E4.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -120978,7 +120978,7 @@ var init_tokenizer2 = __esm({
|
|
|
120978
120978
|
this.advance();
|
|
120979
120979
|
this.advance();
|
|
120980
120980
|
this.consumeDigitsForBase(isHexDigit, "hexadecimal");
|
|
120981
|
-
this.
|
|
120981
|
+
if (this.currentChar() === "n") this.advance();
|
|
120982
120982
|
this.rejectInvalidNumericLiteralContinuation();
|
|
120983
120983
|
return this.source.slice(start.offset, this.index);
|
|
120984
120984
|
}
|
|
@@ -120986,7 +120986,7 @@ var init_tokenizer2 = __esm({
|
|
|
120986
120986
|
this.advance();
|
|
120987
120987
|
this.advance();
|
|
120988
120988
|
this.consumeDigitsForBase(isBinaryDigit, "binary");
|
|
120989
|
-
this.
|
|
120989
|
+
if (this.currentChar() === "n") this.advance();
|
|
120990
120990
|
this.rejectInvalidNumericLiteralContinuation();
|
|
120991
120991
|
return this.source.slice(start.offset, this.index);
|
|
120992
120992
|
}
|
|
@@ -120994,7 +120994,7 @@ var init_tokenizer2 = __esm({
|
|
|
120994
120994
|
this.advance();
|
|
120995
120995
|
this.advance();
|
|
120996
120996
|
this.consumeDigitsForBase(isOctalDigit, "octal");
|
|
120997
|
-
this.
|
|
120997
|
+
if (this.currentChar() === "n") this.advance();
|
|
120998
120998
|
this.rejectInvalidNumericLiteralContinuation();
|
|
120999
120999
|
return this.source.slice(start.offset, this.index);
|
|
121000
121000
|
}
|
|
@@ -121008,6 +121008,11 @@ var init_tokenizer2 = __esm({
|
|
|
121008
121008
|
}
|
|
121009
121009
|
}
|
|
121010
121010
|
this.consumeDecimalDigits();
|
|
121011
|
+
if (this.currentChar() === "n") {
|
|
121012
|
+
this.advance();
|
|
121013
|
+
this.rejectInvalidNumericLiteralContinuation();
|
|
121014
|
+
return this.source.slice(start.offset, this.index);
|
|
121015
|
+
}
|
|
121011
121016
|
if (this.currentChar() === "." && (this.peekChar(1) !== "." || this.peekChar(2) !== ".")) {
|
|
121012
121017
|
this.advance();
|
|
121013
121018
|
this.consumeOptionalDecimalDigits();
|
|
@@ -121106,7 +121111,7 @@ var init_tokenizer2 = __esm({
|
|
|
121106
121111
|
}
|
|
121107
121112
|
rejectBigIntSuffix() {
|
|
121108
121113
|
if (this.currentChar() === "n") {
|
|
121109
|
-
this.syntaxError("BigInt
|
|
121114
|
+
this.syntaxError("BigInt literals cannot contain a fraction or exponent", this.position());
|
|
121110
121115
|
}
|
|
121111
121116
|
}
|
|
121112
121117
|
rejectInvalidNumericLiteralContinuation() {
|
|
@@ -122656,6 +122661,7 @@ function findImportMetaAssignmentInNode(node) {
|
|
|
122656
122661
|
case "BooleanLiteral":
|
|
122657
122662
|
case "NullLiteral":
|
|
122658
122663
|
case "NumericLiteral":
|
|
122664
|
+
case "BigIntLiteral":
|
|
122659
122665
|
case "StringLiteral":
|
|
122660
122666
|
case "ThisExpression":
|
|
122661
122667
|
case "RegexLiteral":
|
|
@@ -122734,6 +122740,12 @@ function isYieldArgumentTerminator(value) {
|
|
|
122734
122740
|
return value === ";" || value === "}" || value === ")" || value === "]" || value === ",";
|
|
122735
122741
|
}
|
|
122736
122742
|
function createNumericLiteral(token) {
|
|
122743
|
+
if (token.value.endsWith("n")) return {
|
|
122744
|
+
type: "BigIntLiteral",
|
|
122745
|
+
raw: token.value,
|
|
122746
|
+
value: token.value.slice(0, -1).replaceAll("_", ""),
|
|
122747
|
+
span: createTokenSpan(token)
|
|
122748
|
+
};
|
|
122737
122749
|
return {
|
|
122738
122750
|
type: "NumericLiteral",
|
|
122739
122751
|
raw: token.value,
|
|
@@ -126319,6 +126331,23 @@ var init_hash = __esm({
|
|
|
126319
126331
|
}
|
|
126320
126332
|
});
|
|
126321
126333
|
|
|
126334
|
+
// packages/safe-js/src/snapshot/bigint.ts
|
|
126335
|
+
function validateBigIntData(value) {
|
|
126336
|
+
if (typeof value !== "string" || value.length === 0) throw new TypeError("Invalid BigInt snapshot value.");
|
|
126337
|
+
if (value === "0") return;
|
|
126338
|
+
const start = value[0] === "-" ? 1 : 0;
|
|
126339
|
+
if (start === value.length || value[start] === "0") throw new TypeError("Invalid BigInt snapshot value.");
|
|
126340
|
+
for (let index = start; index < value.length; index++) {
|
|
126341
|
+
const code = value.charCodeAt(index);
|
|
126342
|
+
if (code < 48 || code > 57) throw new TypeError("Invalid BigInt snapshot value.");
|
|
126343
|
+
}
|
|
126344
|
+
}
|
|
126345
|
+
var init_bigint = __esm({
|
|
126346
|
+
"packages/safe-js/src/snapshot/bigint.ts"() {
|
|
126347
|
+
"use strict";
|
|
126348
|
+
}
|
|
126349
|
+
});
|
|
126350
|
+
|
|
126322
126351
|
// packages/safe-js/src/observability/otel.ts
|
|
126323
126352
|
function bindOtelSpan(value, span) {
|
|
126324
126353
|
spanByAsyncValue.set(value, span);
|
|
@@ -126750,10 +126779,11 @@ function nativeBoxedValue(value) {
|
|
|
126750
126779
|
if (types2.isStringObject(value)) return Reflect.apply(stringValue2, value, []);
|
|
126751
126780
|
if (types2.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
|
|
126752
126781
|
if (types2.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
|
|
126782
|
+
if (types2.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
|
|
126753
126783
|
return void 0;
|
|
126754
126784
|
}
|
|
126755
126785
|
function createSandboxBox(value) {
|
|
126756
|
-
if (typeof value !== "number" && typeof value !== "string" && typeof value !== "boolean" && typeof value !== "symbol")
|
|
126786
|
+
if (typeof value !== "number" && typeof value !== "bigint" && typeof value !== "string" && typeof value !== "boolean" && typeof value !== "symbol")
|
|
126757
126787
|
throw new TypeError("Invalid boxed primitive payload.");
|
|
126758
126788
|
const box = Object(value);
|
|
126759
126789
|
Object.setPrototypeOf(box, null);
|
|
@@ -126784,7 +126814,7 @@ function boxedDataProperties(value, includeSymbols = false) {
|
|
|
126784
126814
|
return !(Number.isInteger(index) && index >= 0 && index < primitive.length && String(index) === key3);
|
|
126785
126815
|
});
|
|
126786
126816
|
}
|
|
126787
|
-
var boxes, numberValue2, stringValue2, booleanValue, symbolValue;
|
|
126817
|
+
var boxes, numberValue2, stringValue2, booleanValue, symbolValue, bigintValue;
|
|
126788
126818
|
var init_boxed = __esm({
|
|
126789
126819
|
"packages/safe-js/src/interp/boxed.ts"() {
|
|
126790
126820
|
"use strict";
|
|
@@ -126793,6 +126823,7 @@ var init_boxed = __esm({
|
|
|
126793
126823
|
stringValue2 = String.prototype.valueOf;
|
|
126794
126824
|
booleanValue = Boolean.prototype.valueOf;
|
|
126795
126825
|
symbolValue = Symbol.prototype.valueOf;
|
|
126826
|
+
bigintValue = BigInt.prototype.valueOf;
|
|
126796
126827
|
}
|
|
126797
126828
|
});
|
|
126798
126829
|
|
|
@@ -128338,6 +128369,7 @@ function encodeReplayData(value, options = {}) {
|
|
|
128338
128369
|
if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
|
|
128339
128370
|
if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
|
|
128340
128371
|
if (entry === void 0) return { tag: "undefined" };
|
|
128372
|
+
if (typeof entry === "bigint") return { tag: "bigint", value: String(entry) };
|
|
128341
128373
|
if (typeof entry === "symbol") {
|
|
128342
128374
|
let id2 = symbols2.get(entry);
|
|
128343
128375
|
if (id2 === void 0) {
|
|
@@ -128540,6 +128572,11 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
128540
128572
|
return capability;
|
|
128541
128573
|
}
|
|
128542
128574
|
if (own(atom, "tag") === "undefined") return void 0;
|
|
128575
|
+
if (own(atom, "tag") === "bigint") {
|
|
128576
|
+
const value = own(atom, "value");
|
|
128577
|
+
validateBigIntData(value);
|
|
128578
|
+
return BigInt(value);
|
|
128579
|
+
}
|
|
128543
128580
|
if (atom.tag === "number") {
|
|
128544
128581
|
switch (own(atom, "value")) {
|
|
128545
128582
|
case "NaN":
|
|
@@ -128609,7 +128646,7 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
128609
128646
|
const payload = own(node, "value");
|
|
128610
128647
|
const payloadRecord = payload !== null && typeof payload === "object" ? record(payload) : void 0;
|
|
128611
128648
|
const symbolReference = payloadRecord !== void 0 && own(payloadRecord, "tag") === "ref" && Number.isSafeInteger(payloadRecord.id) && Number(payloadRecord.id) >= 0 && Number(payloadRecord.id) < nodes.length && own(record(nodes[Number(payloadRecord.id)]), "kind") === "symbol";
|
|
128612
|
-
if (typeof payload !== "number" && typeof payload !== "string" && typeof payload !== "boolean" && !symbolReference && (payload === null || typeof payload !== "object" || own(record(payload), "tag")
|
|
128649
|
+
if (typeof payload !== "number" && typeof payload !== "string" && typeof payload !== "boolean" && !symbolReference && (payload === null || typeof payload !== "object" || !["number", "bigint"].includes(String(own(record(payload), "tag")))))
|
|
128613
128650
|
throw new TypeError("Invalid boxed primitive payload.");
|
|
128614
128651
|
const result3 = createSandboxBox(child(payload));
|
|
128615
128652
|
restored.set(id, result3);
|
|
@@ -128789,6 +128826,7 @@ var init_replay_data = __esm({
|
|
|
128789
128826
|
"packages/safe-js/src/snapshot/replay-data.ts"() {
|
|
128790
128827
|
"use strict";
|
|
128791
128828
|
init_graph_depth();
|
|
128829
|
+
init_bigint();
|
|
128792
128830
|
init_regexp_properties2();
|
|
128793
128831
|
init_symbols2();
|
|
128794
128832
|
init_symbols3();
|
|
@@ -130131,6 +130169,75 @@ var init_engine2 = __esm({
|
|
|
130131
130169
|
}
|
|
130132
130170
|
});
|
|
130133
130171
|
|
|
130172
|
+
// packages/safe-js/src/interp/bigint-operators.ts
|
|
130173
|
+
function bigIntOperation(operator, left, right, budget) {
|
|
130174
|
+
if (operator === ">>>") throw new TypeError("BigInts have no unsigned right shift.");
|
|
130175
|
+
if ((operator === "/" || operator === "%") && right === 0n) throw new RangeError("Division by zero.");
|
|
130176
|
+
if (operator === "**" && right < 0n) throw new RangeError("BigInt exponent must be nonnegative.");
|
|
130177
|
+
const leftSize = left.toString(16).length;
|
|
130178
|
+
const rightSize = right.toString(16).length;
|
|
130179
|
+
budget.visitNode(leftSize + rightSize);
|
|
130180
|
+
let size = Math.max(leftSize, rightSize) + 1;
|
|
130181
|
+
let work = leftSize + rightSize;
|
|
130182
|
+
if (operator === "*") {
|
|
130183
|
+
size = leftSize + rightSize;
|
|
130184
|
+
work = leftSize * rightSize;
|
|
130185
|
+
} else if (operator === "/" || operator === "%") {
|
|
130186
|
+
size = leftSize;
|
|
130187
|
+
work = leftSize * rightSize;
|
|
130188
|
+
} else if (operator === "**") {
|
|
130189
|
+
if (right === 0n) return 1n;
|
|
130190
|
+
if (left === 0n || left === 1n) return left;
|
|
130191
|
+
if (left === -1n) return right % 2n === 0n ? 1n : -1n;
|
|
130192
|
+
size = leftSize * Number(right);
|
|
130193
|
+
work = size * size;
|
|
130194
|
+
} else if (operator === "<<" || operator === ">>") {
|
|
130195
|
+
if (left === 0n) return 0n;
|
|
130196
|
+
const shift = operator === "<<" ? right : -right;
|
|
130197
|
+
size = shift > 0n ? leftSize + Math.ceil(Number(shift) / 4) : leftSize;
|
|
130198
|
+
work = size + rightSize;
|
|
130199
|
+
}
|
|
130200
|
+
if (!Number.isSafeInteger(size) || !Number.isSafeInteger(work))
|
|
130201
|
+
throw new SandboxError({ budget: "dataSize", current: Infinity, limit: Number.MAX_SAFE_INTEGER });
|
|
130202
|
+
budget.visitNode(work);
|
|
130203
|
+
const allocation = {};
|
|
130204
|
+
budget.setRetainedDataUsage(allocation, size);
|
|
130205
|
+
try {
|
|
130206
|
+
switch (operator) {
|
|
130207
|
+
case "+":
|
|
130208
|
+
return left + right;
|
|
130209
|
+
case "-":
|
|
130210
|
+
return left - right;
|
|
130211
|
+
case "*":
|
|
130212
|
+
return left * right;
|
|
130213
|
+
case "/":
|
|
130214
|
+
return left / right;
|
|
130215
|
+
case "%":
|
|
130216
|
+
return left % right;
|
|
130217
|
+
case "**":
|
|
130218
|
+
return left ** right;
|
|
130219
|
+
case "&":
|
|
130220
|
+
return left & right;
|
|
130221
|
+
case "|":
|
|
130222
|
+
return left | right;
|
|
130223
|
+
case "^":
|
|
130224
|
+
return left ^ right;
|
|
130225
|
+
case "<<":
|
|
130226
|
+
return left << right;
|
|
130227
|
+
case ">>":
|
|
130228
|
+
return left >> right;
|
|
130229
|
+
}
|
|
130230
|
+
} finally {
|
|
130231
|
+
budget.setRetainedDataUsage(allocation, 0);
|
|
130232
|
+
}
|
|
130233
|
+
}
|
|
130234
|
+
var init_bigint_operators = __esm({
|
|
130235
|
+
"packages/safe-js/src/interp/bigint-operators.ts"() {
|
|
130236
|
+
"use strict";
|
|
130237
|
+
init_budget2();
|
|
130238
|
+
}
|
|
130239
|
+
});
|
|
130240
|
+
|
|
130134
130241
|
// packages/safe-js/src/interp/jobs.ts
|
|
130135
130242
|
import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
|
|
130136
130243
|
function runPromiseJob(task) {
|
|
@@ -130320,7 +130427,7 @@ function callNumberMethod(value, methodName, args, budget, context) {
|
|
|
130320
130427
|
if (argument !== null && typeof argument === "object") {
|
|
130321
130428
|
return formatObjectArgument(value, methodName, argument, budget, context);
|
|
130322
130429
|
}
|
|
130323
|
-
return formatNumber3(value, methodName, argument === void 0 ? void 0 :
|
|
130430
|
+
return formatNumber3(value, methodName, argument === void 0 ? void 0 : +argument, budget);
|
|
130324
130431
|
}
|
|
130325
130432
|
async function formatObjectArgument(value, methodName, argument, budget, context) {
|
|
130326
130433
|
const retainedArgument = {};
|
|
@@ -131125,10 +131232,10 @@ function splitString(value, separator, limit) {
|
|
|
131125
131232
|
return split.call(value, separator, limit);
|
|
131126
131233
|
}
|
|
131127
131234
|
function asNumber(value) {
|
|
131128
|
-
return
|
|
131235
|
+
return +value;
|
|
131129
131236
|
}
|
|
131130
131237
|
function asNumberOrUndefined(value) {
|
|
131131
|
-
return value === void 0 ? void 0 :
|
|
131238
|
+
return value === void 0 ? void 0 : +value;
|
|
131132
131239
|
}
|
|
131133
131240
|
function asStringOrUndefined(value) {
|
|
131134
131241
|
return value === void 0 ? void 0 : String(value);
|
|
@@ -131539,7 +131646,7 @@ function createObjectArrayGlobals(options) {
|
|
|
131539
131646
|
),
|
|
131540
131647
|
Number: createPrimitiveConstructor(
|
|
131541
131648
|
{
|
|
131542
|
-
call: (args, context) => sandboxNumber(args.length === 0 ? 0 : args[0], options.budget, context),
|
|
131649
|
+
call: (args, context) => sandboxNumber(args.length === 0 ? 0 : args[0], options.budget, context, true),
|
|
131543
131650
|
name: "Number",
|
|
131544
131651
|
properties: {
|
|
131545
131652
|
isFinite: createSandboxClosure({
|
|
@@ -136092,8 +136199,9 @@ async function evaluateIdentifierUpdateExpression(node, context) {
|
|
|
136092
136199
|
)
|
|
136093
136200
|
};
|
|
136094
136201
|
}
|
|
136095
|
-
const
|
|
136096
|
-
const
|
|
136202
|
+
const primitive = await toNumericPrimitive(binding.value, context);
|
|
136203
|
+
const current = typeof primitive === "bigint" ? primitive : toNumber(primitive);
|
|
136204
|
+
const next = typeof current === "bigint" ? bigIntOperation(node.operator === "++" ? "+" : "-", current, 1n, context.budget) : node.operator === "++" ? current + 1 : current - 1;
|
|
136097
136205
|
context.scope.assign(node.argument.name, next);
|
|
136098
136206
|
return {
|
|
136099
136207
|
kind: "normal",
|
|
@@ -136110,10 +136218,9 @@ async function evaluateMemberUpdateExpression(node, context) {
|
|
|
136110
136218
|
throw new TypeError("Cannot update properties of null or undefined.");
|
|
136111
136219
|
}
|
|
136112
136220
|
const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
136113
|
-
const
|
|
136114
|
-
|
|
136115
|
-
);
|
|
136116
|
-
const next = node.operator === "++" ? current + 1 : current - 1;
|
|
136221
|
+
const primitive = await toNumericPrimitive(await getPropertyValue(member.object, property, context, member.superReceiver === void 0 ? member.object : member.superReceiver.value), context);
|
|
136222
|
+
const current = typeof primitive === "bigint" ? primitive : toNumber(primitive);
|
|
136223
|
+
const next = typeof current === "bigint" ? bigIntOperation(node.operator === "++" ? "+" : "-", current, 1n, context.budget) : node.operator === "++" ? current + 1 : current - 1;
|
|
136117
136224
|
if (member.superReceiver === void 0) await setSandboxProperty(member.object, property, next, context.budget, true, createCoercionContext(context));
|
|
136118
136225
|
else await setSuperProperty(member.object, member.superReceiver.value, property, next, context);
|
|
136119
136226
|
return {
|
|
@@ -136147,7 +136254,7 @@ function getPropertyValue(target, property, context, receiver = target) {
|
|
|
136147
136254
|
if (descriptor !== void 0)
|
|
136148
136255
|
return readPropertyDescriptor(descriptor, receiver, createCoercionContext(context), true);
|
|
136149
136256
|
if (isSandboxRegExpIterator(target)) return getRegExpIteratorMember(property, context.budget);
|
|
136150
|
-
if (typeof target === "symbol") {
|
|
136257
|
+
if (typeof target === "symbol" || typeof target === "bigint") {
|
|
136151
136258
|
const prototype = getBoxedPrototype(target, context.budget);
|
|
136152
136259
|
return prototype === void 0 ? void 0 : getPropertyValue(prototype, property, context, receiver);
|
|
136153
136260
|
}
|
|
@@ -136328,6 +136435,7 @@ async function evaluateObjectPropertyKey(node, context) {
|
|
|
136328
136435
|
return evaluateMemberProperty(node.key, context);
|
|
136329
136436
|
}
|
|
136330
136437
|
function getStaticPropertyName(node) {
|
|
136438
|
+
if (node.type === "BigIntLiteral") return BigInt(node.value).toString();
|
|
136331
136439
|
if (node.type === "Identifier") {
|
|
136332
136440
|
return node.name;
|
|
136333
136441
|
}
|
|
@@ -136361,7 +136469,7 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
136361
136469
|
return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
|
|
136362
136470
|
if (Array.isArray(member.object) && hasExplicitSandboxPrototype(member.object))
|
|
136363
136471
|
return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
|
|
136364
|
-
if ((typeof member.object === "string" || typeof member.object === "number" || typeof member.object === "boolean" || typeof member.object === "symbol") && getBoxedPrototype(member.object, context.budget) !== void 0) {
|
|
136472
|
+
if ((typeof member.object === "string" || typeof member.object === "number" || typeof member.object === "bigint" || typeof member.object === "boolean" || typeof member.object === "symbol") && getBoxedPrototype(member.object, context.budget) !== void 0) {
|
|
136365
136473
|
if (isDefaultBoxedMethod(member.object, member.property, context.budget)) {
|
|
136366
136474
|
if (typeof member.object === "string" && isStringMethodName(member.property))
|
|
136367
136475
|
return evaluateStringMethodCall(node, member.object, member.property, context);
|
|
@@ -136611,10 +136719,14 @@ async function applyUnaryOperator(operator, value, context) {
|
|
|
136611
136719
|
return void 0;
|
|
136612
136720
|
case "+":
|
|
136613
136721
|
return toNumber(await toNumericPrimitive(value, context));
|
|
136614
|
-
case "-":
|
|
136615
|
-
|
|
136616
|
-
|
|
136617
|
-
|
|
136722
|
+
case "-": {
|
|
136723
|
+
const primitive = await toNumericPrimitive(value, context);
|
|
136724
|
+
return typeof primitive === "bigint" ? bigIntOperation("-", 0n, primitive, context.budget) : -toNumber(primitive);
|
|
136725
|
+
}
|
|
136726
|
+
case "~": {
|
|
136727
|
+
const primitive = await toNumericPrimitive(value, context);
|
|
136728
|
+
return typeof primitive === "bigint" ? bigIntOperation("^", primitive, -1n, context.budget) : ~toNumber(primitive);
|
|
136729
|
+
}
|
|
136618
136730
|
}
|
|
136619
136731
|
}
|
|
136620
136732
|
function describeTypeofValue(value) {
|
|
@@ -136630,6 +136742,10 @@ function isTruthy(value) {
|
|
|
136630
136742
|
return Boolean(value);
|
|
136631
136743
|
}
|
|
136632
136744
|
function applyBinaryOperator(node, left, right, context) {
|
|
136745
|
+
if ((typeof left === "bigint" || typeof right === "bigint") && ["-", "*", "/", "%", "**", "&", "|", "^", "<<", ">>", ">>>"].includes(node.operator)) {
|
|
136746
|
+
if (typeof left !== "bigint" || typeof right !== "bigint") throw new TypeError("Cannot mix BigInt and other numeric types.");
|
|
136747
|
+
return bigIntOperation(node.operator, left, right, context.budget);
|
|
136748
|
+
}
|
|
136633
136749
|
switch (node.operator) {
|
|
136634
136750
|
case "+":
|
|
136635
136751
|
return applyAdditionOperator(left, right, context);
|
|
@@ -136748,6 +136864,10 @@ async function applyCompoundAssignmentOperator(operator, left, right, context) {
|
|
|
136748
136864
|
left = await toNumericPrimitive(left, context, operator === "+=" ? "default" : "number");
|
|
136749
136865
|
if (convertingObject) convertedLeft = left;
|
|
136750
136866
|
right = await toNumericPrimitive(right, context, operator === "+=" ? "default" : "number");
|
|
136867
|
+
if (operator !== "+=" && (typeof left === "bigint" || typeof right === "bigint")) {
|
|
136868
|
+
if (typeof left !== "bigint" || typeof right !== "bigint") throw new TypeError("Cannot mix BigInt and other numeric types.");
|
|
136869
|
+
return bigIntOperation(operator.slice(0, -1), left, right, context.budget);
|
|
136870
|
+
}
|
|
136751
136871
|
switch (operator) {
|
|
136752
136872
|
case "+=":
|
|
136753
136873
|
return applyAdditionOperator(left, right, context);
|
|
@@ -136784,6 +136904,10 @@ function applyAdditionOperator(left, right, context) {
|
|
|
136784
136904
|
if (typeof leftPrimitive === "string" || typeof rightPrimitive === "string") {
|
|
136785
136905
|
return context.budget.allocateString(toString(leftPrimitive) + toString(rightPrimitive));
|
|
136786
136906
|
}
|
|
136907
|
+
if (typeof leftPrimitive === "bigint" || typeof rightPrimitive === "bigint") {
|
|
136908
|
+
if (typeof leftPrimitive !== "bigint" || typeof rightPrimitive !== "bigint") throw new TypeError("Cannot mix BigInt and other numeric types.");
|
|
136909
|
+
return bigIntOperation("+", leftPrimitive, rightPrimitive, context.budget);
|
|
136910
|
+
}
|
|
136787
136911
|
return toNumber(leftPrimitive) + toNumber(rightPrimitive);
|
|
136788
136912
|
}
|
|
136789
136913
|
function compareRelational(left, right, operator) {
|
|
@@ -136801,8 +136925,9 @@ function compareRelational(left, right, operator) {
|
|
|
136801
136925
|
return leftPrimitive >= rightPrimitive;
|
|
136802
136926
|
}
|
|
136803
136927
|
}
|
|
136804
|
-
const
|
|
136805
|
-
const
|
|
136928
|
+
const hasBigInt = typeof leftPrimitive === "bigint" || typeof rightPrimitive === "bigint";
|
|
136929
|
+
const leftNumber = typeof leftPrimitive === "bigint" || hasBigInt && typeof leftPrimitive === "string" ? leftPrimitive : toNumber(leftPrimitive);
|
|
136930
|
+
const rightNumber = typeof rightPrimitive === "bigint" || hasBigInt && typeof rightPrimitive === "string" ? rightPrimitive : toNumber(rightPrimitive);
|
|
136806
136931
|
switch (operator) {
|
|
136807
136932
|
case "<":
|
|
136808
136933
|
return leftNumber < rightNumber;
|
|
@@ -136815,6 +136940,7 @@ function compareRelational(left, right, operator) {
|
|
|
136815
136940
|
}
|
|
136816
136941
|
}
|
|
136817
136942
|
function isLooselyEqual(left, right) {
|
|
136943
|
+
if (typeof left === "bigint" || typeof right === "bigint") return left == right;
|
|
136818
136944
|
const leftType = getCoercionType(left);
|
|
136819
136945
|
const rightType = getCoercionType(right);
|
|
136820
136946
|
if (leftType === rightType) {
|
|
@@ -136847,6 +136973,7 @@ function isPrimitiveCoercionType(type) {
|
|
|
136847
136973
|
return type !== "object";
|
|
136848
136974
|
}
|
|
136849
136975
|
function getCoercionType(value) {
|
|
136976
|
+
if (typeof value === "bigint") return "bigint";
|
|
136850
136977
|
if (typeof value === "symbol") return "symbol";
|
|
136851
136978
|
if (value === null) {
|
|
136852
136979
|
return "null";
|
|
@@ -136880,6 +137007,7 @@ async function toNumericPrimitive(value, context, hint = "number") {
|
|
|
136880
137007
|
throw new TypeError("Expected a sandbox value.");
|
|
136881
137008
|
}
|
|
136882
137009
|
function toNumber(value) {
|
|
137010
|
+
if (typeof value === "bigint") throw new TypeError("Cannot convert a BigInt value to a number");
|
|
136883
137011
|
if (typeof value === "symbol") throw new TypeError("Cannot convert a Symbol value to a number");
|
|
136884
137012
|
if (isSandboxDate(value)) return dateTime(value);
|
|
136885
137013
|
if (typeof value === "number") {
|
|
@@ -137299,6 +137427,7 @@ var init_interpreter = __esm({
|
|
|
137299
137427
|
"packages/safe-js/src/interp/interpreter.ts"() {
|
|
137300
137428
|
"use strict";
|
|
137301
137429
|
init_promise_replay();
|
|
137430
|
+
init_bigint_operators();
|
|
137302
137431
|
init_accessors();
|
|
137303
137432
|
init_host_capabilities();
|
|
137304
137433
|
init_property_key();
|
|
@@ -137352,6 +137481,16 @@ var init_interpreter = __esm({
|
|
|
137352
137481
|
ArrowFunctionExpression: evaluateArrowFunction,
|
|
137353
137482
|
AwaitExpression: evaluateAwait,
|
|
137354
137483
|
BinaryExpression: evaluateBinaryExpression,
|
|
137484
|
+
BigIntLiteral: async (node, context) => {
|
|
137485
|
+
const allocation = {};
|
|
137486
|
+
context.budget.visitNode(node.value.length);
|
|
137487
|
+
context.budget.setRetainedDataUsage(allocation, node.value.length);
|
|
137488
|
+
try {
|
|
137489
|
+
return { kind: "normal", hasValue: true, value: BigInt(node.value) };
|
|
137490
|
+
} finally {
|
|
137491
|
+
context.budget.setRetainedDataUsage(allocation, 0);
|
|
137492
|
+
}
|
|
137493
|
+
},
|
|
137355
137494
|
BlockStatement: evaluateBlockStatement,
|
|
137356
137495
|
BooleanLiteral: evaluatePrimitiveLiteral,
|
|
137357
137496
|
CallExpression: evaluateCallExpression,
|
|
@@ -139217,7 +139356,7 @@ function wrapSandboxClosureForHost(closure, stackFrames, budget, compileOwner, c
|
|
|
139217
139356
|
return wrapped;
|
|
139218
139357
|
}
|
|
139219
139358
|
function isSandboxLikeValue(value) {
|
|
139220
|
-
if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
139359
|
+
if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") {
|
|
139221
139360
|
return true;
|
|
139222
139361
|
}
|
|
139223
139362
|
if (isSandboxClosure(value) || isSandboxPromise(value)) {
|
|
@@ -139282,7 +139421,7 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path193) {
|
|
|
139282
139421
|
if (options.realm === void 0 || options.errorData || options.hostCalls !== void 0) throw new TypeError("Live capabilities are not portable replay or error data.");
|
|
139283
139422
|
return importHostCapability(value, options.realm.owner);
|
|
139284
139423
|
}
|
|
139285
|
-
if (value === null || value === void 0 || typeof value === "number" || typeof value === "boolean") {
|
|
139424
|
+
if (value === null || value === void 0 || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") {
|
|
139286
139425
|
return value;
|
|
139287
139426
|
}
|
|
139288
139427
|
if (typeof value === "string") {
|
|
@@ -139805,12 +139944,16 @@ var init_date2 = __esm({
|
|
|
139805
139944
|
});
|
|
139806
139945
|
|
|
139807
139946
|
// packages/safe-js/src/interp/string-coercion.ts
|
|
139808
|
-
function sandboxNumber(value, budget, context) {
|
|
139947
|
+
function sandboxNumber(value, budget, context, allowBigInt = false) {
|
|
139948
|
+
const convert = (primitive) => {
|
|
139949
|
+
if (typeof primitive === "bigint" && !allowBigInt) throw new TypeError("Cannot convert a BigInt value to a number");
|
|
139950
|
+
return Number(primitive);
|
|
139951
|
+
};
|
|
139809
139952
|
if (value === null || typeof value !== "object") {
|
|
139810
139953
|
if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
|
|
139811
|
-
return
|
|
139954
|
+
return convert(value);
|
|
139812
139955
|
}
|
|
139813
|
-
return objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number").then(
|
|
139956
|
+
return objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number").then(convert);
|
|
139814
139957
|
}
|
|
139815
139958
|
function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
|
|
139816
139959
|
if (typeof value === "symbol") throw new TypeError("Cannot convert a Symbol value to a string");
|
|
@@ -141903,6 +142046,10 @@ function measureSandboxData(values, options = {}) {
|
|
|
141903
142046
|
const seenSymbols = /* @__PURE__ */ new Set();
|
|
141904
142047
|
let usage = 0;
|
|
141905
142048
|
const visit = (value, depth = 0) => {
|
|
142049
|
+
if (typeof value === "bigint") {
|
|
142050
|
+
usage += value.toString(16).length;
|
|
142051
|
+
return;
|
|
142052
|
+
}
|
|
141906
142053
|
if (typeof value === "symbol") {
|
|
141907
142054
|
if (!seenSymbols.has(value)) {
|
|
141908
142055
|
seenSymbols.add(value);
|
|
@@ -142575,7 +142722,7 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
|
|
|
142575
142722
|
throw new TypeError(`Unsupported sandbox value at ${path193}: ${describeValue2(value)}`);
|
|
142576
142723
|
}
|
|
142577
142724
|
function isSandboxPrimitive(value) {
|
|
142578
|
-
return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "symbol";
|
|
142725
|
+
return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean" || typeof value === "symbol";
|
|
142579
142726
|
}
|
|
142580
142727
|
function isHostPromise(value) {
|
|
142581
142728
|
return value instanceof Promise;
|
|
@@ -142938,6 +143085,7 @@ function createDumpFile(snapshot2) {
|
|
|
142938
143085
|
return dumped;
|
|
142939
143086
|
}
|
|
142940
143087
|
function serializeDumpValue(value, path193, state) {
|
|
143088
|
+
if (typeof value === "bigint") return { kind: "bigint", value: String(value) };
|
|
142941
143089
|
if (typeof value === "symbol") return serializeSymbol(value, state.heapIds, state.heap);
|
|
142942
143090
|
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
142943
143091
|
return value;
|
|
@@ -143365,6 +143513,14 @@ function validateValue(value, path193, depth, state) {
|
|
|
143365
143513
|
}
|
|
143366
143514
|
function validateTaggedValue(record2, path193, state) {
|
|
143367
143515
|
switch (record2.kind) {
|
|
143516
|
+
case "bigint":
|
|
143517
|
+
requireString2(record2.value, `${path193}.value`, state.limits);
|
|
143518
|
+
try {
|
|
143519
|
+
validateBigIntData(record2.value);
|
|
143520
|
+
} catch {
|
|
143521
|
+
fail2("invalidValue", `${path193}.value`, "invalid BigInt value");
|
|
143522
|
+
}
|
|
143523
|
+
return;
|
|
143368
143524
|
case "undefined":
|
|
143369
143525
|
return;
|
|
143370
143526
|
case "number":
|
|
@@ -143531,6 +143687,14 @@ function validateBoxedRecord(record2, path193, heap) {
|
|
|
143531
143687
|
const value = record2.value;
|
|
143532
143688
|
if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") return;
|
|
143533
143689
|
const number = requireRecord3(value, `${path193}.value`);
|
|
143690
|
+
if (number.kind === "bigint") {
|
|
143691
|
+
try {
|
|
143692
|
+
validateBigIntData(number.value);
|
|
143693
|
+
} catch {
|
|
143694
|
+
fail2("invalidValue", `${path193}.value`, "invalid boxed BigInt payload");
|
|
143695
|
+
}
|
|
143696
|
+
return;
|
|
143697
|
+
}
|
|
143534
143698
|
if (number.kind === "ref") {
|
|
143535
143699
|
const id = requireSafeInteger(number.id, `${path193}.value.id`, 1);
|
|
143536
143700
|
const target = requireRecord3(heap[String(id)], `${path193}.value`);
|
|
@@ -143777,6 +143941,7 @@ var init_validation = __esm({
|
|
|
143777
143941
|
"packages/safe-js/src/snapshot/validation.ts"() {
|
|
143778
143942
|
"use strict";
|
|
143779
143943
|
init_shape();
|
|
143944
|
+
init_bigint();
|
|
143780
143945
|
init_regexp_properties2();
|
|
143781
143946
|
init_symbols2();
|
|
143782
143947
|
init_dump_format();
|
|
@@ -144690,6 +144855,7 @@ var init_known_globals = __esm({
|
|
|
144690
144855
|
"AggregateError",
|
|
144691
144856
|
"Array",
|
|
144692
144857
|
"Boolean",
|
|
144858
|
+
"BigInt",
|
|
144693
144859
|
"Date",
|
|
144694
144860
|
"Error",
|
|
144695
144861
|
"Infinity",
|
|
@@ -147934,6 +148100,7 @@ function expressionContainsAwait(node) {
|
|
|
147934
148100
|
case "MetaProperty":
|
|
147935
148101
|
case "NullLiteral":
|
|
147936
148102
|
case "NumericLiteral":
|
|
148103
|
+
case "BigIntLiteral":
|
|
147937
148104
|
case "RegexLiteral":
|
|
147938
148105
|
case "StringLiteral":
|
|
147939
148106
|
case "ThisExpression":
|
|
@@ -148217,6 +148384,7 @@ var init_AS_async_not_needed = __esm({
|
|
|
148217
148384
|
case "MetaProperty":
|
|
148218
148385
|
case "NullLiteral":
|
|
148219
148386
|
case "NumericLiteral":
|
|
148387
|
+
case "BigIntLiteral":
|
|
148220
148388
|
case "RegexLiteral":
|
|
148221
148389
|
case "StringLiteral":
|
|
148222
148390
|
case "UndefinedLiteral":
|
|
@@ -151696,6 +151864,7 @@ function expressionContainsAwait2(node) {
|
|
|
151696
151864
|
case "MetaProperty":
|
|
151697
151865
|
case "NullLiteral":
|
|
151698
151866
|
case "NumericLiteral":
|
|
151867
|
+
case "BigIntLiteral":
|
|
151699
151868
|
case "RegexLiteral":
|
|
151700
151869
|
case "StringLiteral":
|
|
151701
151870
|
case "ThisExpression":
|
|
@@ -151967,6 +152136,7 @@ var init_AS_missing_async = __esm({
|
|
|
151967
152136
|
case "MetaProperty":
|
|
151968
152137
|
case "NullLiteral":
|
|
151969
152138
|
case "NumericLiteral":
|
|
152139
|
+
case "BigIntLiteral":
|
|
151970
152140
|
case "RegexLiteral":
|
|
151971
152141
|
case "StringLiteral":
|
|
151972
152142
|
case "UndefinedLiteral":
|
|
@@ -155350,29 +155520,53 @@ function createConsoleJsonGlobals(options) {
|
|
|
155350
155520
|
};
|
|
155351
155521
|
}
|
|
155352
155522
|
async function stringifyJson4(value, replacer, indent, budget, context) {
|
|
155353
|
-
|
|
155354
|
-
|
|
155355
|
-
|
|
155356
|
-
|
|
155357
|
-
|
|
155358
|
-
|
|
155359
|
-
|
|
155360
|
-
|
|
155361
|
-
|
|
155362
|
-
|
|
155363
|
-
|
|
155364
|
-
|
|
155365
|
-
|
|
155366
|
-
|
|
155367
|
-
|
|
155368
|
-
|
|
155369
|
-
|
|
155370
|
-
|
|
155371
|
-
|
|
155372
|
-
|
|
155373
|
-
|
|
155523
|
+
const allocation = {};
|
|
155524
|
+
let propertyList;
|
|
155525
|
+
const release2 = retainValues(budget, () => [value, replacer, indent]);
|
|
155526
|
+
try {
|
|
155527
|
+
if (Array.isArray(replacer)) {
|
|
155528
|
+
propertyList = [];
|
|
155529
|
+
const seen = /* @__PURE__ */ new Set();
|
|
155530
|
+
let size = 0;
|
|
155531
|
+
const state = { budget, context, gap: "", stack: [] };
|
|
155532
|
+
const length = replacer.length;
|
|
155533
|
+
for (let index = 0; index < length; index++) {
|
|
155534
|
+
budget.visitNode();
|
|
155535
|
+
const entry = await getStringifyProperty(replacer, String(index), state);
|
|
155536
|
+
const primitive = isSandboxBox(entry) ? boxedValue(entry) : entry;
|
|
155537
|
+
if (typeof primitive !== "string" && typeof primitive !== "number") continue;
|
|
155538
|
+
const key3 = await sandboxString(entry, budget, context);
|
|
155539
|
+
if (seen.has(key3)) continue;
|
|
155540
|
+
budget.allocateArrayLength(propertyList.length + 1);
|
|
155541
|
+
size += key3.length + 2;
|
|
155542
|
+
budget.setRetainedDataUsage(allocation, size);
|
|
155543
|
+
propertyList.push(key3);
|
|
155544
|
+
seen.add(key3);
|
|
155545
|
+
}
|
|
155546
|
+
}
|
|
155547
|
+
if (isSandboxBox(indent)) {
|
|
155548
|
+
const primitive = boxedValue(indent);
|
|
155549
|
+
if (typeof primitive === "number") indent = await sandboxNumber(indent, budget, context);
|
|
155550
|
+
else if (typeof primitive === "string") indent = await sandboxString(indent, budget, context);
|
|
155551
|
+
}
|
|
155552
|
+
const holder = {};
|
|
155553
|
+
defineDataProperty9(holder, "", value);
|
|
155554
|
+
const output = await stringifyProperty("", holder, {
|
|
155555
|
+
budget,
|
|
155556
|
+
context,
|
|
155557
|
+
gap: normalizeStringifyGap(indent),
|
|
155558
|
+
replacer: isSandboxClosure(replacer) ? replacer : void 0,
|
|
155559
|
+
propertyList,
|
|
155560
|
+
stack: []
|
|
155561
|
+
});
|
|
155562
|
+
if (output === void 0) {
|
|
155563
|
+
return void 0;
|
|
155564
|
+
}
|
|
155565
|
+
return budget.allocateString(output);
|
|
155566
|
+
} finally {
|
|
155567
|
+
budget.setRetainedDataUsage(allocation, 0);
|
|
155568
|
+
release2();
|
|
155374
155569
|
}
|
|
155375
|
-
return budget.allocateString(output);
|
|
155376
155570
|
}
|
|
155377
155571
|
async function stringifyProperty(key3, holder, state, indent = "") {
|
|
155378
155572
|
let value = await getStringifyProperty(holder, key3, state);
|
|
@@ -155380,7 +155574,7 @@ async function stringifyProperty(key3, holder, state, indent = "") {
|
|
|
155380
155574
|
try {
|
|
155381
155575
|
if (isSandboxDate(value) && getSandboxPropertyDescriptor(value, "toJSON", state.budget) === void 0) {
|
|
155382
155576
|
value = await dateToJSON(value, state.budget, state.context);
|
|
155383
|
-
} else if (isStringifyContainer(value)) {
|
|
155577
|
+
} else if (typeof value === "bigint" || isSandboxClosure(value) || isStringifyContainer(value)) {
|
|
155384
155578
|
const toJSON = await getStringifyProperty(value, "toJSON", state);
|
|
155385
155579
|
if (isSandboxClosure(toJSON)) {
|
|
155386
155580
|
value = await callStringifyClosure(toJSON, [key3], value, state);
|
|
@@ -155462,7 +155656,7 @@ async function stringifyObject(value, state, indent) {
|
|
|
155462
155656
|
const release2 = retainValues(state.budget, () => entries);
|
|
155463
155657
|
try {
|
|
155464
155658
|
const nextIndent = indent + state.gap;
|
|
155465
|
-
for (const key3 of Object.keys(value)) {
|
|
155659
|
+
for (const key3 of state.propertyList ?? Object.keys(value)) {
|
|
155466
155660
|
const serialized = await stringifyProperty(key3, value, state, nextIndent);
|
|
155467
155661
|
if (serialized !== void 0) {
|
|
155468
155662
|
entries.push(`${quoteJsonString(key3)}:${state.gap === "" ? "" : " "}${serialized}`);
|
|
@@ -155525,19 +155719,17 @@ function isStringifyObject(value) {
|
|
|
155525
155719
|
return isStringifyContainer(value) && !Array.isArray(value);
|
|
155526
155720
|
}
|
|
155527
155721
|
function toSandboxValue(value) {
|
|
155528
|
-
if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || isSandboxClosure(value) || isSandboxPromise(value) || Array.isArray(value) || isStringifyContainer(value)) {
|
|
155722
|
+
if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "symbol" || typeof value === "boolean" || isSandboxClosure(value) || isSandboxPromise(value) || Array.isArray(value) || isStringifyContainer(value)) {
|
|
155529
155723
|
return value;
|
|
155530
155724
|
}
|
|
155531
|
-
if (typeof value === "bigint") {
|
|
155532
|
-
throw new TypeError("Do not know how to serialize a BigInt.");
|
|
155533
|
-
}
|
|
155534
155725
|
throw new TypeError(
|
|
155535
155726
|
`JSON.stringify(value) produced an unsupported value of type ${typeof value}.`
|
|
155536
155727
|
);
|
|
155537
155728
|
}
|
|
155538
155729
|
function getStringifyProperty(target, key3, state) {
|
|
155539
155730
|
if (state.context?.getProperty !== void 0) return state.context.getProperty(target, key3);
|
|
155540
|
-
const
|
|
155731
|
+
const object = typeof target === "bigint" ? getBoxedPrototype(target, state.budget) : target;
|
|
155732
|
+
const descriptor = object === void 0 ? void 0 : getSandboxPropertyDescriptor(object, key3, state.budget);
|
|
155541
155733
|
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, target, state.context);
|
|
155542
155734
|
}
|
|
155543
155735
|
function copyJsonToSandbox(value, budget) {
|
|
@@ -156276,6 +156468,109 @@ var init_symbol = __esm({
|
|
|
156276
156468
|
}
|
|
156277
156469
|
});
|
|
156278
156470
|
|
|
156471
|
+
// packages/safe-js/src/interp/globals/bigint.ts
|
|
156472
|
+
function createBigIntGlobal(budget) {
|
|
156473
|
+
const convert = async (value, context, allowNumber = false) => {
|
|
156474
|
+
const primitive = value !== null && typeof value === "object" ? await objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number") : value;
|
|
156475
|
+
if (typeof primitive === "bigint") return primitive;
|
|
156476
|
+
if (typeof primitive !== "string" && typeof primitive !== "boolean" && !(allowNumber && typeof primitive === "number"))
|
|
156477
|
+
throw new TypeError("Cannot convert value to BigInt.");
|
|
156478
|
+
const size = typeof primitive === "string" ? primitive.length : 256;
|
|
156479
|
+
budget.visitNode(size);
|
|
156480
|
+
const allocation = {};
|
|
156481
|
+
budget.setRetainedDataUsage(allocation, size);
|
|
156482
|
+
try {
|
|
156483
|
+
return BigInt(primitive);
|
|
156484
|
+
} finally {
|
|
156485
|
+
budget.setRetainedDataUsage(allocation, 0);
|
|
156486
|
+
}
|
|
156487
|
+
};
|
|
156488
|
+
const constructor = createSandboxClosure({
|
|
156489
|
+
guest: true,
|
|
156490
|
+
sandbox: true,
|
|
156491
|
+
name: "BigInt",
|
|
156492
|
+
length: 1,
|
|
156493
|
+
call: ([value], context) => convert(value, context, true)
|
|
156494
|
+
});
|
|
156495
|
+
const prototype = /* @__PURE__ */ Object.create(null);
|
|
156496
|
+
Object.defineProperties(prototype, {
|
|
156497
|
+
constructor: { value: constructor, writable: true, configurable: true },
|
|
156498
|
+
valueOf: {
|
|
156499
|
+
value: createSandboxClosure({
|
|
156500
|
+
sandbox: true,
|
|
156501
|
+
name: "valueOf",
|
|
156502
|
+
length: 0,
|
|
156503
|
+
call: (_args, context) => primitiveReceiver(context?.thisValue, "bigint")
|
|
156504
|
+
}),
|
|
156505
|
+
writable: true,
|
|
156506
|
+
configurable: true
|
|
156507
|
+
},
|
|
156508
|
+
toString: {
|
|
156509
|
+
value: createSandboxClosure({
|
|
156510
|
+
sandbox: true,
|
|
156511
|
+
name: "toString",
|
|
156512
|
+
length: 1,
|
|
156513
|
+
call: async ([radix], context) => {
|
|
156514
|
+
const value = primitiveReceiver(context?.thisValue, "bigint");
|
|
156515
|
+
const base = radix === void 0 ? 10 : await sandboxNumber(radix, budget, context);
|
|
156516
|
+
const allocation = {};
|
|
156517
|
+
const size = value.toString(16).length * 4;
|
|
156518
|
+
budget.visitNode(size);
|
|
156519
|
+
budget.setRetainedDataUsage(allocation, size);
|
|
156520
|
+
try {
|
|
156521
|
+
return budget.allocateString(value.toString(base));
|
|
156522
|
+
} finally {
|
|
156523
|
+
budget.setRetainedDataUsage(allocation, 0);
|
|
156524
|
+
}
|
|
156525
|
+
}
|
|
156526
|
+
}),
|
|
156527
|
+
writable: true,
|
|
156528
|
+
configurable: true
|
|
156529
|
+
},
|
|
156530
|
+
[Symbol.toStringTag]: { value: "BigInt", configurable: true }
|
|
156531
|
+
});
|
|
156532
|
+
const properties = materializeFunctionProperties(constructor);
|
|
156533
|
+
Object.defineProperty(properties, "prototype", { value: prototype });
|
|
156534
|
+
for (const name of ["asIntN", "asUintN"]) {
|
|
156535
|
+
Object.defineProperty(properties, name, {
|
|
156536
|
+
writable: true,
|
|
156537
|
+
configurable: true,
|
|
156538
|
+
value: createSandboxClosure({
|
|
156539
|
+
sandbox: true,
|
|
156540
|
+
name,
|
|
156541
|
+
length: 2,
|
|
156542
|
+
call: async ([bits, input], context) => {
|
|
156543
|
+
const number = await sandboxNumber(bits, budget, context);
|
|
156544
|
+
const width = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
156545
|
+
if (width < 0 || !Number.isSafeInteger(width)) throw new RangeError("Invalid BigInt width.");
|
|
156546
|
+
const value = await convert(input, context);
|
|
156547
|
+
const size = value.toString(16).length;
|
|
156548
|
+
budget.visitNode(size);
|
|
156549
|
+
if (width >= size * 4 + 1 && (name === "asIntN" || value >= 0n)) return value;
|
|
156550
|
+
const allocation = {};
|
|
156551
|
+
budget.setRetainedDataUsage(allocation, Math.ceil(width / 4) + 1);
|
|
156552
|
+
try {
|
|
156553
|
+
return BigInt[name](width, value);
|
|
156554
|
+
} finally {
|
|
156555
|
+
budget.setRetainedDataUsage(allocation, 0);
|
|
156556
|
+
}
|
|
156557
|
+
}
|
|
156558
|
+
})
|
|
156559
|
+
});
|
|
156560
|
+
}
|
|
156561
|
+
installBoxedPrototype(budget, prototype, constructor, "bigint");
|
|
156562
|
+
return constructor;
|
|
156563
|
+
}
|
|
156564
|
+
var init_bigint2 = __esm({
|
|
156565
|
+
"packages/safe-js/src/interp/globals/bigint.ts"() {
|
|
156566
|
+
"use strict";
|
|
156567
|
+
init_boxed();
|
|
156568
|
+
init_object_model();
|
|
156569
|
+
init_string_coercion();
|
|
156570
|
+
init_values();
|
|
156571
|
+
}
|
|
156572
|
+
});
|
|
156573
|
+
|
|
156279
156574
|
// packages/safe-js/src/interp/globals.ts
|
|
156280
156575
|
function createBuiltinBindings(options) {
|
|
156281
156576
|
return {
|
|
@@ -156284,6 +156579,7 @@ function createBuiltinBindings(options) {
|
|
|
156284
156579
|
Float32Array: createFloat32ArrayGlobal(options.budget),
|
|
156285
156580
|
Date: createDateGlobal(options),
|
|
156286
156581
|
Symbol: createSymbolGlobal(options.budget),
|
|
156582
|
+
BigInt: createBigIntGlobal(options.budget),
|
|
156287
156583
|
...createErrorGlobals(options),
|
|
156288
156584
|
...createMathGlobals({ random: options.random }),
|
|
156289
156585
|
...createObjectArrayGlobals(options),
|
|
@@ -156306,6 +156602,7 @@ var init_globals = __esm({
|
|
|
156306
156602
|
init_promise();
|
|
156307
156603
|
init_date2();
|
|
156308
156604
|
init_symbol();
|
|
156605
|
+
init_bigint2();
|
|
156309
156606
|
}
|
|
156310
156607
|
});
|
|
156311
156608
|
|