poe-code 14.0.74 → 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.
Files changed (65) hide show
  1. package/dist/index.js +1283 -144
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-js/dist/chunks/{chunk-YEZOXLY4.js → chunk-UZYQWFMY.js} +1233 -143
  6. package/packages/safe-js/dist/chunks/chunk-UZYQWFMY.js.map +7 -0
  7. package/packages/safe-js/dist/chunks/{chunk-2J6W3YGB.js → chunk-VD2AS4E4.js} +2 -2
  8. package/packages/safe-js/dist/cli.js +2 -2
  9. package/packages/safe-js/dist/core.js +1 -1
  10. package/packages/safe-js/dist/index.js +2 -2
  11. package/packages/safe-js/dist/index.js.map +1 -1
  12. package/packages/safe-js/dist/interp/bigint-operators.d.ts +3 -0
  13. package/packages/safe-js/dist/interp/bigint-operators.js +62 -0
  14. package/packages/safe-js/dist/interp/boxed.d.ts +2 -2
  15. package/packages/safe-js/dist/interp/boxed.js +4 -1
  16. package/packages/safe-js/dist/interp/globals/bigint.d.ts +2 -0
  17. package/packages/safe-js/dist/interp/globals/bigint.js +85 -0
  18. package/packages/safe-js/dist/interp/globals/console-json.js +57 -24
  19. package/packages/safe-js/dist/interp/globals/object-array.js +1 -1
  20. package/packages/safe-js/dist/interp/globals/regex.js +108 -2
  21. package/packages/safe-js/dist/interp/globals.d.ts +1 -0
  22. package/packages/safe-js/dist/interp/globals.js +2 -0
  23. package/packages/safe-js/dist/interp/host-bridge.js +2 -0
  24. package/packages/safe-js/dist/interp/interpreter.js +59 -12
  25. package/packages/safe-js/dist/interp/iteration.js +5 -2
  26. package/packages/safe-js/dist/interp/methods/number.js +1 -1
  27. package/packages/safe-js/dist/interp/methods/regex-split.d.ts +3 -0
  28. package/packages/safe-js/dist/interp/methods/regex-split.js +102 -0
  29. package/packages/safe-js/dist/interp/methods/regex.d.ts +1 -1
  30. package/packages/safe-js/dist/interp/methods/regex.js +16 -5
  31. package/packages/safe-js/dist/interp/methods/regexp-iterator.d.ts +5 -1
  32. package/packages/safe-js/dist/interp/methods/regexp-iterator.js +59 -7
  33. package/packages/safe-js/dist/interp/methods/string.js +9 -9
  34. package/packages/safe-js/dist/interp/object-model.d.ts +1 -0
  35. package/packages/safe-js/dist/interp/object-model.js +4 -1
  36. package/packages/safe-js/dist/interp/regex/compile-guard.js +26 -4
  37. package/packages/safe-js/dist/interp/regex/engine.d.ts +4 -0
  38. package/packages/safe-js/dist/interp/regex/engine.js +230 -30
  39. package/packages/safe-js/dist/interp/regex/parse.d.ts +42 -4
  40. package/packages/safe-js/dist/interp/regex/parse.js +429 -25
  41. package/packages/safe-js/dist/interp/regexp-iterator.d.ts +4 -2
  42. package/packages/safe-js/dist/interp/regexp-iterator.js +6 -1
  43. package/packages/safe-js/dist/interp/string-coercion.d.ts +1 -1
  44. package/packages/safe-js/dist/interp/string-coercion.js +8 -3
  45. package/packages/safe-js/dist/interp/values.d.ts +1 -1
  46. package/packages/safe-js/dist/interp/values.js +10 -3
  47. package/packages/safe-js/dist/lint/rules/AS-async-not-needed.js +2 -0
  48. package/packages/safe-js/dist/lint/rules/AS-missing-async.js +2 -0
  49. package/packages/safe-js/dist/lint/rules/known-globals.d.ts +1 -1
  50. package/packages/safe-js/dist/lint/rules/known-globals.js +1 -0
  51. package/packages/safe-js/dist/parse/parser.d.ts +6 -1
  52. package/packages/safe-js/dist/parse/parser.js +8 -0
  53. package/packages/safe-js/dist/parse/tokenizer.js +12 -4
  54. package/packages/safe-js/dist/parse.d.ts +1 -1
  55. package/packages/safe-js/dist/snapshot/bigint.d.ts +1 -0
  56. package/packages/safe-js/dist/snapshot/bigint.js +14 -0
  57. package/packages/safe-js/dist/snapshot/dump-format.js +12 -2
  58. package/packages/safe-js/dist/snapshot/replay-data.d.ts +6 -0
  59. package/packages/safe-js/dist/snapshot/replay-data.js +23 -5
  60. package/packages/safe-js/dist/snapshot/restore.js +10 -2
  61. package/packages/safe-js/dist/snapshot/serialize.d.ts +4 -1
  62. package/packages/safe-js/dist/snapshot/serialize.js +6 -1
  63. package/packages/safe-js/dist/snapshot/validation.js +27 -0
  64. package/packages/safe-js/dist/chunks/chunk-YEZOXLY4.js.map +0 -7
  65. /package/packages/safe-js/dist/chunks/{chunk-2J6W3YGB.js.map → chunk-VD2AS4E4.js.map} +0 -0
package/dist/index.js CHANGED
@@ -120228,7 +120228,15 @@ var init_budget2 = __esm({
120228
120228
 
120229
120229
  // packages/safe-js/src/interp/regex/compile-guard.ts
120230
120230
  function regexCompiledData(pattern) {
120231
- return compiledData.get(pattern) ?? { units: 10 + pattern.source.length + measureNode(pattern.body) };
120231
+ return compiledData.get(pattern) ?? { units: measurePattern(pattern) };
120232
+ }
120233
+ function measurePattern(pattern) {
120234
+ let units = 10 + pattern.source.length + measureNode(pattern.body);
120235
+ if (pattern.groups !== void 0) {
120236
+ units += 1;
120237
+ for (const [name, indices] of Object.entries(pattern.groups)) units += name.length + 2 + indices.length;
120238
+ }
120239
+ return units;
120232
120240
  }
120233
120241
  function measureNode(node) {
120234
120242
  switch (node.type) {
@@ -120237,13 +120245,18 @@ function measureNode(node) {
120237
120245
  return 2;
120238
120246
  case "literal":
120239
120247
  return 3 + node.value.length;
120248
+ case "namedBackreference":
120249
+ return 3 + node.name.length;
120240
120250
  case "anchor":
120241
120251
  case "wordBoundary":
120252
+ case "backreference":
120242
120253
  return 3;
120243
120254
  case "characterClass": {
120244
120255
  let usage = 5 + node.items.length;
120256
+ if (node.operation !== void 0) usage += 1 + node.operation.length;
120257
+ if (node.strings !== void 0) usage += 1;
120245
120258
  for (const item of node.items) {
120246
- usage += item.type === "character" ? 3 + item.value.length : item.type === "range" ? 4 + item.from.length + item.to.length : 4;
120259
+ usage += item.type === "character" ? 3 + item.value.length : item.type === "range" ? 4 + item.from.length + item.to.length : item.type === "property" ? 4 + item.value.length + (item.strings === void 0 ? 0 : 1) : item.type === "set" ? 3 + measureNode({ type: "characterClass", ...item.value }) : item.type === "strings" ? 4 + item.values.reduce((total2, value) => total2 + 1 + value.length, 0) : 4;
120247
120260
  }
120248
120261
  return usage;
120249
120262
  }
@@ -120255,7 +120268,10 @@ function measureNode(node) {
120255
120268
  return usage;
120256
120269
  }
120257
120270
  case "group":
120258
- return 5 + measureNode(node.body);
120271
+ return 5 + measureNode(node.body) + (node.name === void 0 ? 0 : 1 + node.name.length) + (node.modifiers === void 0 ? 0 : 2 + Object.keys(node.modifiers).length);
120272
+ case "lookahead":
120273
+ case "lookbehind":
120274
+ return 4 + measureNode(node.body);
120259
120275
  case "quantifier":
120260
120276
  return (Object.hasOwn(node, "max") ? 6 : 5) + measureNode(node.body);
120261
120277
  }
@@ -120374,7 +120390,7 @@ var init_compile_guard = __esm({
120374
120390
  this.work(flags.length);
120375
120391
  }
120376
120392
  retain(pattern, valueUnits = 0) {
120377
- const units = 10 + pattern.source.length + measureNode(pattern.body);
120393
+ const units = measurePattern(pattern);
120378
120394
  if (this.ticket !== void 0) {
120379
120395
  this.ticket.owner.budget.resizeCompileTicket(this.ticket, units + valueUnits);
120380
120396
  }
@@ -120962,7 +120978,7 @@ var init_tokenizer2 = __esm({
120962
120978
  this.advance();
120963
120979
  this.advance();
120964
120980
  this.consumeDigitsForBase(isHexDigit, "hexadecimal");
120965
- this.rejectBigIntSuffix();
120981
+ if (this.currentChar() === "n") this.advance();
120966
120982
  this.rejectInvalidNumericLiteralContinuation();
120967
120983
  return this.source.slice(start.offset, this.index);
120968
120984
  }
@@ -120970,7 +120986,7 @@ var init_tokenizer2 = __esm({
120970
120986
  this.advance();
120971
120987
  this.advance();
120972
120988
  this.consumeDigitsForBase(isBinaryDigit, "binary");
120973
- this.rejectBigIntSuffix();
120989
+ if (this.currentChar() === "n") this.advance();
120974
120990
  this.rejectInvalidNumericLiteralContinuation();
120975
120991
  return this.source.slice(start.offset, this.index);
120976
120992
  }
@@ -120978,7 +120994,7 @@ var init_tokenizer2 = __esm({
120978
120994
  this.advance();
120979
120995
  this.advance();
120980
120996
  this.consumeDigitsForBase(isOctalDigit, "octal");
120981
- this.rejectBigIntSuffix();
120997
+ if (this.currentChar() === "n") this.advance();
120982
120998
  this.rejectInvalidNumericLiteralContinuation();
120983
120999
  return this.source.slice(start.offset, this.index);
120984
121000
  }
@@ -120992,6 +121008,11 @@ var init_tokenizer2 = __esm({
120992
121008
  }
120993
121009
  }
120994
121010
  this.consumeDecimalDigits();
121011
+ if (this.currentChar() === "n") {
121012
+ this.advance();
121013
+ this.rejectInvalidNumericLiteralContinuation();
121014
+ return this.source.slice(start.offset, this.index);
121015
+ }
120995
121016
  if (this.currentChar() === "." && (this.peekChar(1) !== "." || this.peekChar(2) !== ".")) {
120996
121017
  this.advance();
120997
121018
  this.consumeOptionalDecimalDigits();
@@ -121090,7 +121111,7 @@ var init_tokenizer2 = __esm({
121090
121111
  }
121091
121112
  rejectBigIntSuffix() {
121092
121113
  if (this.currentChar() === "n") {
121093
- this.syntaxError("BigInt not supported", this.position());
121114
+ this.syntaxError("BigInt literals cannot contain a fraction or exponent", this.position());
121094
121115
  }
121095
121116
  }
121096
121117
  rejectInvalidNumericLiteralContinuation() {
@@ -121719,10 +121740,11 @@ function parseRegex(source, flags = "", compilation, valueUnits = 0) {
121719
121740
  guard.checkLength(flags.length, true);
121720
121741
  guard.allocate(5 + valueUnits);
121721
121742
  const parsedFlags = parseFlags(flags, guard);
121722
- const parser = new RegexParser(source, guard);
121743
+ const parser = new RegexParser(source, guard, parsedFlags.unicode || parsedFlags.unicodeSets, parsedFlags.unicodeSets);
121723
121744
  const body = parser.parse();
121724
121745
  guard.allocate(5 + source.length);
121725
121746
  const pattern = { source, flags: parsedFlags, captureCount: parser.captureCount, body };
121747
+ if (Object.keys(parser.namedGroups).length > 0) pattern.groups = parser.namedGroups;
121726
121748
  guard.retain(pattern, valueUnits);
121727
121749
  return pattern;
121728
121750
  } finally {
@@ -121732,16 +121754,24 @@ function parseRegex(source, flags = "", compilation, valueUnits = 0) {
121732
121754
  function parseFlags(flags, guard) {
121733
121755
  guard.allocate(10);
121734
121756
  const parsed = {
121757
+ hasIndices: false,
121735
121758
  global: false,
121759
+ sticky: false,
121760
+ unicode: false,
121761
+ unicodeSets: false,
121736
121762
  ignoreCase: false,
121737
121763
  multiline: false,
121738
121764
  dotAll: false
121739
121765
  };
121740
121766
  const names = {
121767
+ d: "hasIndices",
121741
121768
  g: "global",
121742
121769
  i: "ignoreCase",
121743
121770
  m: "multiline",
121744
- s: "dotAll"
121771
+ s: "dotAll",
121772
+ y: "sticky",
121773
+ u: "unicode",
121774
+ v: "unicodeSets"
121745
121775
  };
121746
121776
  for (let position = 0; position < flags.length; position += 1) {
121747
121777
  guard.work(1);
@@ -121755,6 +121785,7 @@ function parseFlags(flags, guard) {
121755
121785
  }
121756
121786
  parsed[name] = true;
121757
121787
  }
121788
+ if (parsed.unicode && parsed.unicodeSets) throw new SyntaxError("Unicode flags u and v cannot be combined");
121758
121789
  return parsed;
121759
121790
  }
121760
121791
  function isDecimalDigit2(character2) {
@@ -121768,20 +121799,29 @@ function allHexDigits(value) {
121768
121799
  }
121769
121800
  return true;
121770
121801
  }
121771
- var RegexParser;
121802
+ var groupNameStart, groupNamePart, RegexParser;
121772
121803
  var init_parse5 = __esm({
121773
121804
  "packages/safe-js/src/interp/regex/parse.ts"() {
121774
121805
  "use strict";
121775
121806
  init_compile_guard();
121807
+ groupNameStart = /^[$_\p{ID_Start}]$/u;
121808
+ groupNamePart = /^[$\u200c\u200d\p{ID_Continue}]$/u;
121776
121809
  RegexParser = class {
121777
- constructor(source, guard) {
121810
+ constructor(source, guard, unicode, unicodeSets) {
121778
121811
  this.source = source;
121779
121812
  this.guard = guard;
121813
+ this.unicode = unicode;
121814
+ this.unicodeSets = unicodeSets;
121780
121815
  }
121781
121816
  source;
121782
121817
  guard;
121818
+ unicode;
121819
+ unicodeSets;
121783
121820
  captureCount = 0;
121784
121821
  cursor = 0;
121822
+ totalCaptureCount;
121823
+ hasNamedCaptures = false;
121824
+ namedGroups = /* @__PURE__ */ Object.create(null);
121785
121825
  get position() {
121786
121826
  return this.cursor;
121787
121827
  }
@@ -121797,6 +121837,7 @@ var init_parse5 = __esm({
121797
121837
  }
121798
121838
  this.fail(`Unexpected character '${this.peek()}'`);
121799
121839
  }
121840
+ if (this.unicode || Object.keys(this.namedGroups).length > 0) this.validateNamedGroups(body);
121800
121841
  return body;
121801
121842
  }
121802
121843
  parseAlternation() {
@@ -121830,15 +121871,20 @@ var init_parse5 = __esm({
121830
121871
  parseQuantifiedAtom() {
121831
121872
  const quantifierStart = this.position;
121832
121873
  const current = this.peek();
121833
- if (current === "*" || current === "+" || current === "?" || current === "{") {
121874
+ if (current === "*" || current === "+" || current === "?" || current === "{" && this.unicode) {
121834
121875
  this.fail("Nothing to repeat", quantifierStart);
121835
121876
  }
121877
+ if (current === "{") {
121878
+ const quantifier2 = this.parseQuantifier();
121879
+ this.position = quantifierStart;
121880
+ if (quantifier2 !== void 0) this.fail("Nothing to repeat", quantifierStart);
121881
+ }
121836
121882
  const body = this.parseAtom();
121837
121883
  const quantifier = this.parseQuantifier();
121838
121884
  if (quantifier === void 0) {
121839
121885
  return body;
121840
121886
  }
121841
- if (body.type === "anchor" || body.type === "wordBoundary") {
121887
+ if (body.type === "anchor" || body.type === "wordBoundary" || body.type === "lookbehind" || this.unicode && body.type === "lookahead") {
121842
121888
  this.fail("Invalid quantifier target", quantifierStart);
121843
121889
  }
121844
121890
  const greedy = this.peek() !== "?";
@@ -121849,7 +121895,7 @@ var init_parse5 = __esm({
121849
121895
  return { type: "quantifier", body, ...quantifier, greedy };
121850
121896
  }
121851
121897
  parseAtom() {
121852
- const character2 = this.take();
121898
+ const character2 = this.takeCharacter();
121853
121899
  switch (character2) {
121854
121900
  case ".":
121855
121901
  this.guard.allocate(2);
@@ -121867,12 +121913,17 @@ var init_parse5 = __esm({
121867
121913
  case "\\":
121868
121914
  return this.parseEscape(false, this.position - 1);
121869
121915
  default:
121916
+ if (this.unicode && (character2 === "]" || character2 === "}")) this.fail("Invalid Unicode pattern character");
121870
121917
  this.guard.allocate(3 + character2.length);
121871
121918
  return { type: "literal", value: character2 };
121872
121919
  }
121873
121920
  }
121874
121921
  parseGroup(start) {
121875
121922
  let capturing = true;
121923
+ let name;
121924
+ let modifiers;
121925
+ let assertionNegated;
121926
+ let lookbehind = false;
121876
121927
  if (this.peek() === "?") {
121877
121928
  this.guard.allocate(Math.min(3, this.source.length - this.position));
121878
121929
  this.guard.work(Math.min(3, this.source.length - this.position));
@@ -121881,17 +121932,33 @@ var init_parse5 = __esm({
121881
121932
  capturing = false;
121882
121933
  this.position += 2;
121883
121934
  } else if (extension.startsWith("?=") || extension.startsWith("?!")) {
121884
- this.fail("Lookahead is not supported", start);
121935
+ capturing = false;
121936
+ assertionNegated = extension.startsWith("?!");
121937
+ this.position += 2;
121885
121938
  } else if (extension.startsWith("?<=") || extension.startsWith("?<!")) {
121886
- this.fail("Lookbehind is not supported", start);
121939
+ capturing = false;
121940
+ assertionNegated = extension.startsWith("?<!");
121941
+ lookbehind = true;
121942
+ this.position += 3;
121887
121943
  } else if (extension.startsWith("?<")) {
121888
- this.fail("Named groups are not supported", start);
121944
+ this.position += 2;
121945
+ name = this.parseGroupName(start);
121946
+ } else if ("ims-".includes(extension[1] ?? "") && extension.length > 1) {
121947
+ capturing = false;
121948
+ this.position++;
121949
+ modifiers = this.parseModifiers(start);
121889
121950
  } else {
121890
121951
  this.fail("Unsupported group construct", start);
121891
121952
  }
121892
121953
  }
121893
121954
  if (capturing) this.guard.allocate(1);
121894
121955
  const index = capturing ? ++this.captureCount : void 0;
121956
+ if (name !== void 0) {
121957
+ this.guard.allocate(name.length + 2);
121958
+ const indices = this.namedGroups[name] ??= [];
121959
+ this.guard.array(indices.length + 1);
121960
+ indices.push(index);
121961
+ }
121895
121962
  this.guard.enterGroup();
121896
121963
  let body;
121897
121964
  try {
@@ -121903,10 +121970,40 @@ var init_parse5 = __esm({
121903
121970
  this.fail("Unterminated group", start);
121904
121971
  }
121905
121972
  this.position += 1;
121973
+ if (assertionNegated !== void 0) {
121974
+ this.guard.allocate(4);
121975
+ return { type: lookbehind ? "lookbehind" : "lookahead", negated: assertionNegated, body };
121976
+ }
121906
121977
  this.guard.allocate(5);
121907
- return { type: "group", capturing, index, body };
121978
+ return {
121979
+ type: "group",
121980
+ capturing,
121981
+ index,
121982
+ body,
121983
+ ...name === void 0 ? {} : { name },
121984
+ ...modifiers === void 0 ? {} : { modifiers }
121985
+ };
121986
+ }
121987
+ parseModifiers(start) {
121988
+ this.guard.allocate(2);
121989
+ const modifiers = {};
121990
+ let enabled = true;
121991
+ while (!this.atEnd() && this.peek() !== ":") {
121992
+ const flag = this.take();
121993
+ if (flag === "-" && enabled) {
121994
+ enabled = false;
121995
+ continue;
121996
+ }
121997
+ const name = flag === "i" ? "ignoreCase" : flag === "m" ? "multiline" : flag === "s" ? "dotAll" : void 0;
121998
+ if (name === void 0 || Object.hasOwn(modifiers, name)) this.fail("Invalid regex modifiers", start);
121999
+ this.guard.allocate(1);
122000
+ modifiers[name] = enabled;
122001
+ }
122002
+ if (this.take() !== ":" || Object.keys(modifiers).length === 0) this.fail("Invalid regex modifiers", start);
122003
+ return modifiers;
121908
122004
  }
121909
122005
  parseCharacterClass(start) {
122006
+ if (this.unicodeSets) return { type: "characterClass", ...this.parseUnicodeSet(start) };
121910
122007
  const negated = this.peek() === "^";
121911
122008
  if (negated) {
121912
122009
  this.position += 1;
@@ -121926,9 +122023,13 @@ var init_parse5 = __esm({
121926
122023
  this.position += 1;
121927
122024
  const right = this.parseClassItem(start);
121928
122025
  if (left.type !== "character" || right.type !== "character") {
121929
- this.fail("Character class ranges require literal endpoints", rangePosition);
122026
+ if (this.unicode) this.fail("Character class ranges require literal endpoints", rangePosition);
122027
+ this.guard.array(items.length + 3);
122028
+ this.guard.allocate(4);
122029
+ items.push(left, { type: "character", value: "-" }, right);
122030
+ continue;
121930
122031
  }
121931
- if (left.value.charCodeAt(0) > right.value.charCodeAt(0)) {
122032
+ if (left.value.codePointAt(0) > right.value.codePointAt(0)) {
121932
122033
  this.fail("Character class range is out of order", rangePosition);
121933
122034
  }
121934
122035
  this.guard.allocate(4 + left.value.length + right.value.length);
@@ -121957,26 +122058,193 @@ var init_parse5 = __esm({
121957
122058
  this.fail("Unsupported character class escape", escapeStart);
121958
122059
  }
121959
122060
  this.guard.allocate(4);
121960
- return { type: "character", value: this.take() };
122061
+ return { type: "character", value: this.takeCharacter() };
122062
+ }
122063
+ parseUnicodeSet(start) {
122064
+ this.guard.enterGroup();
122065
+ try {
122066
+ const negated = this.peek() === "^";
122067
+ if (negated) this.position++;
122068
+ this.guard.allocate(5);
122069
+ const items = [];
122070
+ let operation;
122071
+ while (!this.atEnd() && this.peek() !== "]") {
122072
+ this.guard.array(items.length + 1);
122073
+ let item = this.parseUnicodeSetItem(start);
122074
+ if (this.peek() === "-" && this.source[this.position + 1] !== "-") {
122075
+ this.position++;
122076
+ const right = this.parseUnicodeSetItem(start);
122077
+ if (item.type !== "character" || right.type !== "character") this.fail("Invalid set range", start);
122078
+ if (item.value.codePointAt(0) > right.value.codePointAt(0)) this.fail("Set range is out of order", start);
122079
+ this.guard.allocate(4 + item.value.length + right.value.length);
122080
+ item = { type: "range", from: item.value, to: right.value };
122081
+ }
122082
+ if (operation !== void 0 && item.type === "range") this.fail("Set operations require nested ranges", start);
122083
+ items.push(item);
122084
+ const operator = this.source.slice(this.position, this.position + 2);
122085
+ if (operator === "&&" || operator === "--") {
122086
+ const next = operator === "&&" ? "intersection" : "subtraction";
122087
+ if (operation === void 0 && (items.length !== 1 || item.type === "range") || operation !== void 0 && operation !== next) this.fail("Mixed set operations", start);
122088
+ if (operation === void 0) this.guard.allocate(1 + next.length);
122089
+ operation = next;
122090
+ this.position += 2;
122091
+ if (this.peek() === "]" || this.atEnd()) this.fail("Missing set operand", start);
122092
+ } else if (operation !== void 0 && this.peek() !== "]") this.fail("Missing set operator", start);
122093
+ }
122094
+ if (this.take() !== "]") this.fail("Unterminated character set", start);
122095
+ const mayContainStrings = (item) => {
122096
+ if (item.type === "set") return item.value.strings === true;
122097
+ if (item.type === "property") return item.strings === true;
122098
+ if (item.type === "strings") return item.values.some((value) => value.length !== ((value.codePointAt(0) ?? 0) > 65535 ? 2 : 1));
122099
+ return false;
122100
+ };
122101
+ const strings = operation === "intersection" ? items.every(mayContainStrings) : operation === "subtraction" ? mayContainStrings(items[0]) : items.some(mayContainStrings);
122102
+ if (negated && strings) this.fail("Cannot complement a set containing strings", start);
122103
+ if (strings) this.guard.allocate(1);
122104
+ return { negated, items, ...operation === void 0 ? {} : { operation }, ...strings ? { strings: true } : {} };
122105
+ } finally {
122106
+ this.guard.leaveGroup();
122107
+ }
122108
+ }
122109
+ parseUnicodeSetItem(start) {
122110
+ if (this.peek() === "[") {
122111
+ this.position++;
122112
+ this.guard.allocate(3);
122113
+ return { type: "set", value: this.parseUnicodeSet(start) };
122114
+ }
122115
+ if (this.source.startsWith("\\q{", this.position)) {
122116
+ this.position += 3;
122117
+ this.guard.allocate(4);
122118
+ const values = [];
122119
+ let value2 = "";
122120
+ while (!this.atEnd()) {
122121
+ if (this.peek() === "|" || this.peek() === "}") {
122122
+ this.guard.array(values.length + 1);
122123
+ this.guard.allocate(1);
122124
+ values.push(value2);
122125
+ value2 = "";
122126
+ if (this.take() === "}") return { type: "strings", values };
122127
+ } else {
122128
+ const item = this.parseSetCharacter(start);
122129
+ this.guard.allocate(item.length);
122130
+ value2 += item;
122131
+ }
122132
+ }
122133
+ this.fail("Unterminated class string", start);
122134
+ }
122135
+ if (this.peek() === "\\") return this.parseClassItem(start);
122136
+ const value = this.parseSetCharacter(start);
122137
+ this.guard.allocate(3 + value.length);
122138
+ return { type: "character", value };
122139
+ }
122140
+ parseSetCharacter(start) {
122141
+ if (this.peek() === "\\") {
122142
+ this.position++;
122143
+ const node = this.parseEscape(true, start);
122144
+ if (node.type !== "literal") this.fail("Class strings require literal characters", start);
122145
+ return node.value;
122146
+ }
122147
+ const character2 = this.takeCharacter();
122148
+ if (!character2 || "()[]{}/-|".includes(character2) || "!#$%&*+,.:;<=>?@^`~".includes(character2) && this.peek() === character2)
122149
+ this.fail("Invalid character in Unicode set", start);
122150
+ return character2;
121961
122151
  }
121962
122152
  parseEscape(inCharacterClass, start) {
121963
122153
  if (this.atEnd()) {
121964
122154
  this.fail("Trailing escape", start);
121965
122155
  }
121966
122156
  const escaped = this.take();
121967
- if (escaped >= "1" && escaped <= "9") {
121968
- this.fail("Backreferences are not supported", start);
121969
- }
121970
- if (escaped === "p" || escaped === "P") {
121971
- this.fail("Unicode property escapes are not supported", start);
122157
+ if (escaped === "k") {
122158
+ this.totalCaptureCount ??= this.countAllCaptures();
122159
+ if (this.unicode || this.hasNamedCaptures) {
122160
+ if (inCharacterClass || this.take() !== "<") this.fail("Invalid named backreference", start);
122161
+ const name = this.parseGroupName(start);
122162
+ this.guard.allocate(3 + name.length);
122163
+ return { type: "namedBackreference", name };
122164
+ }
122165
+ }
122166
+ if (isDecimalDigit2(escaped)) {
122167
+ if (!inCharacterClass && escaped !== "0") {
122168
+ let end = this.position;
122169
+ let index = Number(escaped);
122170
+ while (isDecimalDigit2(this.source[end] ?? "")) {
122171
+ this.guard.work(1);
122172
+ index = index * 10 + Number(this.source[end++]);
122173
+ }
122174
+ this.totalCaptureCount ??= this.countAllCaptures();
122175
+ if (index <= this.totalCaptureCount) {
122176
+ this.position = end;
122177
+ this.guard.allocate(3);
122178
+ return { type: "backreference", index };
122179
+ }
122180
+ }
122181
+ if (this.unicode && (escaped !== "0" || isDecimalDigit2(this.peek())))
122182
+ this.fail("Invalid decimal escape", start);
122183
+ this.guard.allocate(4);
122184
+ if (escaped === "8" || escaped === "9") return { type: "literal", value: escaped };
122185
+ let code = Number(escaped);
122186
+ const maximum = escaped <= "3" ? 3 : 2;
122187
+ for (let digits = 1; digits < maximum && this.peek() >= "0" && this.peek() <= "7"; digits++) {
122188
+ code = code * 8 + Number(this.take());
122189
+ }
122190
+ return { type: "literal", value: String.fromCharCode(code) };
122191
+ }
122192
+ if (this.unicode && (escaped === "p" || escaped === "P")) {
122193
+ if (this.take() !== "{") this.fail("Invalid Unicode property escape", start);
122194
+ const begin = this.position;
122195
+ while (!this.atEnd() && this.peek() !== "}") {
122196
+ const character2 = this.take();
122197
+ if (!isDecimalDigit2(character2) && !(character2 >= "a" && character2 <= "z") && !(character2 >= "A" && character2 <= "Z") && character2 !== "_" && character2 !== "=")
122198
+ this.fail("Invalid Unicode property escape", start);
122199
+ }
122200
+ this.guard.allocate(this.position - begin + 9);
122201
+ const value = this.source.slice(begin, this.position);
122202
+ if (this.take() !== "}") this.fail("Unterminated Unicode property escape", start);
122203
+ try {
122204
+ new RegExp(`\\${escaped}{${value}}`, this.unicodeSets ? "v" : "u");
122205
+ } catch {
122206
+ this.fail("Unknown Unicode property", start);
122207
+ }
122208
+ let strings = false;
122209
+ if (this.unicodeSets) {
122210
+ try {
122211
+ new RegExp(`\\p{${value}}`, "u");
122212
+ } catch {
122213
+ strings = true;
122214
+ }
122215
+ }
122216
+ this.guard.array(1);
122217
+ return { type: "characterClass", negated: false, items: [{ type: "property", value, negated: escaped === "P", ...strings ? { strings: true } : {} }] };
121972
122218
  }
121973
122219
  if (escaped === "x") {
121974
122220
  this.guard.allocate(4);
121975
- return { type: "literal", value: this.parseHexEscape(2, "hexadecimal", start) };
122221
+ return { type: "literal", value: this.parseHexEscape(2, "hexadecimal", start, this.unicode ? void 0 : "x") };
121976
122222
  }
121977
122223
  if (escaped === "u") {
121978
122224
  this.guard.allocate(4);
121979
- return { type: "literal", value: this.parseHexEscape(4, "Unicode", start) };
122225
+ if (this.unicode && this.peek() === "{") {
122226
+ this.position++;
122227
+ const begin = this.position;
122228
+ while (!this.atEnd() && this.peek() !== "}") this.position++;
122229
+ this.guard.allocate(this.position - begin);
122230
+ const digits = this.source.slice(begin, this.position);
122231
+ const point = Number.parseInt(digits, 16);
122232
+ if (this.take() !== "}" || digits.length === 0 || !allHexDigits(digits) || point > 1114111)
122233
+ this.fail("Invalid Unicode escape", start);
122234
+ return { type: "literal", value: String.fromCodePoint(point) };
122235
+ }
122236
+ let value = this.parseHexEscape(4, "Unicode", start, this.unicode ? void 0 : "u");
122237
+ if (this.unicode && value.charCodeAt(0) >= 55296 && value.charCodeAt(0) <= 56319 && this.source.startsWith("\\u", this.position)) {
122238
+ const digits = this.source.slice(this.position + 2, this.position + 6);
122239
+ const point = Number.parseInt(digits, 16);
122240
+ this.guard.work(digits.length);
122241
+ this.guard.allocate(digits.length);
122242
+ if (digits.length === 4 && allHexDigits(digits) && point >= 56320 && point <= 57343) {
122243
+ value += String.fromCharCode(point);
122244
+ this.position += 6;
122245
+ }
122246
+ }
122247
+ return { type: "literal", value };
121980
122248
  }
121981
122249
  this.guard.allocate(25);
121982
122250
  const kinds = {
@@ -122007,20 +122275,101 @@ var init_parse5 = __esm({
122007
122275
  v: "\v",
122008
122276
  "0": "\0"
122009
122277
  };
122278
+ if (escaped === "c") {
122279
+ const letter = this.peek();
122280
+ this.guard.allocate(4);
122281
+ if (letter >= "a" && letter <= "z" || letter >= "A" && letter <= "Z" || !this.unicode && inCharacterClass && (isDecimalDigit2(letter) || letter === "_")) {
122282
+ this.position++;
122283
+ return { type: "literal", value: String.fromCharCode(letter.charCodeAt(0) % 32) };
122284
+ }
122285
+ if (this.unicode) this.fail("Invalid control escape", start);
122286
+ this.position--;
122287
+ return { type: "literal", value: "\\" };
122288
+ }
122289
+ if (this.unicode && controls[escaped] === void 0 && !"^$\\.*+?()[]{}|/".includes(escaped) && !(inCharacterClass && (escaped === "-" || this.unicodeSets && "!#$%&+,.:;<=>?@`~".includes(escaped))))
122290
+ this.fail("Invalid identity escape", start);
122010
122291
  this.guard.allocate(4);
122011
122292
  return { type: "literal", value: controls[escaped] ?? escaped };
122012
122293
  }
122013
- parseHexEscape(length, name, start) {
122294
+ parseHexEscape(length, name, start, identity) {
122014
122295
  const end = this.position + length;
122015
122296
  this.guard.allocate(Math.min(length, this.source.length - this.position));
122016
122297
  this.guard.work(Math.min(length, this.source.length - this.position));
122017
122298
  const digits = this.source.slice(this.position, end);
122018
122299
  if (digits.length !== length || !allHexDigits(digits)) {
122300
+ if (identity !== void 0) return identity;
122019
122301
  this.fail(`Invalid ${name} escape`, start);
122020
122302
  }
122021
122303
  this.position = end;
122022
122304
  return String.fromCharCode(Number.parseInt(digits, 16));
122023
122305
  }
122306
+ countAllCaptures() {
122307
+ let count = 0;
122308
+ let escaped = false;
122309
+ let characterClass = false;
122310
+ for (let index = 0; index < this.source.length; index++) {
122311
+ this.guard.work(1);
122312
+ const character2 = this.source[index];
122313
+ if (escaped) escaped = false;
122314
+ else if (character2 === "\\") escaped = true;
122315
+ else if (character2 === "[") characterClass = true;
122316
+ else if (character2 === "]") characterClass = false;
122317
+ else if (!characterClass && character2 === "(") {
122318
+ const named = this.source[index + 1] === "?" && this.source[index + 2] === "<" && this.source[index + 3] !== "=" && this.source[index + 3] !== "!";
122319
+ if (named) this.hasNamedCaptures = true;
122320
+ if (named || this.source[index + 1] !== "?") count++;
122321
+ }
122322
+ }
122323
+ return count;
122324
+ }
122325
+ parseGroupName(start) {
122326
+ let name = "";
122327
+ while (!this.atEnd() && this.peek() !== ">") {
122328
+ let character2 = this.take();
122329
+ if (character2 === "\\") {
122330
+ if (this.take() !== "u") this.fail("Invalid group name escape", start);
122331
+ if (this.peek() === "{") {
122332
+ this.position++;
122333
+ const begin = this.position;
122334
+ while (!this.atEnd() && this.peek() !== "}") this.position++;
122335
+ this.guard.allocate(this.position - begin);
122336
+ const digits = this.source.slice(begin, this.position);
122337
+ const point = Number.parseInt(digits, 16);
122338
+ if (this.take() !== "}" || digits.length === 0 || !allHexDigits(digits) || point > 1114111)
122339
+ this.fail("Invalid group name escape", start);
122340
+ character2 = String.fromCodePoint(point);
122341
+ } else character2 = this.parseHexEscape(4, "Unicode", start);
122342
+ }
122343
+ this.guard.allocate(character2.length);
122344
+ name += character2;
122345
+ }
122346
+ if (this.take() !== ">" || name.length === 0) this.fail("Invalid group name", start);
122347
+ let first = true;
122348
+ for (const character2 of name) {
122349
+ this.guard.work(1);
122350
+ if (!(first ? groupNameStart : groupNamePart).test(character2)) this.fail("Invalid group name", start);
122351
+ first = false;
122352
+ }
122353
+ return name;
122354
+ }
122355
+ validateNamedGroups(node) {
122356
+ this.guard.work(1);
122357
+ this.guard.allocate(1);
122358
+ const names = /* @__PURE__ */ new Set();
122359
+ if (node.type === "namedBackreference" && !Object.hasOwn(this.namedGroups, node.name))
122360
+ this.fail("Unknown named backreference");
122361
+ if (node.type === "group" && node.name !== void 0) names.add(node.name);
122362
+ const children2 = node.type === "sequence" ? node.elements : node.type === "alternation" ? node.alternatives : node.type === "group" || node.type === "quantifier" || node.type === "lookahead" || node.type === "lookbehind" ? [node.body] : [];
122363
+ for (const child of children2) {
122364
+ for (const name of this.validateNamedGroups(child)) {
122365
+ this.guard.work(1);
122366
+ if (names.has(name) && node.type !== "alternation") this.fail("Duplicate capture group name");
122367
+ this.guard.allocate(1);
122368
+ names.add(name);
122369
+ }
122370
+ }
122371
+ return names;
122372
+ }
122024
122373
  parseQuantifier() {
122025
122374
  const character2 = this.peek();
122026
122375
  if (character2 === "*") {
@@ -122050,18 +122399,29 @@ var init_parse5 = __esm({
122050
122399
  }
122051
122400
  if (this.peek() === "}") {
122052
122401
  this.position += 1;
122402
+ if (!Number.isSafeInteger(min)) this.fail("Quantifier is too large", start);
122053
122403
  this.guard.allocate(3);
122054
122404
  return { min, max: min };
122055
122405
  }
122056
122406
  if (this.peek() !== ",") {
122407
+ if (!this.unicode) {
122408
+ this.position = start;
122409
+ return void 0;
122410
+ }
122057
122411
  this.fail("Invalid quantifier", start);
122058
122412
  }
122059
122413
  this.position += 1;
122060
122414
  const max = this.parseDecimal();
122061
122415
  if (this.peek() !== "}") {
122416
+ if (!this.unicode) {
122417
+ this.position = start;
122418
+ return void 0;
122419
+ }
122062
122420
  this.fail("Unterminated quantifier", start);
122063
122421
  }
122064
122422
  this.position += 1;
122423
+ if (!Number.isSafeInteger(min) || max !== void 0 && !Number.isSafeInteger(max))
122424
+ this.fail("Quantifier is too large", start);
122065
122425
  if (max !== void 0 && min > max) {
122066
122426
  this.fail("Quantifier range is out of order", start);
122067
122427
  }
@@ -122078,11 +122438,7 @@ var init_parse5 = __esm({
122078
122438
  }
122079
122439
  this.guard.allocate(this.position - start);
122080
122440
  this.guard.work(this.position - start);
122081
- const value = Number(this.source.slice(start, this.position));
122082
- if (!Number.isSafeInteger(value)) {
122083
- this.fail("Quantifier is too large", start);
122084
- }
122085
- return value;
122441
+ return Number(this.source.slice(start, this.position));
122086
122442
  }
122087
122443
  peek() {
122088
122444
  return this.source[this.position] ?? "";
@@ -122092,6 +122448,12 @@ var init_parse5 = __esm({
122092
122448
  this.position += 1;
122093
122449
  return character2;
122094
122450
  }
122451
+ takeCharacter() {
122452
+ if (!this.unicode || this.atEnd()) return this.take();
122453
+ const character2 = String.fromCodePoint(this.source.codePointAt(this.position));
122454
+ this.position += character2.length;
122455
+ return character2;
122456
+ }
122095
122457
  atEnd() {
122096
122458
  return this.position >= this.source.length;
122097
122459
  }
@@ -122299,6 +122661,7 @@ function findImportMetaAssignmentInNode(node) {
122299
122661
  case "BooleanLiteral":
122300
122662
  case "NullLiteral":
122301
122663
  case "NumericLiteral":
122664
+ case "BigIntLiteral":
122302
122665
  case "StringLiteral":
122303
122666
  case "ThisExpression":
122304
122667
  case "RegexLiteral":
@@ -122377,6 +122740,12 @@ function isYieldArgumentTerminator(value) {
122377
122740
  return value === ";" || value === "}" || value === ")" || value === "]" || value === ",";
122378
122741
  }
122379
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
+ };
122380
122749
  return {
122381
122750
  type: "NumericLiteral",
122382
122751
  raw: token.value,
@@ -125962,6 +126331,23 @@ var init_hash = __esm({
125962
126331
  }
125963
126332
  });
125964
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
+
125965
126351
  // packages/safe-js/src/observability/otel.ts
125966
126352
  function bindOtelSpan(value, span) {
125967
126353
  spanByAsyncValue.set(value, span);
@@ -126228,9 +126614,13 @@ function isSandboxRegExpIterator(value) {
126228
126614
  return typeof value === "object" && value !== null && states2.has(value);
126229
126615
  }
126230
126616
  function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.create(null)) {
126617
+ if ((state.global !== void 0 || state.unicode !== void 0) && (typeof state.global !== "boolean" || typeof state.unicode !== "boolean"))
126618
+ throw new TypeError("Invalid RegExp iterator modes.");
126619
+ if (state.matcher !== void 0 && (state.matcher === null || typeof state.matcher !== "object"))
126620
+ throw new TypeError("Invalid RegExp iterator matcher.");
126231
126621
  if (!state.exhausted && (state.matcher === void 0 || state.input === void 0))
126232
126622
  throw new TypeError("A live RegExp iterator requires its matcher and input.");
126233
- states2.set(target, state.exhausted ? { matcher: void 0, input: void 0, exhausted: true } : { ...state });
126623
+ states2.set(target, state.exhausted ? { ...state, matcher: void 0, input: void 0, exhausted: true } : { ...state });
126234
126624
  return target;
126235
126625
  }
126236
126626
  function regexpIteratorState(value) {
@@ -126389,10 +126779,11 @@ function nativeBoxedValue(value) {
126389
126779
  if (types2.isStringObject(value)) return Reflect.apply(stringValue2, value, []);
126390
126780
  if (types2.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
126391
126781
  if (types2.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
126782
+ if (types2.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
126392
126783
  return void 0;
126393
126784
  }
126394
126785
  function createSandboxBox(value) {
126395
- 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")
126396
126787
  throw new TypeError("Invalid boxed primitive payload.");
126397
126788
  const box = Object(value);
126398
126789
  Object.setPrototypeOf(box, null);
@@ -126423,7 +126814,7 @@ function boxedDataProperties(value, includeSymbols = false) {
126423
126814
  return !(Number.isInteger(index) && index >= 0 && index < primitive.length && String(index) === key3);
126424
126815
  });
126425
126816
  }
126426
- var boxes, numberValue2, stringValue2, booleanValue, symbolValue;
126817
+ var boxes, numberValue2, stringValue2, booleanValue, symbolValue, bigintValue;
126427
126818
  var init_boxed = __esm({
126428
126819
  "packages/safe-js/src/interp/boxed.ts"() {
126429
126820
  "use strict";
@@ -126432,6 +126823,7 @@ var init_boxed = __esm({
126432
126823
  stringValue2 = String.prototype.valueOf;
126433
126824
  booleanValue = Boolean.prototype.valueOf;
126434
126825
  symbolValue = Symbol.prototype.valueOf;
126826
+ bigintValue = BigInt.prototype.valueOf;
126435
126827
  }
126436
126828
  });
126437
126829
 
@@ -127671,6 +128063,9 @@ function getSandboxPrototype(value, budget) {
127671
128063
  function hasExplicitSandboxPrototype(value) {
127672
128064
  return prototypes.has(value);
127673
128065
  }
128066
+ function hasNullObjectPrototype(value) {
128067
+ return prototypes.get(value) === null && !Array.isArray(value) && !isSandboxClosure(value) && !isSandboxRegex(value);
128068
+ }
127674
128069
  function getSandboxPropertyDescriptor(value, key3, budget) {
127675
128070
  const hostProperties = isSandboxClosure(value) ? value.properties : void 0;
127676
128071
  if (isSandboxClosure(value) && !isGuestClosure(value))
@@ -127752,7 +128147,7 @@ function hasGuestObjectState(value) {
127752
128147
  const intrinsicUnchanged = intrinsicConstructors.get(value);
127753
128148
  if (intrinsicUnchanged !== void 0) return !intrinsicUnchanged();
127754
128149
  if (isLiveCapability(value)) return true;
127755
- if (functionProperties.has(value) || prototypes.has(value)) return true;
128150
+ if (functionProperties.has(value) || prototypes.has(value) && !hasNullObjectPrototype(value)) return true;
127756
128151
  if (isSandboxBox(value) || isSandboxDate(value)) return false;
127757
128152
  return descriptorObjects.has(value) && Object.values(Object.getOwnPropertyDescriptors(value)).some(
127758
128153
  (descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
@@ -127974,6 +128369,7 @@ function encodeReplayData(value, options = {}) {
127974
128369
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
127975
128370
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
127976
128371
  if (entry === void 0) return { tag: "undefined" };
128372
+ if (typeof entry === "bigint") return { tag: "bigint", value: String(entry) };
127977
128373
  if (typeof entry === "symbol") {
127978
128374
  let id2 = symbols2.get(entry);
127979
128375
  if (id2 === void 0) {
@@ -128070,7 +128466,16 @@ function encodeReplayData(value, options = {}) {
128070
128466
  }
128071
128467
  let symbolIndex = 0;
128072
128468
  const symbolEntries = serializeSymbolProperties(entry, (value2) => encode(value2, depth + 1, [...path193, { symbol: Math.floor(symbolIndex++ / 2) }]));
128073
- nodes[id] = { kind: "regexp-iterator", matcher: child(snapshot2.matcher, "<matcher>"), input: child(snapshot2.input, "<input>"), exhausted: snapshot2.exhausted, properties, extensible: Object.isExtensible(entry), symbolEntries };
128469
+ nodes[id] = {
128470
+ kind: "regexp-iterator",
128471
+ matcher: child(snapshot2.matcher, "<matcher>"),
128472
+ input: child(snapshot2.input, "<input>"),
128473
+ exhausted: snapshot2.exhausted,
128474
+ properties,
128475
+ extensible: Object.isExtensible(entry),
128476
+ symbolEntries,
128477
+ ...snapshot2.global === void 0 ? {} : { global: snapshot2.global, unicode: snapshot2.unicode }
128478
+ };
128074
128479
  } else if (isSandboxCollectionIterator(entry)) {
128075
128480
  const snapshot2 = snapshotCollectionIterator(entry);
128076
128481
  const properties = /* @__PURE__ */ Object.create(null);
@@ -128124,6 +128529,7 @@ function encodeReplayData(value, options = {}) {
128124
128529
  nodes[id] = {
128125
128530
  kind: Array.isArray(entry) ? "array" : "object",
128126
128531
  nullPrototype: prototype === null,
128532
+ ...hasNullObjectPrototype(entry) ? { sandboxNullPrototype: true } : {},
128127
128533
  ...errorType === void 0 ? {} : { errorType },
128128
128534
  extensible: Object.isExtensible(entry),
128129
128535
  properties,
@@ -128166,6 +128572,11 @@ function decodeReplayData(input, options = {}, parent) {
128166
128572
  return capability;
128167
128573
  }
128168
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
+ }
128169
128580
  if (atom.tag === "number") {
128170
128581
  switch (own(atom, "value")) {
128171
128582
  case "NaN":
@@ -128235,7 +128646,7 @@ function decodeReplayData(input, options = {}, parent) {
128235
128646
  const payload = own(node, "value");
128236
128647
  const payloadRecord = payload !== null && typeof payload === "object" ? record(payload) : void 0;
128237
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";
128238
- if (typeof payload !== "number" && typeof payload !== "string" && typeof payload !== "boolean" && !symbolReference && (payload === null || typeof payload !== "object" || own(record(payload), "tag") !== "number"))
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")))))
128239
128650
  throw new TypeError("Invalid boxed primitive payload.");
128240
128651
  const result3 = createSandboxBox(child(payload));
128241
128652
  restored.set(id, result3);
@@ -128268,9 +128679,15 @@ function decodeReplayData(input, options = {}, parent) {
128268
128679
  restored.set(id, result3);
128269
128680
  const matcher = child(own(node, "matcher"));
128270
128681
  const input2 = child(own(node, "input"));
128271
- if (matcher !== void 0 && !isSandboxRegex(matcher)) throw new TypeError("Invalid replay RegExp iterator matcher.");
128682
+ if ((node.global !== void 0 || node.unicode !== void 0) && (typeof node.global !== "boolean" || typeof node.unicode !== "boolean")) throw new TypeError("Invalid replay RegExp iterator modes.");
128683
+ if (matcher !== void 0 && (node.global === void 0 ? !isSandboxRegex(matcher) : matcher === null || typeof matcher !== "object")) throw new TypeError("Invalid replay RegExp iterator matcher.");
128272
128684
  if (input2 !== void 0 && typeof input2 !== "string") throw new TypeError("Invalid replay RegExp iterator input.");
128273
- restoreSandboxRegExpIterator({ matcher, input: input2, exhausted }, result3);
128685
+ restoreSandboxRegExpIterator({
128686
+ matcher,
128687
+ input: input2,
128688
+ exhausted,
128689
+ ...node.global === void 0 ? {} : { global: node.global, unicode: node.unicode }
128690
+ }, result3);
128274
128691
  defineProperties(result3, record(own(node, "properties")), child, node.symbolEntries);
128275
128692
  if (!node.extensible) Object.preventExtensions(result3);
128276
128693
  return result3;
@@ -128340,6 +128757,10 @@ function decodeReplayData(input, options = {}, parent) {
128340
128757
  throw new TypeError("Invalid replay object metadata.");
128341
128758
  }
128342
128759
  const result2 = kind === "array" ? [] : Object.create(node.nullPrototype ? null : Object.prototype);
128760
+ if (Object.hasOwn(node, "sandboxNullPrototype")) {
128761
+ if (kind !== "object" || node.sandboxNullPrototype !== true) throw new TypeError("Invalid replay object prototype.");
128762
+ setSandboxPrototype(result2, null);
128763
+ }
128343
128764
  if (Object.hasOwn(node, "errorType")) {
128344
128765
  sandboxErrorTypes.set(result2, node.errorType);
128345
128766
  }
@@ -128405,6 +128826,7 @@ var init_replay_data = __esm({
128405
128826
  "packages/safe-js/src/snapshot/replay-data.ts"() {
128406
128827
  "use strict";
128407
128828
  init_graph_depth();
128829
+ init_bigint();
128408
128830
  init_regexp_properties2();
128409
128831
  init_symbols2();
128410
128832
  init_symbols3();
@@ -129345,15 +129767,17 @@ var init_resources = __esm({
129345
129767
 
129346
129768
  // packages/safe-js/src/interp/regex/engine.ts
129347
129769
  function matchRegex(pattern, input, lastIndex = 0) {
129348
- const startIndex = pattern.flags.global ? normalizeLastIndex(lastIndex) : 0;
129770
+ const startIndex = pattern.flags.global || pattern.flags.sticky ? normalizeLastIndex(lastIndex) : 0;
129349
129771
  return matchRegexFrom(pattern, input, startIndex);
129350
129772
  }
129351
129773
  function matchRegexFrom(pattern, input, startIndex) {
129352
129774
  if (startIndex > input.length) {
129353
129775
  return null;
129354
129776
  }
129355
- for (let attempt = startIndex; attempt <= input.length; attempt += 1) {
129356
- const context = { input, flags: pattern.flags, steps: 0 };
129777
+ const unicode = pattern.flags.unicode || pattern.flags.unicodeSets;
129778
+ if (unicode && startIndex > 0 && startIndex < input.length && input.charCodeAt(startIndex) >= 56320 && input.charCodeAt(startIndex) <= 57343 && input.charCodeAt(startIndex - 1) >= 55296 && input.charCodeAt(startIndex - 1) <= 56319) startIndex--;
129779
+ for (let attempt = startIndex; attempt <= input.length; attempt = advanceStringIndex(input, attempt, unicode)) {
129780
+ const context = { input, flags: pattern.flags, groups: pattern.groups, direction: 1, work: { steps: 0 } };
129357
129781
  charge(context);
129358
129782
  const initialState = {
129359
129783
  position: attempt,
@@ -129361,25 +129785,59 @@ function matchRegexFrom(pattern, input, startIndex) {
129361
129785
  };
129362
129786
  const result = matchNode(pattern.body, initialState, context).next();
129363
129787
  if (!result.done) {
129364
- return toRegexMatch(input, attempt, result.value);
129788
+ return toRegexMatch(input, attempt, result.value, pattern.flags.hasIndices, pattern.groups);
129365
129789
  }
129790
+ if (pattern.flags.sticky) break;
129366
129791
  }
129367
129792
  return null;
129368
129793
  }
129369
129794
  function* matchNode(node, state, context) {
129370
129795
  charge(context);
129796
+ const unicode = context.flags.unicode || context.flags.unicodeSets;
129797
+ const character2 = readCharacter(context.input, state.position, context.direction, unicode);
129371
129798
  switch (node.type) {
129372
129799
  case "empty":
129373
129800
  yield state;
129374
129801
  return;
129375
129802
  case "literal":
129376
- if (charactersEqual(context.input[state.position], node.value, context.flags.ignoreCase)) {
129377
- yield { ...state, position: state.position + 1 };
129803
+ if (charactersEqual(character2, node.value, context.flags.ignoreCase, unicode)) {
129804
+ yield { ...state, position: state.position + context.direction * character2.length };
129805
+ }
129806
+ return;
129807
+ case "backreference":
129808
+ case "namedBackreference": {
129809
+ let capture;
129810
+ if (node.type === "backreference") capture = state.captures[node.index - 1];
129811
+ else {
129812
+ for (const index of context.groups?.[node.name] ?? []) {
129813
+ charge(context);
129814
+ if (state.captures[index - 1] !== void 0) {
129815
+ capture = state.captures[index - 1];
129816
+ break;
129817
+ }
129818
+ }
129819
+ }
129820
+ if (capture === void 0) {
129821
+ yield state;
129822
+ return;
129378
129823
  }
129824
+ let position = state.position;
129825
+ let reference = context.direction === 1 ? capture.start : capture.end;
129826
+ const end = context.direction === 1 ? capture.end : capture.start;
129827
+ while (reference !== end) {
129828
+ charge(context);
129829
+ const expected = readCharacter(context.input, reference, context.direction, unicode);
129830
+ const actual = readCharacter(context.input, position, context.direction, unicode);
129831
+ if (!charactersEqual(actual, expected, context.flags.ignoreCase, unicode)) return;
129832
+ reference += context.direction * expected.length;
129833
+ position += context.direction * actual.length;
129834
+ }
129835
+ yield { ...state, position };
129379
129836
  return;
129837
+ }
129380
129838
  case "dot":
129381
- if (state.position < context.input.length && (context.flags.dotAll || !isLineTerminator(context.input[state.position]))) {
129382
- yield { ...state, position: state.position + 1 };
129839
+ if (character2 !== void 0 && (context.flags.dotAll || !isLineTerminator(character2))) {
129840
+ yield { ...state, position: state.position + context.direction * character2.length };
129383
129841
  }
129384
129842
  return;
129385
129843
  case "anchor":
@@ -129388,17 +129846,24 @@ function* matchNode(node, state, context) {
129388
129846
  }
129389
129847
  return;
129390
129848
  case "wordBoundary": {
129391
- const previousWord = state.position > 0 && isWordCharacter(context.input[state.position - 1]);
129392
- const nextWord = state.position < context.input.length && isWordCharacter(context.input[state.position]);
129849
+ const previousWord = state.position > 0 && matchesCharacterClassItem(context.input[state.position - 1], { type: "kind", kind: "word", negated: false }, context.flags.ignoreCase, unicode);
129850
+ const nextWord = state.position < context.input.length && matchesCharacterClassItem(context.input[state.position], { type: "kind", kind: "word", negated: false }, context.flags.ignoreCase, unicode);
129393
129851
  if (previousWord !== nextWord !== node.negated) {
129394
129852
  yield state;
129395
129853
  }
129396
129854
  return;
129397
129855
  }
129398
129856
  case "characterClass": {
129399
- const character2 = context.input[state.position];
129400
- if (character2 !== void 0 && matchesCharacterClass(character2, node.items, node.negated, context.flags.ignoreCase)) {
129401
- yield { ...state, position: state.position + 1 };
129857
+ if (context.flags.unicodeSets) {
129858
+ const lengths = [...matchUnicodeSet(node, state.position, context)].sort((a, b) => b - a);
129859
+ for (const length of lengths) {
129860
+ charge(context);
129861
+ yield { ...state, position: state.position + context.direction * length };
129862
+ }
129863
+ return;
129864
+ }
129865
+ if (character2 !== void 0 && matchesCharacterClass(character2, node.items, node.negated, context)) {
129866
+ yield { ...state, position: state.position + context.direction * character2.length };
129402
129867
  }
129403
129868
  return;
129404
129869
  }
@@ -129410,14 +129875,30 @@ function* matchNode(node, state, context) {
129410
129875
  yield* matchNode(alternative, cloneState(state), context);
129411
129876
  }
129412
129877
  return;
129878
+ case "lookahead":
129879
+ case "lookbehind": {
129880
+ const result = matchNode(node.body, cloneState(state), {
129881
+ ...context,
129882
+ direction: node.type === "lookbehind" ? -1 : 1
129883
+ }).next();
129884
+ if (node.negated) {
129885
+ if (result.done) yield state;
129886
+ } else if (!result.done) {
129887
+ yield { position: state.position, captures: result.value.captures };
129888
+ }
129889
+ return;
129890
+ }
129413
129891
  case "group":
129414
- for (const result of matchNode(node.body, cloneState(state), context)) {
129892
+ for (const result of matchNode(node.body, cloneState(state), node.modifiers === void 0 ? context : {
129893
+ ...context,
129894
+ flags: { ...context.flags, ...node.modifiers }
129895
+ })) {
129415
129896
  if (!node.capturing || node.index === void 0) {
129416
129897
  yield result;
129417
129898
  continue;
129418
129899
  }
129419
129900
  const captures = result.captures.slice();
129420
- captures[node.index - 1] = { start: state.position, end: result.position };
129901
+ captures[node.index - 1] = { start: Math.min(state.position, result.position), end: Math.max(state.position, result.position) };
129421
129902
  yield { position: result.position, captures };
129422
129903
  }
129423
129904
  return;
@@ -129431,7 +129912,8 @@ function* matchSequence(elements, index, state, context) {
129431
129912
  yield state;
129432
129913
  return;
129433
129914
  }
129434
- for (const result of matchNode(elements[index], state, context)) {
129915
+ const element = elements[context.direction === 1 ? index : elements.length - 1 - index];
129916
+ for (const result of matchNode(element, state, context)) {
129435
129917
  yield* matchSequence(elements, index + 1, result, context);
129436
129918
  }
129437
129919
  }
@@ -129467,11 +129949,28 @@ function matchesAnchor(kind, position, context) {
129467
129949
  }
129468
129950
  return position === context.input.length || context.flags.multiline && position < context.input.length && isLineTerminator(context.input[position]);
129469
129951
  }
129470
- function matchesCharacterClass(character2, items, negated, ignoreCase) {
129471
- const matched = items.some((item) => matchesCharacterClassItem(character2, item, ignoreCase));
129952
+ function matchesCharacterClass(character2, items, negated, context) {
129953
+ const matched = items.some((item) => {
129954
+ if (context.flags.unicode) charge(context);
129955
+ return matchesCharacterClassItem(character2, item, context.flags.ignoreCase, context.flags.unicode);
129956
+ });
129472
129957
  return negated ? !matched : matched;
129473
129958
  }
129474
- function matchesCharacterClassItem(character2, item, ignoreCase) {
129959
+ function matchesCharacterClassItem(character2, item, ignoreCase, unicode, unicodeSets = false) {
129960
+ if (item.type === "strings" || item.type === "set") return false;
129961
+ if (unicode) {
129962
+ const hex = (value) => `\\u{${value.codePointAt(0).toString(16)}}`;
129963
+ let atom;
129964
+ if (item.type === "character") atom = hex(item.value);
129965
+ else if (item.type === "range") atom = `[${hex(item.from)}-${hex(item.to)}]`;
129966
+ else if (item.type === "property") atom = `\\${item.negated ? "P" : "p"}{${item.value}}`;
129967
+ else {
129968
+ const kind = item.kind === "digit" ? "d" : item.kind === "word" ? "w" : "s";
129969
+ atom = `\\${item.negated ? kind.toUpperCase() : kind}`;
129970
+ }
129971
+ return new RegExp(`^(?:${atom})$`, (ignoreCase ? "i" : "") + (unicodeSets ? "v" : "u")).test(character2);
129972
+ }
129973
+ if (item.type === "property") return false;
129475
129974
  if (item.type === "character") {
129476
129975
  return charactersEqual(character2, item.value, ignoreCase);
129477
129976
  }
@@ -129485,22 +129984,102 @@ function matchesCharacterClassItem(character2, item, ignoreCase) {
129485
129984
  if (!ignoreCase) {
129486
129985
  return false;
129487
129986
  }
129488
- const foldedCandidate = foldCharacter(character2, true).charCodeAt(0);
129489
- const foldedFrom = foldCharacter(item.from, true).charCodeAt(0);
129490
- const foldedTo = foldCharacter(item.to, true).charCodeAt(0);
129491
- return foldedCandidate >= foldedFrom && foldedCandidate <= foldedTo;
129987
+ return new RegExp(`^[\\u${from.toString(16).padStart(4, "0")}-\\u${to.toString(16).padStart(4, "0")}]$`, "i").test(character2);
129492
129988
  }
129493
129989
  const matched = item.kind === "digit" ? isDigit5(character2) : item.kind === "word" ? isWordCharacter(character2) : isSpaceCharacter(character2);
129494
129990
  return item.negated ? !matched : matched;
129495
129991
  }
129496
- function toRegexMatch(input, start, state) {
129497
- return {
129992
+ function matchUnicodeSet(set, position, context) {
129993
+ charge(context);
129994
+ let lengths = /* @__PURE__ */ new Set();
129995
+ for (let index = 0; index < set.items.length; index++) {
129996
+ const next = matchUnicodeSetItem(set.items[index], position, context);
129997
+ if (index === 0) lengths = next;
129998
+ else if (set.operation === void 0) {
129999
+ for (const length of next) {
130000
+ charge(context);
130001
+ lengths.add(length);
130002
+ }
130003
+ } else {
130004
+ for (const length of lengths) {
130005
+ charge(context);
130006
+ if (set.operation === "intersection" ? !next.has(length) : next.has(length)) lengths.delete(length);
130007
+ }
130008
+ }
130009
+ }
130010
+ if (set.negated) {
130011
+ const character2 = readCharacter(context.input, position, context.direction, true);
130012
+ return new Set(character2 !== void 0 && !lengths.has(character2.length) ? [character2.length] : []);
130013
+ }
130014
+ return lengths;
130015
+ }
130016
+ function matchUnicodeSetItem(item, position, context) {
130017
+ charge(context);
130018
+ if (item.type === "set") return matchUnicodeSet(item.value, position, context);
130019
+ const lengths = /* @__PURE__ */ new Set();
130020
+ if (item.type === "strings") {
130021
+ for (const value of item.values) {
130022
+ charge(context);
130023
+ let reference = context.direction === 1 ? 0 : value.length;
130024
+ let cursor2 = position;
130025
+ const end = context.direction === 1 ? value.length : 0;
130026
+ while (reference !== end) {
130027
+ charge(context);
130028
+ const expected = readCharacter(value, reference, context.direction, true);
130029
+ const actual = readCharacter(context.input, cursor2, context.direction, true);
130030
+ if (!charactersEqual(actual, expected, context.flags.ignoreCase, true)) break;
130031
+ reference += context.direction * expected.length;
130032
+ cursor2 += context.direction * actual.length;
130033
+ }
130034
+ if (reference === end) lengths.add(Math.abs(cursor2 - position));
130035
+ }
130036
+ return lengths;
130037
+ }
130038
+ if (item.type === "property" && item.strings) {
130039
+ const atom = `\\p{${item.value}}`;
130040
+ const flags = (context.flags.ignoreCase ? "i" : "") + "v";
130041
+ const matcher = new RegExp(context.direction === 1 ? atom : `(?<=(${atom}))`, flags + "y");
130042
+ matcher.lastIndex = position;
130043
+ const match = matcher.exec(context.input);
130044
+ if (match === null) return lengths;
130045
+ const longest = context.direction === 1 ? match[0] : match[1];
130046
+ const member = new RegExp(`^(?:${atom})$`, flags);
130047
+ let consumed = 0;
130048
+ while (consumed < longest.length) {
130049
+ charge(context);
130050
+ const cursor2 = context.direction === 1 ? consumed : longest.length - consumed;
130051
+ consumed += readCharacter(longest, cursor2, context.direction, true).length;
130052
+ const candidate = context.direction === 1 ? longest.slice(0, consumed) : longest.slice(longest.length - consumed);
130053
+ if (member.test(candidate)) lengths.add(consumed);
130054
+ }
130055
+ return lengths;
130056
+ }
130057
+ const character2 = readCharacter(context.input, position, context.direction, true);
130058
+ if (character2 !== void 0 && matchesCharacterClassItem(character2, item, context.flags.ignoreCase, true, true))
130059
+ lengths.add(character2.length);
130060
+ return lengths;
130061
+ }
130062
+ function toRegexMatch(input, start, state, hasIndices, groups) {
130063
+ const match = {
129498
130064
  index: start,
129499
130065
  text: input.slice(start, state.position),
129500
130066
  captures: state.captures.map(
129501
130067
  (capture) => capture === void 0 ? void 0 : input.slice(capture.start, capture.end)
129502
130068
  )
129503
130069
  };
130070
+ if (hasIndices) {
130071
+ match.indices = [[start, state.position], ...state.captures.map((capture) => capture === void 0 ? void 0 : [capture.start, capture.end])];
130072
+ }
130073
+ if (groups !== void 0) {
130074
+ match.groups = /* @__PURE__ */ Object.create(null);
130075
+ if (hasIndices) match.indicesGroups = /* @__PURE__ */ Object.create(null);
130076
+ for (const [name, indices] of Object.entries(groups)) {
130077
+ const index = indices.find((index2) => state.captures[index2 - 1] !== void 0);
130078
+ match.groups[name] = index === void 0 ? void 0 : match.captures[index - 1];
130079
+ if (match.indicesGroups !== void 0) match.indicesGroups[name] = index === void 0 ? void 0 : match.indices[index];
130080
+ }
130081
+ }
130082
+ return match;
129504
130083
  }
129505
130084
  function cloneState(state) {
129506
130085
  return { position: state.position, captures: state.captures.slice() };
@@ -129530,13 +130109,13 @@ function clearNodeCaptures(node, captures) {
129530
130109
  }
129531
130110
  return;
129532
130111
  }
129533
- if (node.type === "quantifier") {
130112
+ if (node.type === "quantifier" || node.type === "lookahead" || node.type === "lookbehind") {
129534
130113
  clearNodeCaptures(node.body, captures);
129535
130114
  }
129536
130115
  }
129537
130116
  function charge(context) {
129538
- context.steps += 1;
129539
- allocateRegexSteps(context.steps);
130117
+ context.work.steps += 1;
130118
+ allocateRegexSteps(context.work.steps);
129540
130119
  }
129541
130120
  function normalizeLastIndex(lastIndex) {
129542
130121
  if (Number.isNaN(lastIndex) || lastIndex <= 0) {
@@ -129544,9 +130123,20 @@ function normalizeLastIndex(lastIndex) {
129544
130123
  }
129545
130124
  return Math.min(Math.floor(lastIndex), Number.MAX_SAFE_INTEGER);
129546
130125
  }
129547
- function charactersEqual(left, right, ignoreCase) {
130126
+ function charactersEqual(left, right, ignoreCase, unicode = false) {
130127
+ if (unicode && ignoreCase && left !== void 0)
130128
+ return new RegExp(`^\\u{${right.codePointAt(0).toString(16)}}$`, "iu").test(left);
129548
130129
  return left !== void 0 && foldCharacter(left, ignoreCase) === foldCharacter(right, ignoreCase);
129549
130130
  }
130131
+ function advanceStringIndex(input, index, unicode) {
130132
+ return index + (unicode && (input.codePointAt(index) ?? 0) > 65535 ? 2 : 1);
130133
+ }
130134
+ function readCharacter(input, position, direction, unicode) {
130135
+ let index = direction === 1 ? position : position - 1;
130136
+ if (index < 0 || index >= input.length) return void 0;
130137
+ if (unicode && direction === -1 && index > 0 && input.charCodeAt(index) >= 56320 && input.charCodeAt(index) <= 57343 && input.charCodeAt(index - 1) >= 55296 && input.charCodeAt(index - 1) <= 56319) index--;
130138
+ return unicode ? String.fromCodePoint(input.codePointAt(index)) : input[index];
130139
+ }
129550
130140
  function foldCharacter(character2, ignoreCase) {
129551
130141
  if (!ignoreCase) {
129552
130142
  return character2;
@@ -129579,6 +130169,75 @@ var init_engine2 = __esm({
129579
130169
  }
129580
130170
  });
129581
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
+
129582
130241
  // packages/safe-js/src/interp/jobs.ts
129583
130242
  import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
129584
130243
  function runPromiseJob(task) {
@@ -129768,7 +130427,7 @@ function callNumberMethod(value, methodName, args, budget, context) {
129768
130427
  if (argument !== null && typeof argument === "object") {
129769
130428
  return formatObjectArgument(value, methodName, argument, budget, context);
129770
130429
  }
129771
- return formatNumber3(value, methodName, argument === void 0 ? void 0 : Number(argument), budget);
130430
+ return formatNumber3(value, methodName, argument === void 0 ? void 0 : +argument, budget);
129772
130431
  }
129773
130432
  async function formatObjectArgument(value, methodName, argument, budget, context) {
129774
130433
  const retainedArgument = {};
@@ -130124,7 +130783,7 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure, use
130124
130783
  );
130125
130784
  }
130126
130785
  async function replaceRegex(value, regex, replacement, budget, callClosure, context) {
130127
- if (hasRegexPropertyOverride(regex, ["exec", "flags", ...Object.keys(regexFlagProperties)], budget))
130786
+ if (getSandboxRegexPattern(regex).groups !== void 0 || hasRegexPropertyOverride(regex, ["exec", "flags", ...Object.keys(regexFlagProperties)], budget))
130128
130787
  return regexReplace(value, regex, replacement, budget, callClosure, context);
130129
130788
  if (regex.flags.includes("g")) regex.lastIndex = 0;
130130
130789
  const cursor2 = regex.lastIndex;
@@ -130174,7 +130833,7 @@ async function regexReplace(input, regex, replacementInput, budget, callClosure,
130174
130833
  input = void 0;
130175
130834
  replacement = isSandboxClosure(replacementInput) ? replacementInput : await sandboxString(replacementInput, budget, context);
130176
130835
  replacementInput = void 0;
130177
- if (isSandboxRegex(regex) && !hasRegexPropertyOverride(regex, ["exec", "flags", ...Object.keys(regexFlagProperties)], budget)) {
130836
+ if (isSandboxRegex(regex) && getSandboxRegexPattern(regex).groups === void 0 && !hasRegexPropertyOverride(regex, ["exec", "flags", ...Object.keys(regexFlagProperties)], budget)) {
130178
130837
  release2();
130179
130838
  return await replaceRegex(value, regex, replacement, budget, callClosure, context);
130180
130839
  }
@@ -130389,7 +131048,7 @@ function splitNormalized(value, separator, limit, budget, parent) {
130389
131048
  while (result2.length < limit) {
130390
131049
  const match = executeRegex(splitter, value, Number(splitter.lastIndex));
130391
131050
  if (match === null) break;
130392
- if (match.text.length === 0) splitter.lastIndex = match.index + 1;
131051
+ if (match.text.length === 0) splitter.lastIndex = advanceStringIndex(value, match.index, splitter.flags.includes("u") || splitter.flags.includes("v"));
130393
131052
  endedWithZeroWidthMatch = match.text.length === 0 && match.index === value.length;
130394
131053
  if (match.text.length === 0 && (match.index === copiedThrough || match.index === value.length))
130395
131054
  continue;
@@ -130548,7 +131207,7 @@ function callMatchLikeMethod(value, methodName, args, compilation, lastIndex) {
130548
131207
  return match?.index ?? -1;
130549
131208
  }
130550
131209
  if (methodName === "match" && !regex.flags.includes("g"))
130551
- return toMatchArray(executeRegex(regex, value, lastIndex ?? Number(regex.lastIndex)), value);
131210
+ return toMatchArray(executeRegex(regex, value, lastIndex ?? Number(regex.lastIndex)), value, compilation.owner?.budget);
130552
131211
  if (methodName === "match") regex.lastIndex = 0;
130553
131212
  const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, normalizeLastIndex(lastIndex ?? Number(regex.lastIndex)), compilation) : regex;
130554
131213
  if (methodName === "matchAll")
@@ -130564,7 +131223,7 @@ function collectRegexMatches(regex, value, all, budget, lastIndex = 0) {
130564
131223
  budget?.allocateArrayLength(matches.length + 1);
130565
131224
  matches.push(match);
130566
131225
  lastIndex = match.index + match.text.length;
130567
- if (all && match.text.length === 0) regex.lastIndex = ++lastIndex;
131226
+ if (all && match.text.length === 0) regex.lastIndex = lastIndex = advanceStringIndex(value, lastIndex, regex.flags.includes("u") || regex.flags.includes("v"));
130568
131227
  } while (all);
130569
131228
  return matches;
130570
131229
  }
@@ -130573,10 +131232,10 @@ function splitString(value, separator, limit) {
130573
131232
  return split.call(value, separator, limit);
130574
131233
  }
130575
131234
  function asNumber(value) {
130576
- return Number(value);
131235
+ return +value;
130577
131236
  }
130578
131237
  function asNumberOrUndefined(value) {
130579
- return value === void 0 ? void 0 : Number(value);
131238
+ return value === void 0 ? void 0 : +value;
130580
131239
  }
130581
131240
  function asStringOrUndefined(value) {
130582
131241
  return value === void 0 ? void 0 : String(value);
@@ -130987,7 +131646,7 @@ function createObjectArrayGlobals(options) {
130987
131646
  ),
130988
131647
  Number: createPrimitiveConstructor(
130989
131648
  {
130990
- 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),
130991
131650
  name: "Number",
130992
131651
  properties: {
130993
131652
  isFinite: createSandboxClosure({
@@ -135540,8 +136199,9 @@ async function evaluateIdentifierUpdateExpression(node, context) {
135540
136199
  )
135541
136200
  };
135542
136201
  }
135543
- const current = toNumber(await toNumericPrimitive(binding.value, context));
135544
- const next = node.operator === "++" ? current + 1 : current - 1;
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;
135545
136205
  context.scope.assign(node.argument.name, next);
135546
136206
  return {
135547
136207
  kind: "normal",
@@ -135558,10 +136218,9 @@ async function evaluateMemberUpdateExpression(node, context) {
135558
136218
  throw new TypeError("Cannot update properties of null or undefined.");
135559
136219
  }
135560
136220
  const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
135561
- const current = toNumber(
135562
- await toNumericPrimitive(await getPropertyValue(member.object, property, context, member.superReceiver === void 0 ? member.object : member.superReceiver.value), context)
135563
- );
135564
- 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;
135565
136224
  if (member.superReceiver === void 0) await setSandboxProperty(member.object, property, next, context.budget, true, createCoercionContext(context));
135566
136225
  else await setSuperProperty(member.object, member.superReceiver.value, property, next, context);
135567
136226
  return {
@@ -135595,7 +136254,7 @@ function getPropertyValue(target, property, context, receiver = target) {
135595
136254
  if (descriptor !== void 0)
135596
136255
  return readPropertyDescriptor(descriptor, receiver, createCoercionContext(context), true);
135597
136256
  if (isSandboxRegExpIterator(target)) return getRegExpIteratorMember(property, context.budget);
135598
- if (typeof target === "symbol") {
136257
+ if (typeof target === "symbol" || typeof target === "bigint") {
135599
136258
  const prototype = getBoxedPrototype(target, context.budget);
135600
136259
  return prototype === void 0 ? void 0 : getPropertyValue(prototype, property, context, receiver);
135601
136260
  }
@@ -135776,6 +136435,7 @@ async function evaluateObjectPropertyKey(node, context) {
135776
136435
  return evaluateMemberProperty(node.key, context);
135777
136436
  }
135778
136437
  function getStaticPropertyName(node) {
136438
+ if (node.type === "BigIntLiteral") return BigInt(node.value).toString();
135779
136439
  if (node.type === "Identifier") {
135780
136440
  return node.name;
135781
136441
  }
@@ -135809,7 +136469,7 @@ async function evaluateMemberCallExpression(node, context) {
135809
136469
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
135810
136470
  if (Array.isArray(member.object) && hasExplicitSandboxPrototype(member.object))
135811
136471
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
135812
- 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) {
135813
136473
  if (isDefaultBoxedMethod(member.object, member.property, context.budget)) {
135814
136474
  if (typeof member.object === "string" && isStringMethodName(member.property))
135815
136475
  return evaluateStringMethodCall(node, member.object, member.property, context);
@@ -136059,10 +136719,14 @@ async function applyUnaryOperator(operator, value, context) {
136059
136719
  return void 0;
136060
136720
  case "+":
136061
136721
  return toNumber(await toNumericPrimitive(value, context));
136062
- case "-":
136063
- return -toNumber(await toNumericPrimitive(value, context));
136064
- case "~":
136065
- return ~toNumber(await toNumericPrimitive(value, context));
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
+ }
136066
136730
  }
136067
136731
  }
136068
136732
  function describeTypeofValue(value) {
@@ -136078,6 +136742,10 @@ function isTruthy(value) {
136078
136742
  return Boolean(value);
136079
136743
  }
136080
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
+ }
136081
136749
  switch (node.operator) {
136082
136750
  case "+":
136083
136751
  return applyAdditionOperator(left, right, context);
@@ -136196,6 +136864,10 @@ async function applyCompoundAssignmentOperator(operator, left, right, context) {
136196
136864
  left = await toNumericPrimitive(left, context, operator === "+=" ? "default" : "number");
136197
136865
  if (convertingObject) convertedLeft = left;
136198
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
+ }
136199
136871
  switch (operator) {
136200
136872
  case "+=":
136201
136873
  return applyAdditionOperator(left, right, context);
@@ -136232,6 +136904,10 @@ function applyAdditionOperator(left, right, context) {
136232
136904
  if (typeof leftPrimitive === "string" || typeof rightPrimitive === "string") {
136233
136905
  return context.budget.allocateString(toString(leftPrimitive) + toString(rightPrimitive));
136234
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
+ }
136235
136911
  return toNumber(leftPrimitive) + toNumber(rightPrimitive);
136236
136912
  }
136237
136913
  function compareRelational(left, right, operator) {
@@ -136249,8 +136925,9 @@ function compareRelational(left, right, operator) {
136249
136925
  return leftPrimitive >= rightPrimitive;
136250
136926
  }
136251
136927
  }
136252
- const leftNumber = toNumber(leftPrimitive);
136253
- const rightNumber = toNumber(rightPrimitive);
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);
136254
136931
  switch (operator) {
136255
136932
  case "<":
136256
136933
  return leftNumber < rightNumber;
@@ -136263,6 +136940,7 @@ function compareRelational(left, right, operator) {
136263
136940
  }
136264
136941
  }
136265
136942
  function isLooselyEqual(left, right) {
136943
+ if (typeof left === "bigint" || typeof right === "bigint") return left == right;
136266
136944
  const leftType = getCoercionType(left);
136267
136945
  const rightType = getCoercionType(right);
136268
136946
  if (leftType === rightType) {
@@ -136295,6 +136973,7 @@ function isPrimitiveCoercionType(type) {
136295
136973
  return type !== "object";
136296
136974
  }
136297
136975
  function getCoercionType(value) {
136976
+ if (typeof value === "bigint") return "bigint";
136298
136977
  if (typeof value === "symbol") return "symbol";
136299
136978
  if (value === null) {
136300
136979
  return "null";
@@ -136328,6 +137007,7 @@ async function toNumericPrimitive(value, context, hint = "number") {
136328
137007
  throw new TypeError("Expected a sandbox value.");
136329
137008
  }
136330
137009
  function toNumber(value) {
137010
+ if (typeof value === "bigint") throw new TypeError("Cannot convert a BigInt value to a number");
136331
137011
  if (typeof value === "symbol") throw new TypeError("Cannot convert a Symbol value to a number");
136332
137012
  if (isSandboxDate(value)) return dateTime(value);
136333
137013
  if (typeof value === "number") {
@@ -136747,6 +137427,7 @@ var init_interpreter = __esm({
136747
137427
  "packages/safe-js/src/interp/interpreter.ts"() {
136748
137428
  "use strict";
136749
137429
  init_promise_replay();
137430
+ init_bigint_operators();
136750
137431
  init_accessors();
136751
137432
  init_host_capabilities();
136752
137433
  init_property_key();
@@ -136800,6 +137481,16 @@ var init_interpreter = __esm({
136800
137481
  ArrowFunctionExpression: evaluateArrowFunction,
136801
137482
  AwaitExpression: evaluateAwait,
136802
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
+ },
136803
137494
  BlockStatement: evaluateBlockStatement,
136804
137495
  BooleanLiteral: evaluatePrimitiveLiteral,
136805
137496
  CallExpression: evaluateCallExpression,
@@ -136968,7 +137659,7 @@ async function callRegexMethod(target, methodName, args, budget, context) {
136968
137659
  cursor2 = target.lastIndex;
136969
137660
  const lastIndex = await sandboxNumber(cursor2, budget, context);
136970
137661
  const match = executeRegex(target, input, lastIndex);
136971
- return toMatchArray(match, input);
137662
+ return toMatchArray(match, input, budget);
136972
137663
  } finally {
136973
137664
  budget.setRetainedValues(retained, void 0);
136974
137665
  }
@@ -137019,17 +137710,26 @@ async function regexToString(target, budget, context) {
137019
137710
  function executeRegex(target, input, lastIndex) {
137020
137711
  const pattern = getSandboxRegexPattern(target);
137021
137712
  const match = matchRegex(pattern, input, lastIndex);
137022
- if (pattern.flags.global) {
137713
+ if (pattern.flags.global || pattern.flags.sticky) {
137023
137714
  target.lastIndex = match === null ? 0 : match.index + match.text.length;
137024
137715
  }
137025
137716
  return match;
137026
137717
  }
137027
- function toMatchArray(match, input) {
137718
+ function toMatchArray(match, input, budget) {
137028
137719
  if (match === null) {
137029
137720
  return null;
137030
137721
  }
137722
+ budget?.allocateArrayLength(match.captures.length + 1);
137031
137723
  const result = [match.text, ...match.captures];
137032
- Object.assign(result, { index: match.index, input, groups: void 0 });
137724
+ if (match.groups !== void 0) setSandboxPrototype(match.groups, null, budget);
137725
+ if (match.indicesGroups !== void 0) setSandboxPrototype(match.indicesGroups, null, budget);
137726
+ Object.assign(result, { index: match.index, input, groups: match.groups });
137727
+ if (match.indices !== void 0) {
137728
+ budget?.allocateArrayLength(match.indices.length);
137729
+ budget?.allocateArrayLength(2);
137730
+ Object.assign(match.indices, { groups: match.indicesGroups });
137731
+ Object.assign(result, { indices: match.indices });
137732
+ }
137033
137733
  return result;
137034
137734
  }
137035
137735
  var regexMethodNames, regexFlagProperties;
@@ -137064,9 +137764,10 @@ function nextRegExpIterator(iterator, budget) {
137064
137764
  budget?.visitNode();
137065
137765
  if (state.exhausted) return { value: void 0, done: true };
137066
137766
  const matcher = state.matcher;
137767
+ if (!isSandboxRegex(matcher)) throw new TypeError("Custom RegExp iterator execution requires a sandbox context.");
137067
137768
  const input = state.input;
137068
137769
  const match = executeRegex(matcher, input, Number(matcher.lastIndex));
137069
- if (match === null || !matcher.flags.includes("g")) {
137770
+ if (match === null || !(state.global ?? matcher.flags.includes("g"))) {
137070
137771
  state.exhausted = true;
137071
137772
  state.matcher = void 0;
137072
137773
  state.input = void 0;
@@ -137074,12 +137775,52 @@ function nextRegExpIterator(iterator, budget) {
137074
137775
  if (match === null) return { value: void 0, done: true };
137075
137776
  if (!state.exhausted && match.text.length === 0) {
137076
137777
  const index = Number(matcher.lastIndex);
137077
- const unicode = matcher.flags.includes("u") || matcher.flags.includes("v");
137778
+ const unicode = state.unicode ?? (matcher.flags.includes("u") || matcher.flags.includes("v"));
137078
137779
  const codePoint = input.codePointAt(index);
137079
137780
  matcher.lastIndex = index + (unicode && codePoint !== void 0 && codePoint > 65535 ? 2 : 1);
137080
137781
  }
137081
- budget?.allocateArrayLength(match.captures.length + 1);
137082
- return { value: toMatchArray(match, input), done: false };
137782
+ return { value: toMatchArray(match, input, budget), done: false };
137783
+ }
137784
+ async function nextObservableRegExpIterator(iterator, budget, context) {
137785
+ const state = regexpIteratorState(iterator);
137786
+ if (state.exhausted) return { value: void 0, done: true };
137787
+ const matcher = state.matcher;
137788
+ if (isSandboxRegex(matcher) && !hasRegexPropertyOverride(matcher, ["exec"], budget) && (matcher.lastIndex === null || typeof matcher.lastIndex !== "object"))
137789
+ return nextRegExpIterator(iterator, budget);
137790
+ const input = state.input;
137791
+ let result;
137792
+ let field;
137793
+ const release2 = retainValues(budget, () => [iterator, matcher, input, result, field]);
137794
+ const read = (value, key3) => {
137795
+ if (context.getProperty !== void 0) return context.getProperty(value, key3);
137796
+ const descriptor = getSandboxPropertyDescriptor(value, key3, budget);
137797
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
137798
+ };
137799
+ try {
137800
+ budget.visitNode();
137801
+ result = await regexExec(matcher, input, budget, context);
137802
+ const global2 = state.global ?? (isSandboxRegex(matcher) && matcher.flags.includes("g"));
137803
+ if (result === null || !global2) {
137804
+ state.exhausted = true;
137805
+ state.matcher = void 0;
137806
+ state.input = void 0;
137807
+ return result === null ? { value: void 0, done: true } : { value: result, done: false };
137808
+ }
137809
+ field = await read(result, "0");
137810
+ const text5 = await sandboxString(field, budget, context);
137811
+ field = void 0;
137812
+ if (text5.length === 0) {
137813
+ field = await read(matcher, "lastIndex");
137814
+ const index = normalizeLastIndex(await sandboxNumber(field, budget, context));
137815
+ field = void 0;
137816
+ const unicode = state.unicode ?? (isSandboxRegex(matcher) && (matcher.flags.includes("u") || matcher.flags.includes("v")));
137817
+ const point = input.codePointAt(index);
137818
+ await setSandboxProperty(matcher, "lastIndex", index + (unicode && point !== void 0 && point > 65535 ? 2 : 1), budget, true, context);
137819
+ }
137820
+ return { value: result, done: false };
137821
+ } finally {
137822
+ release2();
137823
+ }
137083
137824
  }
137084
137825
  function getRegExpIteratorMember(property, budget) {
137085
137826
  if (property === Symbol.toStringTag) return "RegExp String Iterator";
@@ -137096,7 +137837,7 @@ function getRegExpIteratorMember(property, budget) {
137096
137837
  const receiver = context?.thisValue;
137097
137838
  if (!isSandboxRegExpIterator(receiver))
137098
137839
  throw new TypeError("RegExp string iterator next requires a matching receiver.");
137099
- return nextRegExpIterator(receiver, budget);
137840
+ return context === void 0 ? nextRegExpIterator(receiver, budget) : nextObservableRegExpIterator(receiver, budget, context);
137100
137841
  }
137101
137842
  });
137102
137843
  }
@@ -137106,6 +137847,12 @@ var init_regexp_iterator2 = __esm({
137106
137847
  init_regexp_iterator();
137107
137848
  init_values();
137108
137849
  init_regex();
137850
+ init_object_model();
137851
+ init_accessors();
137852
+ init_interpreter();
137853
+ init_string_coercion();
137854
+ init_engine2();
137855
+ init_resources();
137109
137856
  }
137110
137857
  });
137111
137858
 
@@ -137292,8 +138039,11 @@ function getSandboxIterator(value, budget, context) {
137292
138039
  }
137293
138040
  if (isSandboxCollectionIterator(value))
137294
138041
  return { next: () => nextCollectionIterator(value, budget), snapshotIndex: () => 0 };
137295
- if (isSandboxRegExpIterator(value))
138042
+ if (isSandboxRegExpIterator(value)) {
138043
+ if (context !== void 0 && budget !== void 0)
138044
+ return { asynchronous: true, next: () => nextObservableRegExpIterator(value, budget, context), snapshotIndex: () => 0 };
137296
138045
  return { next: () => nextRegExpIterator(value, budget), snapshotIndex: () => 0 };
138046
+ }
137297
138047
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
137298
138048
  if (isFloat32Array(value)) {
137299
138049
  return syncIterator(Float32Array.prototype.values.call(value));
@@ -138606,7 +139356,7 @@ function wrapSandboxClosureForHost(closure, stackFrames, budget, compileOwner, c
138606
139356
  return wrapped;
138607
139357
  }
138608
139358
  function isSandboxLikeValue(value) {
138609
- 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") {
138610
139360
  return true;
138611
139361
  }
138612
139362
  if (isSandboxClosure(value) || isSandboxPromise(value)) {
@@ -138671,7 +139421,7 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path193) {
138671
139421
  if (options.realm === void 0 || options.errorData || options.hostCalls !== void 0) throw new TypeError("Live capabilities are not portable replay or error data.");
138672
139422
  return importHostCapability(value, options.realm.owner);
138673
139423
  }
138674
- 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") {
138675
139425
  return value;
138676
139426
  }
138677
139427
  if (typeof value === "string") {
@@ -139194,12 +139944,16 @@ var init_date2 = __esm({
139194
139944
  });
139195
139945
 
139196
139946
  // packages/safe-js/src/interp/string-coercion.ts
139197
- 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
+ };
139198
139952
  if (value === null || typeof value !== "object") {
139199
139953
  if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
139200
- return Number(value);
139954
+ return convert(value);
139201
139955
  }
139202
- return objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number").then(Number);
139956
+ return objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number").then(convert);
139203
139957
  }
139204
139958
  function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
139205
139959
  if (typeof value === "symbol") throw new TypeError("Cannot convert a Symbol value to a string");
@@ -141292,6 +142046,10 @@ function measureSandboxData(values, options = {}) {
141292
142046
  const seenSymbols = /* @__PURE__ */ new Set();
141293
142047
  let usage = 0;
141294
142048
  const visit = (value, depth = 0) => {
142049
+ if (typeof value === "bigint") {
142050
+ usage += value.toString(16).length;
142051
+ return;
142052
+ }
141295
142053
  if (typeof value === "symbol") {
141296
142054
  if (!seenSymbols.has(value)) {
141297
142055
  seenSymbols.add(value);
@@ -141550,7 +142308,7 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
141550
142308
  const copy = restoreSandboxRegExpIterator({ matcher: void 0, input: void 0, exhausted: true });
141551
142309
  state.seen.set(value, copy);
141552
142310
  const matcher = copyToSandbox(snapshot2.matcher, state, `${path193}.<matcher>`, true, depth + 1);
141553
- if (matcher !== void 0 && !isSandboxRegex(matcher)) throw new TypeError("Invalid RegExp iterator matcher.");
142311
+ if (matcher !== void 0 && (snapshot2.global === void 0 ? !isSandboxRegex(matcher) : matcher === null || typeof matcher !== "object")) throw new TypeError("Invalid RegExp iterator matcher.");
141554
142312
  restoreSandboxRegExpIterator({ ...snapshot2, matcher }, copy);
141555
142313
  for (const entry of getEnumerableObjectEntries(value, path193)) {
141556
142314
  defineOwnDataProperty(copy, entry.key, copyToSandbox(entry.value, state, joinPath2(path193, entry.key), true, depth + 1));
@@ -141738,6 +142496,7 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
141738
142496
  const copy = createPlainObject(
141739
142497
  !cloneSandboxCollections || Object.getPrototypeOf(value) === null
141740
142498
  );
142499
+ if (!state.structuredClone && hasNullObjectPrototype(value)) setSandboxPrototype(copy, null);
141741
142500
  state.seen.set(value, copy);
141742
142501
  const errorType = sandboxErrorTypes.get(value);
141743
142502
  if (errorType !== void 0) sandboxErrorTypes.set(copy, errorType);
@@ -141949,7 +142708,7 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
141949
142708
  if (existing !== void 0) {
141950
142709
  return existing;
141951
142710
  }
141952
- const copy = createPlainObject(Object.getPrototypeOf(value) === null);
142711
+ const copy = createPlainObject(hasNullObjectPrototype(value) || Object.getPrototypeOf(value) === null);
141953
142712
  state.seen.set(value, copy);
141954
142713
  for (const entry of getEnumerableObjectEntries(value, path193)) {
141955
142714
  defineOwnDataProperty(
@@ -141963,7 +142722,7 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
141963
142722
  throw new TypeError(`Unsupported sandbox value at ${path193}: ${describeValue2(value)}`);
141964
142723
  }
141965
142724
  function isSandboxPrimitive(value) {
141966
- 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";
141967
142726
  }
141968
142727
  function isHostPromise(value) {
141969
142728
  return value instanceof Promise;
@@ -142326,6 +143085,7 @@ function createDumpFile(snapshot2) {
142326
143085
  return dumped;
142327
143086
  }
142328
143087
  function serializeDumpValue(value, path193, state) {
143088
+ if (typeof value === "bigint") return { kind: "bigint", value: String(value) };
142329
143089
  if (typeof value === "symbol") return serializeSymbol(value, state.heapIds, state.heap);
142330
143090
  if (value === null || typeof value === "string" || typeof value === "boolean") {
142331
143091
  return value;
@@ -142372,11 +143132,14 @@ function serializeHeapReference(value, path193, state) {
142372
143132
  if (isSandboxRegExpIterator(value)) {
142373
143133
  const snapshot2 = regexpIteratorState(value);
142374
143134
  const matcher = snapshot2.matcher;
143135
+ const serializedMatcher = snapshot2.global === void 0 && isSandboxRegex(matcher) ? { kind: "regex", source: matcher.source, flags: matcher.flags, lastIndex: Number(matcher.lastIndex) } : serializeDumpValue(matcher, `${path193}.<matcher>`, state);
143136
+ if (serializedMatcher === SKIP_VALUE) throw new TypeError("Unsupported RegExp iterator matcher in public dump.");
142375
143137
  const entries = /* @__PURE__ */ Object.create(null);
142376
143138
  state.heap[String(id)] = {
142377
143139
  kind: "regexp-iterator",
142378
143140
  exhausted: snapshot2.exhausted,
142379
- matcher: matcher === void 0 ? { kind: "undefined" } : { kind: "regex", source: matcher.source, flags: matcher.flags, lastIndex: Number(matcher.lastIndex) },
143141
+ matcher: serializedMatcher,
143142
+ ...snapshot2.global === void 0 ? {} : { global: snapshot2.global, unicode: snapshot2.unicode },
142380
143143
  input: snapshot2.input ?? { kind: "undefined" },
142381
143144
  entries,
142382
143145
  symbolEntries: serializeSymbolProperties(value, (entry) => {
@@ -142449,6 +143212,7 @@ function serializeHeapReference(value, path193, state) {
142449
143212
  });
142450
143213
  state.heap[String(id)] = {
142451
143214
  kind: "object",
143215
+ ...hasNullObjectPrototype(value) ? { sandboxNullPrototype: true } : {},
142452
143216
  entries: serializeObjectEntries(value, path193, state),
142453
143217
  ...symbolEntries.length === 0 ? {} : { symbolEntries },
142454
143218
  ...errorType === void 0 ? {} : { errorType }
@@ -142482,7 +143246,7 @@ function indexHeapContainers(snapshot2) {
142482
143246
  const heapIds = /* @__PURE__ */ new Map();
142483
143247
  let nextId = 1;
142484
143248
  for (const [value, stat35] of stats2.entries()) {
142485
- if (stat35.count > 1 || stat35.cyclic || ownSerializableSymbolKeys(value).length > 0 || isSandboxBox(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
143249
+ if (stat35.count > 1 || stat35.cyclic || hasNullObjectPrototype(value) || ownSerializableSymbolKeys(value).length > 0 || isSandboxBox(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
142486
143250
  heapIds.set(value, nextId);
142487
143251
  nextId += 1;
142488
143252
  }
@@ -142664,6 +143428,8 @@ function validateDumpHeap(root, state) {
142664
143428
  continue;
142665
143429
  }
142666
143430
  if (entry.kind === "object") {
143431
+ if (Object.hasOwn(entry, "sandboxNullPrototype") && entry.sandboxNullPrototype !== true)
143432
+ fail2("invalidValue", `${path193}.sandboxNullPrototype`, "invalid object prototype");
142667
143433
  requireRecord3(entry.entries, `${path193}.entries`);
142668
143434
  continue;
142669
143435
  }
@@ -142747,6 +143513,14 @@ function validateValue(value, path193, depth, state) {
142747
143513
  }
142748
143514
  function validateTaggedValue(record2, path193, state) {
142749
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;
142750
143524
  case "undefined":
142751
143525
  return;
142752
143526
  case "number":
@@ -142784,7 +143558,11 @@ function validateTaggedValue(record2, path193, state) {
142784
143558
  return;
142785
143559
  case "array":
142786
143560
  case "arguments":
143561
+ return;
142787
143562
  case "object":
143563
+ if (Object.hasOwn(record2, "sandboxNullPrototype") && record2.sandboxNullPrototype !== true)
143564
+ fail2("invalidValue", `${path193}.sandboxNullPrototype`, "invalid object prototype");
143565
+ return;
142788
143566
  case "map":
142789
143567
  case "set":
142790
143568
  case "collection-iterator":
@@ -142854,6 +143632,8 @@ function validateHeapValue(value, path193, state, heap) {
142854
143632
  }
142855
143633
  if (record2.kind === "set") requireArray(record2.values, `${path193}.values`, state);
142856
143634
  if (record2.kind === "regexp-iterator") {
143635
+ if ((record2.global !== void 0 || record2.unicode !== void 0) && (typeof record2.global !== "boolean" || typeof record2.unicode !== "boolean"))
143636
+ fail2("invalidValue", path193, "invalid RegExp iterator modes");
142857
143637
  if (typeof record2.exhausted !== "boolean") fail2("invalidValue", `${path193}.exhausted`, "invalid iterator exhaustion");
142858
143638
  if (!Object.hasOwn(record2, "matcher") || !Object.hasOwn(record2, "input")) fail2("invalidValue", path193, "missing RegExp iterator state");
142859
143639
  requireRecord3(record2.entries, `${path193}.entries`);
@@ -142907,6 +143687,14 @@ function validateBoxedRecord(record2, path193, heap) {
142907
143687
  const value = record2.value;
142908
143688
  if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") return;
142909
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
+ }
142910
143698
  if (number.kind === "ref") {
142911
143699
  const id = requireSafeInteger(number.id, `${path193}.value.id`, 1);
142912
143700
  const target = requireRecord3(heap[String(id)], `${path193}.value`);
@@ -143153,6 +143941,7 @@ var init_validation = __esm({
143153
143941
  "packages/safe-js/src/snapshot/validation.ts"() {
143154
143942
  "use strict";
143155
143943
  init_shape();
143944
+ init_bigint();
143156
143945
  init_regexp_properties2();
143157
143946
  init_symbols2();
143158
143947
  init_dump_format();
@@ -144066,6 +144855,7 @@ var init_known_globals = __esm({
144066
144855
  "AggregateError",
144067
144856
  "Array",
144068
144857
  "Boolean",
144858
+ "BigInt",
144069
144859
  "Date",
144070
144860
  "Error",
144071
144861
  "Infinity",
@@ -147310,6 +148100,7 @@ function expressionContainsAwait(node) {
147310
148100
  case "MetaProperty":
147311
148101
  case "NullLiteral":
147312
148102
  case "NumericLiteral":
148103
+ case "BigIntLiteral":
147313
148104
  case "RegexLiteral":
147314
148105
  case "StringLiteral":
147315
148106
  case "ThisExpression":
@@ -147593,6 +148384,7 @@ var init_AS_async_not_needed = __esm({
147593
148384
  case "MetaProperty":
147594
148385
  case "NullLiteral":
147595
148386
  case "NumericLiteral":
148387
+ case "BigIntLiteral":
147596
148388
  case "RegexLiteral":
147597
148389
  case "StringLiteral":
147598
148390
  case "UndefinedLiteral":
@@ -151072,6 +151864,7 @@ function expressionContainsAwait2(node) {
151072
151864
  case "MetaProperty":
151073
151865
  case "NullLiteral":
151074
151866
  case "NumericLiteral":
151867
+ case "BigIntLiteral":
151075
151868
  case "RegexLiteral":
151076
151869
  case "StringLiteral":
151077
151870
  case "ThisExpression":
@@ -151343,6 +152136,7 @@ var init_AS_missing_async = __esm({
151343
152136
  case "MetaProperty":
151344
152137
  case "NullLiteral":
151345
152138
  case "NumericLiteral":
152139
+ case "BigIntLiteral":
151346
152140
  case "RegexLiteral":
151347
152141
  case "StringLiteral":
151348
152142
  case "UndefinedLiteral":
@@ -154726,29 +155520,53 @@ function createConsoleJsonGlobals(options) {
154726
155520
  };
154727
155521
  }
154728
155522
  async function stringifyJson4(value, replacer, indent, budget, context) {
154729
- if (replacer !== void 0 && replacer !== null && !isSandboxClosure(replacer)) {
154730
- throw new TypeError(
154731
- "JSON.stringify(value, replacer, indent) only supports function, null, or undefined replacers."
154732
- );
154733
- }
154734
- if (indent !== void 0 && typeof indent !== "number" && typeof indent !== "string") {
154735
- throw new TypeError(
154736
- "JSON.stringify(value, replacer, indent) requires indent to be a string, number, or undefined."
154737
- );
154738
- }
154739
- const holder = {};
154740
- defineDataProperty9(holder, "", value);
154741
- const output = await stringifyProperty("", holder, {
154742
- budget,
154743
- context,
154744
- gap: normalizeStringifyGap(indent),
154745
- replacer: isSandboxClosure(replacer) ? replacer : void 0,
154746
- stack: []
154747
- });
154748
- if (output === void 0) {
154749
- return void 0;
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();
154750
155569
  }
154751
- return budget.allocateString(output);
154752
155570
  }
154753
155571
  async function stringifyProperty(key3, holder, state, indent = "") {
154754
155572
  let value = await getStringifyProperty(holder, key3, state);
@@ -154756,7 +155574,7 @@ async function stringifyProperty(key3, holder, state, indent = "") {
154756
155574
  try {
154757
155575
  if (isSandboxDate(value) && getSandboxPropertyDescriptor(value, "toJSON", state.budget) === void 0) {
154758
155576
  value = await dateToJSON(value, state.budget, state.context);
154759
- } else if (isStringifyContainer(value)) {
155577
+ } else if (typeof value === "bigint" || isSandboxClosure(value) || isStringifyContainer(value)) {
154760
155578
  const toJSON = await getStringifyProperty(value, "toJSON", state);
154761
155579
  if (isSandboxClosure(toJSON)) {
154762
155580
  value = await callStringifyClosure(toJSON, [key3], value, state);
@@ -154838,7 +155656,7 @@ async function stringifyObject(value, state, indent) {
154838
155656
  const release2 = retainValues(state.budget, () => entries);
154839
155657
  try {
154840
155658
  const nextIndent = indent + state.gap;
154841
- for (const key3 of Object.keys(value)) {
155659
+ for (const key3 of state.propertyList ?? Object.keys(value)) {
154842
155660
  const serialized = await stringifyProperty(key3, value, state, nextIndent);
154843
155661
  if (serialized !== void 0) {
154844
155662
  entries.push(`${quoteJsonString(key3)}:${state.gap === "" ? "" : " "}${serialized}`);
@@ -154901,19 +155719,17 @@ function isStringifyObject(value) {
154901
155719
  return isStringifyContainer(value) && !Array.isArray(value);
154902
155720
  }
154903
155721
  function toSandboxValue(value) {
154904
- 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)) {
154905
155723
  return value;
154906
155724
  }
154907
- if (typeof value === "bigint") {
154908
- throw new TypeError("Do not know how to serialize a BigInt.");
154909
- }
154910
155725
  throw new TypeError(
154911
155726
  `JSON.stringify(value) produced an unsupported value of type ${typeof value}.`
154912
155727
  );
154913
155728
  }
154914
155729
  function getStringifyProperty(target, key3, state) {
154915
155730
  if (state.context?.getProperty !== void 0) return state.context.getProperty(target, key3);
154916
- const descriptor = getSandboxPropertyDescriptor(target, key3, state.budget);
155731
+ const object = typeof target === "bigint" ? getBoxedPrototype(target, state.budget) : target;
155732
+ const descriptor = object === void 0 ? void 0 : getSandboxPropertyDescriptor(object, key3, state.budget);
154917
155733
  return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, target, state.context);
154918
155734
  }
154919
155735
  function copyJsonToSandbox(value, budget) {
@@ -155079,6 +155895,104 @@ var init_math = __esm({
155079
155895
  }
155080
155896
  });
155081
155897
 
155898
+ // packages/safe-js/src/interp/methods/regex-split.ts
155899
+ async function regexSplit(target, input, limit, constructor, budget, context) {
155900
+ if (target === null || typeof target !== "object") throw new TypeError("RegExp split requires an object receiver.");
155901
+ let string;
155902
+ let species;
155903
+ let field;
155904
+ let flags;
155905
+ let matcher;
155906
+ let match;
155907
+ const result = [];
155908
+ const release2 = retainValues(budget, () => [target, input, limit, string, species, field, flags, matcher, match, result]);
155909
+ const read = (value, key3) => {
155910
+ if (context?.getProperty !== void 0) return context.getProperty(value, key3);
155911
+ const descriptor = getSandboxPropertyDescriptor(value, key3, budget);
155912
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
155913
+ };
155914
+ const append = (value) => {
155915
+ budget.allocateArrayLength(result.length + 1);
155916
+ result.push(value);
155917
+ };
155918
+ try {
155919
+ string = await sandboxString(input, budget, context);
155920
+ input = void 0;
155921
+ field = await read(target, "constructor");
155922
+ species = constructor;
155923
+ if (field !== void 0) {
155924
+ if (field === null || typeof field !== "object") throw new TypeError("Invalid RegExp species constructor.");
155925
+ species = await read(field, Symbol.species);
155926
+ if (species === null || species === void 0) species = constructor;
155927
+ }
155928
+ field = void 0;
155929
+ if (!isSandboxClosure(species) || species.construct === void 0) throw new TypeError("RegExp species must be a constructor.");
155930
+ field = await read(target, "flags");
155931
+ flags = await sandboxString(field, budget, context);
155932
+ field = void 0;
155933
+ const unicode = flags.includes("u") || flags.includes("v");
155934
+ if (!flags.includes("y")) flags = budget.allocateString(flags + "y");
155935
+ matcher = await invokeBuiltinClosure(species, [target, flags], budget, context, void 0, true);
155936
+ const maximum = limit === void 0 ? 2 ** 32 - 1 : await sandboxNumber(limit, budget, context) >>> 0;
155937
+ limit = void 0;
155938
+ if (maximum === 0) return result;
155939
+ if (string.length === 0) {
155940
+ match = await regexExec(matcher, string, budget, context);
155941
+ if (match === null) append(string);
155942
+ return result;
155943
+ }
155944
+ let end = 0;
155945
+ let index = 0;
155946
+ while (index < string.length) {
155947
+ budget.visitNode();
155948
+ match = void 0;
155949
+ await setSandboxProperty(matcher, "lastIndex", index, budget, true, context);
155950
+ match = await regexExec(matcher, string, budget, context);
155951
+ if (match !== null) {
155952
+ field = await read(matcher, "lastIndex");
155953
+ const next = Math.min(normalizeLastIndex(await sandboxNumber(field, budget, context)), string.length);
155954
+ field = void 0;
155955
+ if (next !== end) {
155956
+ append(budget.allocateString(string.slice(end, index)));
155957
+ if (result.length === maximum) return result;
155958
+ end = next;
155959
+ field = await read(match, "length");
155960
+ const length = normalizeLastIndex(await sandboxNumber(field, budget, context));
155961
+ field = void 0;
155962
+ for (let capture = 1; capture < length; capture++) {
155963
+ budget.visitNode();
155964
+ field = await read(match, String(capture));
155965
+ append(field);
155966
+ field = void 0;
155967
+ if (result.length === maximum) return result;
155968
+ }
155969
+ index = end;
155970
+ continue;
155971
+ }
155972
+ }
155973
+ index += unicode && (string.codePointAt(index) ?? 0) > 65535 ? 2 : 1;
155974
+ }
155975
+ append(budget.allocateString(string.slice(end)));
155976
+ return result;
155977
+ } finally {
155978
+ release2();
155979
+ }
155980
+ }
155981
+ var init_regex_split = __esm({
155982
+ "packages/safe-js/src/interp/methods/regex-split.ts"() {
155983
+ "use strict";
155984
+ init_values();
155985
+ init_object_model();
155986
+ init_accessors();
155987
+ init_builtin_call();
155988
+ init_interpreter();
155989
+ init_string_coercion();
155990
+ init_engine2();
155991
+ init_resources();
155992
+ init_regex();
155993
+ }
155994
+ });
155995
+
155082
155996
  // packages/safe-js/src/interp/globals/regex.ts
155083
155997
  function createRegexGlobals(options) {
155084
155998
  const invoke2 = (construct) => async (args, context) => {
@@ -155143,7 +156057,55 @@ function createRegexGlobals(options) {
155143
156057
  }
155144
156058
  };
155145
156059
  const constructor = createSandboxClosure({ guest: true, sandbox: true, name: "RegExp", length: 2, call: invoke2(false), construct: invoke2(true) });
156060
+ Object.defineProperty(materializeFunctionProperties(constructor), "escape", {
156061
+ value: createSandboxClosure({
156062
+ guest: true,
156063
+ sandbox: true,
156064
+ name: "escape",
156065
+ length: 1,
156066
+ call: (args) => {
156067
+ const input = args[0];
156068
+ if (typeof input !== "string") throw new TypeError("RegExp.escape requires a string.");
156069
+ const allocation = {};
156070
+ let escaped = "";
156071
+ try {
156072
+ for (const character2 of input) {
156073
+ options.budget.visitNode();
156074
+ const point = character2.codePointAt(0);
156075
+ let part = character2;
156076
+ if (escaped.length === 0 && (point >= 48 && point <= 57 || point >= 65 && point <= 90 || point >= 97 && point <= 122)) {
156077
+ part = `\\x${point.toString(16)}`;
156078
+ } else if ("^$\\.*+?()[]{}|/".includes(character2)) {
156079
+ part = "\\" + character2;
156080
+ } else {
156081
+ const control2 = "\f\n\r \v".indexOf(character2);
156082
+ if (control2 !== -1) part = "\\" + "fnrtv"[control2];
156083
+ else if (",-=<>#&!%:;@~'`\"".includes(character2) || character2.trim() === "" || point >= 55296 && point <= 57343) {
156084
+ part = point <= 255 ? `\\x${point.toString(16).padStart(2, "0")}` : `\\u${point.toString(16).padStart(4, "0")}`;
156085
+ }
156086
+ }
156087
+ options.budget.setRetainedDataUsage(allocation, escaped.length + part.length);
156088
+ escaped = options.budget.allocateString(escaped + part);
156089
+ }
156090
+ return escaped;
156091
+ } finally {
156092
+ options.budget.setRetainedDataUsage(allocation, 0);
156093
+ }
156094
+ }
156095
+ }),
156096
+ writable: true,
156097
+ configurable: true
156098
+ });
155146
156099
  const prototype = /* @__PURE__ */ Object.create(null);
156100
+ Object.defineProperty(materializeFunctionProperties(constructor), Symbol.species, {
156101
+ get: accessorAdapter(createSandboxClosure({
156102
+ sandbox: true,
156103
+ name: "get [Symbol.species]",
156104
+ length: 0,
156105
+ call: (_args, context) => context?.thisValue
156106
+ }), "get"),
156107
+ configurable: true
156108
+ });
155147
156109
  Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
155148
156110
  Object.defineProperty(prototype, "constructor", { value: constructor, writable: true, configurable: true });
155149
156111
  Object.defineProperty(prototype, Symbol.search, {
@@ -155186,6 +156148,73 @@ function createRegexGlobals(options) {
155186
156148
  writable: true,
155187
156149
  configurable: true
155188
156150
  });
156151
+ Object.defineProperty(prototype, Symbol.matchAll, {
156152
+ value: createSandboxClosure({
156153
+ guest: true,
156154
+ sandbox: true,
156155
+ name: "[Symbol.matchAll]",
156156
+ length: 1,
156157
+ call: async (args, context) => {
156158
+ const target = context?.thisValue;
156159
+ if (target === null || typeof target !== "object") throw new TypeError("RegExp matchAll requires an object receiver.");
156160
+ let input = args[0];
156161
+ let string;
156162
+ let species;
156163
+ let field;
156164
+ let flags;
156165
+ let matcher;
156166
+ const release2 = retainValues(options.budget, () => [target, input, string, species, field, flags, matcher]);
156167
+ const read = (value, key3) => {
156168
+ if (context?.getProperty !== void 0) return context.getProperty(value, key3);
156169
+ const descriptor = getSandboxPropertyDescriptor(value, key3, options.budget);
156170
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
156171
+ };
156172
+ try {
156173
+ string = await sandboxString(input, options.budget, context);
156174
+ input = void 0;
156175
+ field = await read(target, "constructor");
156176
+ species = constructor;
156177
+ if (field !== void 0) {
156178
+ if (field === null || typeof field !== "object") throw new TypeError("Invalid RegExp species constructor.");
156179
+ species = await read(field, Symbol.species);
156180
+ if (species === null || species === void 0) species = constructor;
156181
+ }
156182
+ field = void 0;
156183
+ if (!isSandboxClosure(species) || species.construct === void 0) throw new TypeError("RegExp species must be a constructor.");
156184
+ field = await read(target, "flags");
156185
+ flags = await sandboxString(field, options.budget, context);
156186
+ field = void 0;
156187
+ matcher = await invokeBuiltinClosure(species, [target, flags], options.budget, context, void 0, true);
156188
+ field = await read(target, "lastIndex");
156189
+ const cursor2 = normalizeLastIndex(await sandboxNumber(field, options.budget, context));
156190
+ field = void 0;
156191
+ await setSandboxProperty(matcher, "lastIndex", cursor2, options.budget, true, context);
156192
+ return restoreSandboxRegExpIterator({
156193
+ matcher,
156194
+ input: string,
156195
+ exhausted: false,
156196
+ global: flags.includes("g"),
156197
+ unicode: flags.includes("u") || flags.includes("v")
156198
+ });
156199
+ } finally {
156200
+ release2();
156201
+ }
156202
+ }
156203
+ }),
156204
+ writable: true,
156205
+ configurable: true
156206
+ });
156207
+ Object.defineProperty(prototype, Symbol.split, {
156208
+ value: createSandboxClosure({
156209
+ guest: true,
156210
+ sandbox: true,
156211
+ name: "[Symbol.split]",
156212
+ length: 2,
156213
+ call: (args, context) => regexSplit(context?.thisValue, args[0], args[1], constructor, options.budget, context)
156214
+ }),
156215
+ writable: true,
156216
+ configurable: true
156217
+ });
155189
156218
  for (const name of ["exec", "test", "toString"]) {
155190
156219
  Object.defineProperty(prototype, name, {
155191
156220
  value: createSandboxClosure({
@@ -155231,6 +156260,11 @@ var init_regex2 = __esm({
155231
156260
  init_regex();
155232
156261
  init_string();
155233
156262
  init_builtin_call();
156263
+ init_regexp_iterator();
156264
+ init_engine2();
156265
+ init_resources();
156266
+ init_interpreter();
156267
+ init_regex_split();
155234
156268
  }
155235
156269
  });
155236
156270
 
@@ -155434,6 +156468,109 @@ var init_symbol = __esm({
155434
156468
  }
155435
156469
  });
155436
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
+
155437
156574
  // packages/safe-js/src/interp/globals.ts
155438
156575
  function createBuiltinBindings(options) {
155439
156576
  return {
@@ -155442,6 +156579,7 @@ function createBuiltinBindings(options) {
155442
156579
  Float32Array: createFloat32ArrayGlobal(options.budget),
155443
156580
  Date: createDateGlobal(options),
155444
156581
  Symbol: createSymbolGlobal(options.budget),
156582
+ BigInt: createBigIntGlobal(options.budget),
155445
156583
  ...createErrorGlobals(options),
155446
156584
  ...createMathGlobals({ random: options.random }),
155447
156585
  ...createObjectArrayGlobals(options),
@@ -155464,6 +156602,7 @@ var init_globals = __esm({
155464
156602
  init_promise();
155465
156603
  init_date2();
155466
156604
  init_symbol();
156605
+ init_bigint2();
155467
156606
  }
155468
156607
  });
155469
156608