@poe-platform/safe-js 0.1.204 → 0.1.205

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-EOTY4PCT.js";
30
+ } from "./chunk-YWQDSWZN.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-Z2ZXS55C.js.map
8252
+ //# sourceMappingURL=chunk-EOKMWSSM.js.map
@@ -1255,7 +1255,7 @@ var Lexer = class {
1255
1255
  this.advance();
1256
1256
  this.advance();
1257
1257
  this.consumeDigitsForBase(isHexDigit, "hexadecimal");
1258
- this.rejectBigIntSuffix();
1258
+ if (this.currentChar() === "n") this.advance();
1259
1259
  this.rejectInvalidNumericLiteralContinuation();
1260
1260
  return this.source.slice(start.offset, this.index);
1261
1261
  }
@@ -1263,7 +1263,7 @@ var Lexer = class {
1263
1263
  this.advance();
1264
1264
  this.advance();
1265
1265
  this.consumeDigitsForBase(isBinaryDigit, "binary");
1266
- this.rejectBigIntSuffix();
1266
+ if (this.currentChar() === "n") this.advance();
1267
1267
  this.rejectInvalidNumericLiteralContinuation();
1268
1268
  return this.source.slice(start.offset, this.index);
1269
1269
  }
@@ -1271,7 +1271,7 @@ var Lexer = class {
1271
1271
  this.advance();
1272
1272
  this.advance();
1273
1273
  this.consumeDigitsForBase(isOctalDigit, "octal");
1274
- this.rejectBigIntSuffix();
1274
+ if (this.currentChar() === "n") this.advance();
1275
1275
  this.rejectInvalidNumericLiteralContinuation();
1276
1276
  return this.source.slice(start.offset, this.index);
1277
1277
  }
@@ -1285,6 +1285,11 @@ var Lexer = class {
1285
1285
  }
1286
1286
  }
1287
1287
  this.consumeDecimalDigits();
1288
+ if (this.currentChar() === "n") {
1289
+ this.advance();
1290
+ this.rejectInvalidNumericLiteralContinuation();
1291
+ return this.source.slice(start.offset, this.index);
1292
+ }
1288
1293
  if (this.currentChar() === "." && (this.peekChar(1) !== "." || this.peekChar(2) !== ".")) {
1289
1294
  this.advance();
1290
1295
  this.consumeOptionalDecimalDigits();
@@ -1383,7 +1388,7 @@ var Lexer = class {
1383
1388
  }
1384
1389
  rejectBigIntSuffix() {
1385
1390
  if (this.currentChar() === "n") {
1386
- this.syntaxError("BigInt not supported", this.position());
1391
+ this.syntaxError("BigInt literals cannot contain a fraction or exponent", this.position());
1387
1392
  }
1388
1393
  }
1389
1394
  rejectInvalidNumericLiteralContinuation() {
@@ -5824,6 +5829,7 @@ function findImportMetaAssignmentInNode(node) {
5824
5829
  case "BooleanLiteral":
5825
5830
  case "NullLiteral":
5826
5831
  case "NumericLiteral":
5832
+ case "BigIntLiteral":
5827
5833
  case "StringLiteral":
5828
5834
  case "ThisExpression":
5829
5835
  case "RegexLiteral":
@@ -5902,6 +5908,12 @@ function isYieldArgumentTerminator(value) {
5902
5908
  return value === ";" || value === "}" || value === ")" || value === "]" || value === ",";
5903
5909
  }
5904
5910
  function createNumericLiteral(token) {
5911
+ if (token.value.endsWith("n")) return {
5912
+ type: "BigIntLiteral",
5913
+ raw: token.value,
5914
+ value: token.value.slice(0, -1).replaceAll("_", ""),
5915
+ span: createTokenSpan(token)
5916
+ };
5905
5917
  return {
5906
5918
  type: "NumericLiteral",
5907
5919
  raw: token.value,
@@ -7102,15 +7114,17 @@ var numberValue = Number.prototype.valueOf;
7102
7114
  var stringValue = String.prototype.valueOf;
7103
7115
  var booleanValue = Boolean.prototype.valueOf;
7104
7116
  var symbolValue = Symbol.prototype.valueOf;
7117
+ var bigintValue = BigInt.prototype.valueOf;
7105
7118
  function nativeBoxedValue(value) {
7106
7119
  if (types3.isNumberObject(value)) return Reflect.apply(numberValue, value, []);
7107
7120
  if (types3.isStringObject(value)) return Reflect.apply(stringValue, value, []);
7108
7121
  if (types3.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
7109
7122
  if (types3.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
7123
+ if (types3.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
7110
7124
  return void 0;
7111
7125
  }
7112
7126
  function createSandboxBox(value) {
7113
- if (typeof value !== "number" && typeof value !== "string" && typeof value !== "boolean" && typeof value !== "symbol")
7127
+ if (typeof value !== "number" && typeof value !== "bigint" && typeof value !== "string" && typeof value !== "boolean" && typeof value !== "symbol")
7114
7128
  throw new TypeError("Invalid boxed primitive payload.");
7115
7129
  const box = Object(value);
7116
7130
  Object.setPrototypeOf(box, null);
@@ -7605,6 +7619,18 @@ async function flushPromiseJobs() {
7605
7619
  // packages/safe-js/src/interp/promise-replay.ts
7606
7620
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
7607
7621
 
7622
+ // packages/safe-js/src/snapshot/bigint.ts
7623
+ function validateBigIntData(value) {
7624
+ if (typeof value !== "string" || value.length === 0) throw new TypeError("Invalid BigInt snapshot value.");
7625
+ if (value === "0") return;
7626
+ const start = value[0] === "-" ? 1 : 0;
7627
+ if (start === value.length || value[start] === "0") throw new TypeError("Invalid BigInt snapshot value.");
7628
+ for (let index = start; index < value.length; index++) {
7629
+ const code = value.charCodeAt(index);
7630
+ if (code < 48 || code > 57) throw new TypeError("Invalid BigInt snapshot value.");
7631
+ }
7632
+ }
7633
+
7608
7634
  // packages/safe-js/src/interp/symbols.ts
7609
7635
  var wellKnownSymbols = Object.freeze({
7610
7636
  iterator: Symbol.iterator,
@@ -8274,6 +8300,7 @@ function createDumpFile(snapshot) {
8274
8300
  return dumped;
8275
8301
  }
8276
8302
  function serializeDumpValue(value, path, state) {
8303
+ if (typeof value === "bigint") return { kind: "bigint", value: String(value) };
8277
8304
  if (typeof value === "symbol") return serializeSymbol(value, state.heapIds, state.heap);
8278
8305
  if (value === null || typeof value === "string" || typeof value === "boolean") {
8279
8306
  return value;
@@ -8705,6 +8732,14 @@ function validateValue(value, path, depth, state) {
8705
8732
  }
8706
8733
  function validateTaggedValue(record2, path, state) {
8707
8734
  switch (record2.kind) {
8735
+ case "bigint":
8736
+ requireString(record2.value, `${path}.value`, state.limits);
8737
+ try {
8738
+ validateBigIntData(record2.value);
8739
+ } catch {
8740
+ fail("invalidValue", `${path}.value`, "invalid BigInt value");
8741
+ }
8742
+ return;
8708
8743
  case "undefined":
8709
8744
  return;
8710
8745
  case "number":
@@ -8871,6 +8906,14 @@ function validateBoxedRecord(record2, path, heap) {
8871
8906
  const value = record2.value;
8872
8907
  if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") return;
8873
8908
  const number = requireRecord(value, `${path}.value`);
8909
+ if (number.kind === "bigint") {
8910
+ try {
8911
+ validateBigIntData(number.value);
8912
+ } catch {
8913
+ fail("invalidValue", `${path}.value`, "invalid boxed BigInt payload");
8914
+ }
8915
+ return;
8916
+ }
8874
8917
  if (number.kind === "ref") {
8875
8918
  const id = requireSafeInteger(number.id, `${path}.value.id`, 1);
8876
8919
  const target = requireRecord(heap[String(id)], `${path}.value`);
@@ -10062,6 +10105,69 @@ function isLineTerminator(character) {
10062
10105
  return character === "\n" || character === "\r" || character === "\u2028" || character === "\u2029";
10063
10106
  }
10064
10107
 
10108
+ // packages/safe-js/src/interp/bigint-operators.ts
10109
+ function bigIntOperation(operator, left, right, budget) {
10110
+ if (operator === ">>>") throw new TypeError("BigInts have no unsigned right shift.");
10111
+ if ((operator === "/" || operator === "%") && right === 0n) throw new RangeError("Division by zero.");
10112
+ if (operator === "**" && right < 0n) throw new RangeError("BigInt exponent must be nonnegative.");
10113
+ const leftSize = left.toString(16).length;
10114
+ const rightSize = right.toString(16).length;
10115
+ budget.visitNode(leftSize + rightSize);
10116
+ let size = Math.max(leftSize, rightSize) + 1;
10117
+ let work = leftSize + rightSize;
10118
+ if (operator === "*") {
10119
+ size = leftSize + rightSize;
10120
+ work = leftSize * rightSize;
10121
+ } else if (operator === "/" || operator === "%") {
10122
+ size = leftSize;
10123
+ work = leftSize * rightSize;
10124
+ } else if (operator === "**") {
10125
+ if (right === 0n) return 1n;
10126
+ if (left === 0n || left === 1n) return left;
10127
+ if (left === -1n) return right % 2n === 0n ? 1n : -1n;
10128
+ size = leftSize * Number(right);
10129
+ work = size * size;
10130
+ } else if (operator === "<<" || operator === ">>") {
10131
+ if (left === 0n) return 0n;
10132
+ const shift = operator === "<<" ? right : -right;
10133
+ size = shift > 0n ? leftSize + Math.ceil(Number(shift) / 4) : leftSize;
10134
+ work = size + rightSize;
10135
+ }
10136
+ if (!Number.isSafeInteger(size) || !Number.isSafeInteger(work))
10137
+ throw new SandboxError({ budget: "dataSize", current: Infinity, limit: Number.MAX_SAFE_INTEGER });
10138
+ budget.visitNode(work);
10139
+ const allocation = {};
10140
+ budget.setRetainedDataUsage(allocation, size);
10141
+ try {
10142
+ switch (operator) {
10143
+ case "+":
10144
+ return left + right;
10145
+ case "-":
10146
+ return left - right;
10147
+ case "*":
10148
+ return left * right;
10149
+ case "/":
10150
+ return left / right;
10151
+ case "%":
10152
+ return left % right;
10153
+ case "**":
10154
+ return left ** right;
10155
+ case "&":
10156
+ return left & right;
10157
+ case "|":
10158
+ return left | right;
10159
+ case "^":
10160
+ return left ^ right;
10161
+ case "<<":
10162
+ return left << right;
10163
+ case ">>":
10164
+ return left >> right;
10165
+ }
10166
+ } finally {
10167
+ budget.setRetainedDataUsage(allocation, 0);
10168
+ }
10169
+ }
10170
+
10065
10171
  // packages/safe-js/src/interp/jobs.ts
10066
10172
  import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
10067
10173
  var activeJob = new AsyncLocalStorage4();
@@ -10237,7 +10343,7 @@ function callNumberMethod(value, methodName, args, budget, context) {
10237
10343
  if (argument !== null && typeof argument === "object") {
10238
10344
  return formatObjectArgument(value, methodName, argument, budget, context);
10239
10345
  }
10240
- return formatNumber(value, methodName, argument === void 0 ? void 0 : Number(argument), budget);
10346
+ return formatNumber(value, methodName, argument === void 0 ? void 0 : +argument, budget);
10241
10347
  }
10242
10348
  async function formatObjectArgument(value, methodName, argument, budget, context) {
10243
10349
  const retainedArgument = {};
@@ -11060,10 +11166,10 @@ function splitString(value, separator, limit) {
11060
11166
  return split.call(value, separator, limit);
11061
11167
  }
11062
11168
  function asNumber(value) {
11063
- return Number(value);
11169
+ return +value;
11064
11170
  }
11065
11171
  function asNumberOrUndefined(value) {
11066
- return value === void 0 ? void 0 : Number(value);
11172
+ return value === void 0 ? void 0 : +value;
11067
11173
  }
11068
11174
  function asStringOrUndefined(value) {
11069
11175
  return value === void 0 ? void 0 : String(value);
@@ -11413,7 +11519,7 @@ function createObjectArrayGlobals(options) {
11413
11519
  ),
11414
11520
  Number: createPrimitiveConstructor(
11415
11521
  {
11416
- call: (args, context) => sandboxNumber(args.length === 0 ? 0 : args[0], options.budget, context),
11522
+ call: (args, context) => sandboxNumber(args.length === 0 ? 0 : args[0], options.budget, context, true),
11417
11523
  name: "Number",
11418
11524
  properties: {
11419
11525
  isFinite: createSandboxClosure({
@@ -14097,6 +14203,16 @@ var dispatchTable = {
14097
14203
  ArrowFunctionExpression: evaluateArrowFunction,
14098
14204
  AwaitExpression: evaluateAwait,
14099
14205
  BinaryExpression: evaluateBinaryExpression,
14206
+ BigIntLiteral: async (node, context) => {
14207
+ const allocation = {};
14208
+ context.budget.visitNode(node.value.length);
14209
+ context.budget.setRetainedDataUsage(allocation, node.value.length);
14210
+ try {
14211
+ return { kind: "normal", hasValue: true, value: BigInt(node.value) };
14212
+ } finally {
14213
+ context.budget.setRetainedDataUsage(allocation, 0);
14214
+ }
14215
+ },
14100
14216
  BlockStatement: evaluateBlockStatement,
14101
14217
  BooleanLiteral: evaluatePrimitiveLiteral,
14102
14218
  CallExpression: evaluateCallExpression,
@@ -15871,8 +15987,9 @@ async function evaluateIdentifierUpdateExpression(node, context) {
15871
15987
  )
15872
15988
  };
15873
15989
  }
15874
- const current = toNumber(await toNumericPrimitive(binding.value, context));
15875
- const next = node.operator === "++" ? current + 1 : current - 1;
15990
+ const primitive = await toNumericPrimitive(binding.value, context);
15991
+ const current = typeof primitive === "bigint" ? primitive : toNumber(primitive);
15992
+ const next = typeof current === "bigint" ? bigIntOperation(node.operator === "++" ? "+" : "-", current, 1n, context.budget) : node.operator === "++" ? current + 1 : current - 1;
15876
15993
  context.scope.assign(node.argument.name, next);
15877
15994
  return {
15878
15995
  kind: "normal",
@@ -15889,10 +16006,9 @@ async function evaluateMemberUpdateExpression(node, context) {
15889
16006
  throw new TypeError("Cannot update properties of null or undefined.");
15890
16007
  }
15891
16008
  const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
15892
- const current = toNumber(
15893
- await toNumericPrimitive(await getPropertyValue(member.object, property, context, member.superReceiver === void 0 ? member.object : member.superReceiver.value), context)
15894
- );
15895
- const next = node.operator === "++" ? current + 1 : current - 1;
16009
+ const primitive = await toNumericPrimitive(await getPropertyValue(member.object, property, context, member.superReceiver === void 0 ? member.object : member.superReceiver.value), context);
16010
+ const current = typeof primitive === "bigint" ? primitive : toNumber(primitive);
16011
+ const next = typeof current === "bigint" ? bigIntOperation(node.operator === "++" ? "+" : "-", current, 1n, context.budget) : node.operator === "++" ? current + 1 : current - 1;
15896
16012
  if (member.superReceiver === void 0) await setSandboxProperty(member.object, property, next, context.budget, true, createCoercionContext(context));
15897
16013
  else await setSuperProperty(member.object, member.superReceiver.value, property, next, context);
15898
16014
  return {
@@ -15926,7 +16042,7 @@ function getPropertyValue(target, property, context, receiver = target) {
15926
16042
  if (descriptor !== void 0)
15927
16043
  return readPropertyDescriptor(descriptor, receiver, createCoercionContext(context), true);
15928
16044
  if (isSandboxRegExpIterator(target)) return getRegExpIteratorMember(property, context.budget);
15929
- if (typeof target === "symbol") {
16045
+ if (typeof target === "symbol" || typeof target === "bigint") {
15930
16046
  const prototype = getBoxedPrototype(target, context.budget);
15931
16047
  return prototype === void 0 ? void 0 : getPropertyValue(prototype, property, context, receiver);
15932
16048
  }
@@ -16107,6 +16223,7 @@ async function evaluateObjectPropertyKey(node, context) {
16107
16223
  return evaluateMemberProperty(node.key, context);
16108
16224
  }
16109
16225
  function getStaticPropertyName(node) {
16226
+ if (node.type === "BigIntLiteral") return BigInt(node.value).toString();
16110
16227
  if (node.type === "Identifier") {
16111
16228
  return node.name;
16112
16229
  }
@@ -16140,7 +16257,7 @@ async function evaluateMemberCallExpression(node, context) {
16140
16257
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
16141
16258
  if (Array.isArray(member.object) && hasExplicitSandboxPrototype(member.object))
16142
16259
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
16143
- if ((typeof member.object === "string" || typeof member.object === "number" || typeof member.object === "boolean" || typeof member.object === "symbol") && getBoxedPrototype(member.object, context.budget) !== void 0) {
16260
+ 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) {
16144
16261
  if (isDefaultBoxedMethod(member.object, member.property, context.budget)) {
16145
16262
  if (typeof member.object === "string" && isStringMethodName(member.property))
16146
16263
  return evaluateStringMethodCall(node, member.object, member.property, context);
@@ -16390,10 +16507,14 @@ async function applyUnaryOperator(operator, value, context) {
16390
16507
  return void 0;
16391
16508
  case "+":
16392
16509
  return toNumber(await toNumericPrimitive(value, context));
16393
- case "-":
16394
- return -toNumber(await toNumericPrimitive(value, context));
16395
- case "~":
16396
- return ~toNumber(await toNumericPrimitive(value, context));
16510
+ case "-": {
16511
+ const primitive = await toNumericPrimitive(value, context);
16512
+ return typeof primitive === "bigint" ? bigIntOperation("-", 0n, primitive, context.budget) : -toNumber(primitive);
16513
+ }
16514
+ case "~": {
16515
+ const primitive = await toNumericPrimitive(value, context);
16516
+ return typeof primitive === "bigint" ? bigIntOperation("^", primitive, -1n, context.budget) : ~toNumber(primitive);
16517
+ }
16397
16518
  }
16398
16519
  }
16399
16520
  function describeTypeofValue(value) {
@@ -16409,6 +16530,10 @@ function isTruthy(value) {
16409
16530
  return Boolean(value);
16410
16531
  }
16411
16532
  function applyBinaryOperator(node, left, right, context) {
16533
+ if ((typeof left === "bigint" || typeof right === "bigint") && ["-", "*", "/", "%", "**", "&", "|", "^", "<<", ">>", ">>>"].includes(node.operator)) {
16534
+ if (typeof left !== "bigint" || typeof right !== "bigint") throw new TypeError("Cannot mix BigInt and other numeric types.");
16535
+ return bigIntOperation(node.operator, left, right, context.budget);
16536
+ }
16412
16537
  switch (node.operator) {
16413
16538
  case "+":
16414
16539
  return applyAdditionOperator(left, right, context);
@@ -16527,6 +16652,10 @@ async function applyCompoundAssignmentOperator(operator, left, right, context) {
16527
16652
  left = await toNumericPrimitive(left, context, operator === "+=" ? "default" : "number");
16528
16653
  if (convertingObject) convertedLeft = left;
16529
16654
  right = await toNumericPrimitive(right, context, operator === "+=" ? "default" : "number");
16655
+ if (operator !== "+=" && (typeof left === "bigint" || typeof right === "bigint")) {
16656
+ if (typeof left !== "bigint" || typeof right !== "bigint") throw new TypeError("Cannot mix BigInt and other numeric types.");
16657
+ return bigIntOperation(operator.slice(0, -1), left, right, context.budget);
16658
+ }
16530
16659
  switch (operator) {
16531
16660
  case "+=":
16532
16661
  return applyAdditionOperator(left, right, context);
@@ -16563,6 +16692,10 @@ function applyAdditionOperator(left, right, context) {
16563
16692
  if (typeof leftPrimitive === "string" || typeof rightPrimitive === "string") {
16564
16693
  return context.budget.allocateString(toString(leftPrimitive) + toString(rightPrimitive));
16565
16694
  }
16695
+ if (typeof leftPrimitive === "bigint" || typeof rightPrimitive === "bigint") {
16696
+ if (typeof leftPrimitive !== "bigint" || typeof rightPrimitive !== "bigint") throw new TypeError("Cannot mix BigInt and other numeric types.");
16697
+ return bigIntOperation("+", leftPrimitive, rightPrimitive, context.budget);
16698
+ }
16566
16699
  return toNumber(leftPrimitive) + toNumber(rightPrimitive);
16567
16700
  }
16568
16701
  function compareRelational(left, right, operator) {
@@ -16580,8 +16713,9 @@ function compareRelational(left, right, operator) {
16580
16713
  return leftPrimitive >= rightPrimitive;
16581
16714
  }
16582
16715
  }
16583
- const leftNumber = toNumber(leftPrimitive);
16584
- const rightNumber = toNumber(rightPrimitive);
16716
+ const hasBigInt = typeof leftPrimitive === "bigint" || typeof rightPrimitive === "bigint";
16717
+ const leftNumber = typeof leftPrimitive === "bigint" || hasBigInt && typeof leftPrimitive === "string" ? leftPrimitive : toNumber(leftPrimitive);
16718
+ const rightNumber = typeof rightPrimitive === "bigint" || hasBigInt && typeof rightPrimitive === "string" ? rightPrimitive : toNumber(rightPrimitive);
16585
16719
  switch (operator) {
16586
16720
  case "<":
16587
16721
  return leftNumber < rightNumber;
@@ -16594,6 +16728,7 @@ function compareRelational(left, right, operator) {
16594
16728
  }
16595
16729
  }
16596
16730
  function isLooselyEqual(left, right) {
16731
+ if (typeof left === "bigint" || typeof right === "bigint") return left == right;
16597
16732
  const leftType = getCoercionType(left);
16598
16733
  const rightType = getCoercionType(right);
16599
16734
  if (leftType === rightType) {
@@ -16626,6 +16761,7 @@ function isPrimitiveCoercionType(type) {
16626
16761
  return type !== "object";
16627
16762
  }
16628
16763
  function getCoercionType(value) {
16764
+ if (typeof value === "bigint") return "bigint";
16629
16765
  if (typeof value === "symbol") return "symbol";
16630
16766
  if (value === null) {
16631
16767
  return "null";
@@ -16659,6 +16795,7 @@ async function toNumericPrimitive(value, context, hint = "number") {
16659
16795
  throw new TypeError("Expected a sandbox value.");
16660
16796
  }
16661
16797
  function toNumber(value) {
16798
+ if (typeof value === "bigint") throw new TypeError("Cannot convert a BigInt value to a number");
16662
16799
  if (typeof value === "symbol") throw new TypeError("Cannot convert a Symbol value to a number");
16663
16800
  if (isSandboxDate(value)) return dateTime(value);
16664
16801
  if (typeof value === "number") {
@@ -18256,6 +18393,7 @@ function encodeReplayData(value, options = {}) {
18256
18393
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
18257
18394
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
18258
18395
  if (entry === void 0) return { tag: "undefined" };
18396
+ if (typeof entry === "bigint") return { tag: "bigint", value: String(entry) };
18259
18397
  if (typeof entry === "symbol") {
18260
18398
  let id2 = symbols.get(entry);
18261
18399
  if (id2 === void 0) {
@@ -18458,6 +18596,11 @@ function decodeReplayData(input, options = {}, parent) {
18458
18596
  return capability;
18459
18597
  }
18460
18598
  if (own(atom, "tag") === "undefined") return void 0;
18599
+ if (own(atom, "tag") === "bigint") {
18600
+ const value = own(atom, "value");
18601
+ validateBigIntData(value);
18602
+ return BigInt(value);
18603
+ }
18461
18604
  if (atom.tag === "number") {
18462
18605
  switch (own(atom, "value")) {
18463
18606
  case "NaN":
@@ -18527,7 +18670,7 @@ function decodeReplayData(input, options = {}, parent) {
18527
18670
  const payload = own(node, "value");
18528
18671
  const payloadRecord = payload !== null && typeof payload === "object" ? record(payload) : void 0;
18529
18672
  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";
18530
- if (typeof payload !== "number" && typeof payload !== "string" && typeof payload !== "boolean" && !symbolReference && (payload === null || typeof payload !== "object" || own(record(payload), "tag") !== "number"))
18673
+ if (typeof payload !== "number" && typeof payload !== "string" && typeof payload !== "boolean" && !symbolReference && (payload === null || typeof payload !== "object" || !["number", "bigint"].includes(String(own(record(payload), "tag")))))
18531
18674
  throw new TypeError("Invalid boxed primitive payload.");
18532
18675
  const result3 = createSandboxBox(child(payload));
18533
18676
  restored.set(id, result3);
@@ -19278,7 +19421,7 @@ function wrapSandboxClosureForHost(closure, stackFrames, budget, compileOwner, c
19278
19421
  return wrapped;
19279
19422
  }
19280
19423
  function isSandboxLikeValue(value) {
19281
- if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
19424
+ if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") {
19282
19425
  return true;
19283
19426
  }
19284
19427
  if (isSandboxClosure(value) || isSandboxPromise(value)) {
@@ -19343,7 +19486,7 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path) {
19343
19486
  if (options.realm === void 0 || options.errorData || options.hostCalls !== void 0) throw new TypeError("Live capabilities are not portable replay or error data.");
19344
19487
  return importHostCapability(value, options.realm.owner);
19345
19488
  }
19346
- if (value === null || value === void 0 || typeof value === "number" || typeof value === "boolean") {
19489
+ if (value === null || value === void 0 || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") {
19347
19490
  return value;
19348
19491
  }
19349
19492
  if (typeof value === "string") {
@@ -19822,12 +19965,16 @@ function getDatePrototype(value, budget, owner) {
19822
19965
  var defaultStringHook = /* @__PURE__ */ Symbol("defaultStringHook");
19823
19966
  var defaultValueHook = /* @__PURE__ */ Symbol("defaultValueHook");
19824
19967
  var joiningArrays = /* @__PURE__ */ new WeakSet();
19825
- function sandboxNumber(value, budget, context) {
19968
+ function sandboxNumber(value, budget, context, allowBigInt = false) {
19969
+ const convert = (primitive) => {
19970
+ if (typeof primitive === "bigint" && !allowBigInt) throw new TypeError("Cannot convert a BigInt value to a number");
19971
+ return Number(primitive);
19972
+ };
19826
19973
  if (value === null || typeof value !== "object") {
19827
19974
  if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
19828
- return Number(value);
19975
+ return convert(value);
19829
19976
  }
19830
- return objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number").then(Number);
19977
+ return objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number").then(convert);
19831
19978
  }
19832
19979
  function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
19833
19980
  if (typeof value === "symbol") throw new TypeError("Cannot convert a Symbol value to a string");
@@ -21831,6 +21978,10 @@ function measureSandboxData(values, options = {}) {
21831
21978
  const seenSymbols = /* @__PURE__ */ new Set();
21832
21979
  let usage = 0;
21833
21980
  const visit = (value, depth = 0) => {
21981
+ if (typeof value === "bigint") {
21982
+ usage += value.toString(16).length;
21983
+ return;
21984
+ }
21834
21985
  if (typeof value === "symbol") {
21835
21986
  if (!seenSymbols.has(value)) {
21836
21987
  seenSymbols.add(value);
@@ -22503,7 +22654,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
22503
22654
  throw new TypeError(`Unsupported sandbox value at ${path}: ${describeValue2(value)}`);
22504
22655
  }
22505
22656
  function isSandboxPrimitive(value) {
22506
- return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "symbol";
22657
+ return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean" || typeof value === "symbol";
22507
22658
  }
22508
22659
  function isHostPromise(value) {
22509
22660
  return value instanceof Promise;
@@ -24227,6 +24378,7 @@ var KNOWN_RUNTIME_GLOBALS = [
24227
24378
  "AggregateError",
24228
24379
  "Array",
24229
24380
  "Boolean",
24381
+ "BigInt",
24230
24382
  "Date",
24231
24383
  "Error",
24232
24384
  "Infinity",
@@ -27498,6 +27650,7 @@ var ASAsyncNotNeededScanner = class {
27498
27650
  case "MetaProperty":
27499
27651
  case "NullLiteral":
27500
27652
  case "NumericLiteral":
27653
+ case "BigIntLiteral":
27501
27654
  case "RegexLiteral":
27502
27655
  case "StringLiteral":
27503
27656
  case "UndefinedLiteral":
@@ -27779,6 +27932,7 @@ function expressionContainsAwait(node) {
27779
27932
  case "MetaProperty":
27780
27933
  case "NullLiteral":
27781
27934
  case "NumericLiteral":
27935
+ case "BigIntLiteral":
27782
27936
  case "RegexLiteral":
27783
27937
  case "StringLiteral":
27784
27938
  case "ThisExpression":
@@ -31192,6 +31346,7 @@ var ASMissingAsyncScanner = class {
31192
31346
  case "MetaProperty":
31193
31347
  case "NullLiteral":
31194
31348
  case "NumericLiteral":
31349
+ case "BigIntLiteral":
31195
31350
  case "RegexLiteral":
31196
31351
  case "StringLiteral":
31197
31352
  case "UndefinedLiteral":
@@ -31462,6 +31617,7 @@ function expressionContainsAwait2(node) {
31462
31617
  case "MetaProperty":
31463
31618
  case "NullLiteral":
31464
31619
  case "NumericLiteral":
31620
+ case "BigIntLiteral":
31465
31621
  case "RegexLiteral":
31466
31622
  case "StringLiteral":
31467
31623
  case "ThisExpression":
@@ -34955,12 +35111,9 @@ function isStringifyObject(value) {
34955
35111
  return isStringifyContainer(value) && !Array.isArray(value);
34956
35112
  }
34957
35113
  function toSandboxValue(value) {
34958
- if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || isSandboxClosure(value) || isSandboxPromise(value) || Array.isArray(value) || isStringifyContainer(value)) {
35114
+ if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean" || isSandboxClosure(value) || isSandboxPromise(value) || Array.isArray(value) || isStringifyContainer(value)) {
34959
35115
  return value;
34960
35116
  }
34961
- if (typeof value === "bigint") {
34962
- throw new TypeError("Do not know how to serialize a BigInt.");
34963
- }
34964
35117
  throw new TypeError(
34965
35118
  `JSON.stringify(value) produced an unsupported value of type ${typeof value}.`
34966
35119
  );
@@ -35522,6 +35675,100 @@ function createSymbolGlobal(budget) {
35522
35675
  return constructor;
35523
35676
  }
35524
35677
 
35678
+ // packages/safe-js/src/interp/globals/bigint.ts
35679
+ function createBigIntGlobal(budget) {
35680
+ const convert = async (value, context, allowNumber = false) => {
35681
+ const primitive = value !== null && typeof value === "object" ? await objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number") : value;
35682
+ if (typeof primitive === "bigint") return primitive;
35683
+ if (typeof primitive !== "string" && typeof primitive !== "boolean" && !(allowNumber && typeof primitive === "number"))
35684
+ throw new TypeError("Cannot convert value to BigInt.");
35685
+ const size = typeof primitive === "string" ? primitive.length : 256;
35686
+ budget.visitNode(size);
35687
+ const allocation = {};
35688
+ budget.setRetainedDataUsage(allocation, size);
35689
+ try {
35690
+ return BigInt(primitive);
35691
+ } finally {
35692
+ budget.setRetainedDataUsage(allocation, 0);
35693
+ }
35694
+ };
35695
+ const constructor = createSandboxClosure({
35696
+ guest: true,
35697
+ sandbox: true,
35698
+ name: "BigInt",
35699
+ length: 1,
35700
+ call: ([value], context) => convert(value, context, true)
35701
+ });
35702
+ const prototype = /* @__PURE__ */ Object.create(null);
35703
+ Object.defineProperties(prototype, {
35704
+ constructor: { value: constructor, writable: true, configurable: true },
35705
+ valueOf: {
35706
+ value: createSandboxClosure({
35707
+ sandbox: true,
35708
+ name: "valueOf",
35709
+ length: 0,
35710
+ call: (_args, context) => primitiveReceiver(context?.thisValue, "bigint")
35711
+ }),
35712
+ writable: true,
35713
+ configurable: true
35714
+ },
35715
+ toString: {
35716
+ value: createSandboxClosure({
35717
+ sandbox: true,
35718
+ name: "toString",
35719
+ length: 1,
35720
+ call: async ([radix], context) => {
35721
+ const value = primitiveReceiver(context?.thisValue, "bigint");
35722
+ const base = radix === void 0 ? 10 : await sandboxNumber(radix, budget, context);
35723
+ const allocation = {};
35724
+ const size = value.toString(16).length * 4;
35725
+ budget.visitNode(size);
35726
+ budget.setRetainedDataUsage(allocation, size);
35727
+ try {
35728
+ return budget.allocateString(value.toString(base));
35729
+ } finally {
35730
+ budget.setRetainedDataUsage(allocation, 0);
35731
+ }
35732
+ }
35733
+ }),
35734
+ writable: true,
35735
+ configurable: true
35736
+ },
35737
+ [Symbol.toStringTag]: { value: "BigInt", configurable: true }
35738
+ });
35739
+ const properties = materializeFunctionProperties(constructor);
35740
+ Object.defineProperty(properties, "prototype", { value: prototype });
35741
+ for (const name of ["asIntN", "asUintN"]) {
35742
+ Object.defineProperty(properties, name, {
35743
+ writable: true,
35744
+ configurable: true,
35745
+ value: createSandboxClosure({
35746
+ sandbox: true,
35747
+ name,
35748
+ length: 2,
35749
+ call: async ([bits, input], context) => {
35750
+ const number = await sandboxNumber(bits, budget, context);
35751
+ const width = Number.isNaN(number) ? 0 : Math.trunc(number);
35752
+ if (width < 0 || !Number.isSafeInteger(width)) throw new RangeError("Invalid BigInt width.");
35753
+ const value = await convert(input, context);
35754
+ const size = value.toString(16).length;
35755
+ budget.visitNode(size);
35756
+ if (width >= size * 4 + 1 && (name === "asIntN" || value >= 0n)) return value;
35757
+ const allocation = {};
35758
+ budget.setRetainedDataUsage(allocation, Math.ceil(width / 4) + 1);
35759
+ try {
35760
+ return BigInt[name](width, value);
35761
+ } finally {
35762
+ budget.setRetainedDataUsage(allocation, 0);
35763
+ }
35764
+ }
35765
+ })
35766
+ });
35767
+ }
35768
+ installBoxedPrototype(budget, prototype, constructor, "bigint");
35769
+ return constructor;
35770
+ }
35771
+
35525
35772
  // packages/safe-js/src/interp/globals.ts
35526
35773
  function createBuiltinBindings(options) {
35527
35774
  return {
@@ -35530,6 +35777,7 @@ function createBuiltinBindings(options) {
35530
35777
  Float32Array: createFloat32ArrayGlobal(options.budget),
35531
35778
  Date: createDateGlobal(options),
35532
35779
  Symbol: createSymbolGlobal(options.budget),
35780
+ BigInt: createBigIntGlobal(options.budget),
35533
35781
  ...createErrorGlobals(options),
35534
35782
  ...createMathGlobals({ random: options.random }),
35535
35783
  ...createObjectArrayGlobals(options),
@@ -37656,4 +37904,4 @@ export {
37656
37904
  FileSnapshotBackend,
37657
37905
  run
37658
37906
  };
37659
- //# sourceMappingURL=chunk-EOTY4PCT.js.map
37907
+ //# sourceMappingURL=chunk-YWQDSWZN.js.map