@poe-platform/safe-js 0.1.189 → 0.1.191

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.
@@ -6723,9 +6723,13 @@ function isSandboxRegExpIterator(value) {
6723
6723
  return typeof value === "object" && value !== null && states2.has(value);
6724
6724
  }
6725
6725
  function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.create(null)) {
6726
+ if ((state.global !== void 0 || state.unicode !== void 0) && (typeof state.global !== "boolean" || typeof state.unicode !== "boolean"))
6727
+ throw new TypeError("Invalid RegExp iterator modes.");
6728
+ if (state.matcher !== void 0 && (state.matcher === null || typeof state.matcher !== "object"))
6729
+ throw new TypeError("Invalid RegExp iterator matcher.");
6726
6730
  if (!state.exhausted && (state.matcher === void 0 || state.input === void 0))
6727
6731
  throw new TypeError("A live RegExp iterator requires its matcher and input.");
6728
- states2.set(target, state.exhausted ? { matcher: void 0, input: void 0, exhausted: true } : { ...state });
6732
+ states2.set(target, state.exhausted ? { ...state, matcher: void 0, input: void 0, exhausted: true } : { ...state });
6729
6733
  return target;
6730
6734
  }
6731
6735
  function regexpIteratorState(value) {
@@ -7956,11 +7960,14 @@ function serializeHeapReference(value, path, state) {
7956
7960
  if (isSandboxRegExpIterator(value)) {
7957
7961
  const snapshot = regexpIteratorState(value);
7958
7962
  const matcher = snapshot.matcher;
7963
+ const serializedMatcher = snapshot.global === void 0 && isSandboxRegex(matcher) ? { kind: "regex", source: matcher.source, flags: matcher.flags, lastIndex: Number(matcher.lastIndex) } : serializeDumpValue(matcher, `${path}.<matcher>`, state);
7964
+ if (serializedMatcher === SKIP_VALUE) throw new TypeError("Unsupported RegExp iterator matcher in public dump.");
7959
7965
  const entries = /* @__PURE__ */ Object.create(null);
7960
7966
  state.heap[String(id)] = {
7961
7967
  kind: "regexp-iterator",
7962
7968
  exhausted: snapshot.exhausted,
7963
- matcher: matcher === void 0 ? { kind: "undefined" } : { kind: "regex", source: matcher.source, flags: matcher.flags, lastIndex: Number(matcher.lastIndex) },
7969
+ matcher: serializedMatcher,
7970
+ ...snapshot.global === void 0 ? {} : { global: snapshot.global, unicode: snapshot.unicode },
7964
7971
  input: snapshot.input ?? { kind: "undefined" },
7965
7972
  entries,
7966
7973
  symbolEntries: serializeSymbolProperties(value, (entry) => {
@@ -8442,6 +8449,8 @@ function validateHeapValue(value, path, state, heap) {
8442
8449
  }
8443
8450
  if (record2.kind === "set") requireArray(record2.values, `${path}.values`, state);
8444
8451
  if (record2.kind === "regexp-iterator") {
8452
+ if ((record2.global !== void 0 || record2.unicode !== void 0) && (typeof record2.global !== "boolean" || typeof record2.unicode !== "boolean"))
8453
+ fail("invalidValue", path, "invalid RegExp iterator modes");
8445
8454
  if (typeof record2.exhausted !== "boolean") fail("invalidValue", `${path}.exhausted`, "invalid iterator exhaustion");
8446
8455
  if (!Object.hasOwn(record2, "matcher") || !Object.hasOwn(record2, "input")) fail("invalidValue", path, "missing RegExp iterator state");
8447
8456
  requireRecord(record2.entries, `${path}.entries`);
@@ -10068,7 +10077,7 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure, use
10068
10077
  }
10069
10078
  async function replaceRegex(value, regex, replacement, budget, callClosure, context) {
10070
10079
  if (hasRegexPropertyOverride(regex, ["exec", "flags", ...Object.keys(regexFlagProperties)], budget))
10071
- return replaceObservableRegex(value, regex, replacement, budget, callClosure, context);
10080
+ return regexReplace(value, regex, replacement, budget, callClosure, context);
10072
10081
  if (regex.flags.includes("g")) regex.lastIndex = 0;
10073
10082
  const cursor = regex.lastIndex;
10074
10083
  let result = "";
@@ -10099,7 +10108,10 @@ function readReplacementProperty(target, key, budget, context) {
10099
10108
  if (descriptor !== void 0) return readPropertyDescriptor(descriptor, target, context);
10100
10109
  return isSandboxRegex(target) ? getRegexMember(target, key, budget, context) : void 0;
10101
10110
  }
10102
- async function replaceObservableRegex(value, regex, replacement, budget, callClosure, context) {
10111
+ async function regexReplace(input, regex, replacementInput, budget, callClosure, context) {
10112
+ if (regex === null || typeof regex !== "object") throw new TypeError("RegExp replace requires an object receiver.");
10113
+ let value;
10114
+ let replacement;
10103
10115
  const matches = [];
10104
10116
  let current;
10105
10117
  let field;
@@ -10108,15 +10120,23 @@ async function replaceObservableRegex(value, regex, replacement, budget, callClo
10108
10120
  let captures = [];
10109
10121
  let result = "";
10110
10122
  let flags;
10111
- const release = retainValues(budget, () => [value, regex, replacement, matches, current, field, groups, matched, captures, result, flags]);
10123
+ const release = retainValues(budget, () => [input, value, regex, replacementInput, replacement, matches, current, field, groups, matched, captures, result, flags]);
10112
10124
  try {
10125
+ value = await sandboxString(input, budget, context);
10126
+ input = void 0;
10127
+ replacement = isSandboxClosure(replacementInput) ? replacementInput : await sandboxString(replacementInput, budget, context);
10128
+ replacementInput = void 0;
10129
+ if (isSandboxRegex(regex) && !hasRegexPropertyOverride(regex, ["exec", "flags", ...Object.keys(regexFlagProperties)], budget)) {
10130
+ release();
10131
+ return await replaceRegex(value, regex, replacement, budget, callClosure, context);
10132
+ }
10113
10133
  field = await readReplacementProperty(regex, "flags", budget, context);
10114
10134
  flags = await sandboxString(field, budget, context);
10115
10135
  field = void 0;
10116
10136
  const global = flags.includes("g");
10117
10137
  const fullUnicode = flags.includes("u") || flags.includes("v");
10118
10138
  flags = void 0;
10119
- if (global) regex.lastIndex = 0;
10139
+ if (global) await setSandboxProperty(regex, "lastIndex", 0, budget, true, context);
10120
10140
  while (true) {
10121
10141
  budget.visitNode();
10122
10142
  current = await regexExec(regex, value, budget, context);
@@ -10128,10 +10148,10 @@ async function replaceObservableRegex(value, regex, replacement, budget, callClo
10128
10148
  matched = await sandboxString(field, budget, context);
10129
10149
  field = void 0;
10130
10150
  if (matched.length === 0) {
10131
- field = regex.lastIndex;
10151
+ field = await readReplacementProperty(regex, "lastIndex", budget, context);
10132
10152
  const index = normalizeLastIndex(await sandboxNumber(field, budget, context));
10133
10153
  const point = fullUnicode ? value.codePointAt(index) : void 0;
10134
- regex.lastIndex = index + (point !== void 0 && point > 65535 ? 2 : 1);
10154
+ await setSandboxProperty(regex, "lastIndex", index + (point !== void 0 && point > 65535 ? 2 : 1), budget, true, context);
10135
10155
  field = void 0;
10136
10156
  }
10137
10157
  matched = void 0;
@@ -16716,9 +16736,10 @@ function nextRegExpIterator(iterator, budget) {
16716
16736
  budget?.visitNode();
16717
16737
  if (state.exhausted) return { value: void 0, done: true };
16718
16738
  const matcher = state.matcher;
16739
+ if (!isSandboxRegex(matcher)) throw new TypeError("Custom RegExp iterator execution requires a sandbox context.");
16719
16740
  const input = state.input;
16720
16741
  const match = executeRegex(matcher, input, Number(matcher.lastIndex));
16721
- if (match === null || !matcher.flags.includes("g")) {
16742
+ if (match === null || !(state.global ?? matcher.flags.includes("g"))) {
16722
16743
  state.exhausted = true;
16723
16744
  state.matcher = void 0;
16724
16745
  state.input = void 0;
@@ -16726,13 +16747,54 @@ function nextRegExpIterator(iterator, budget) {
16726
16747
  if (match === null) return { value: void 0, done: true };
16727
16748
  if (!state.exhausted && match.text.length === 0) {
16728
16749
  const index = Number(matcher.lastIndex);
16729
- const unicode = matcher.flags.includes("u") || matcher.flags.includes("v");
16750
+ const unicode = state.unicode ?? (matcher.flags.includes("u") || matcher.flags.includes("v"));
16730
16751
  const codePoint = input.codePointAt(index);
16731
16752
  matcher.lastIndex = index + (unicode && codePoint !== void 0 && codePoint > 65535 ? 2 : 1);
16732
16753
  }
16733
16754
  budget?.allocateArrayLength(match.captures.length + 1);
16734
16755
  return { value: toMatchArray(match, input), done: false };
16735
16756
  }
16757
+ async function nextObservableRegExpIterator(iterator, budget, context) {
16758
+ const state = regexpIteratorState(iterator);
16759
+ if (state.exhausted) return { value: void 0, done: true };
16760
+ const matcher = state.matcher;
16761
+ if (isSandboxRegex(matcher) && !hasRegexPropertyOverride(matcher, ["exec"], budget) && (matcher.lastIndex === null || typeof matcher.lastIndex !== "object"))
16762
+ return nextRegExpIterator(iterator, budget);
16763
+ const input = state.input;
16764
+ let result;
16765
+ let field;
16766
+ const release = retainValues(budget, () => [iterator, matcher, input, result, field]);
16767
+ const read = (value, key) => {
16768
+ if (context.getProperty !== void 0) return context.getProperty(value, key);
16769
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
16770
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
16771
+ };
16772
+ try {
16773
+ budget.visitNode();
16774
+ result = await regexExec(matcher, input, budget, context);
16775
+ const global = state.global ?? (isSandboxRegex(matcher) && matcher.flags.includes("g"));
16776
+ if (result === null || !global) {
16777
+ state.exhausted = true;
16778
+ state.matcher = void 0;
16779
+ state.input = void 0;
16780
+ return result === null ? { value: void 0, done: true } : { value: result, done: false };
16781
+ }
16782
+ field = await read(result, "0");
16783
+ const text = await sandboxString(field, budget, context);
16784
+ field = void 0;
16785
+ if (text.length === 0) {
16786
+ field = await read(matcher, "lastIndex");
16787
+ const index = normalizeLastIndex(await sandboxNumber(field, budget, context));
16788
+ field = void 0;
16789
+ const unicode = state.unicode ?? (isSandboxRegex(matcher) && (matcher.flags.includes("u") || matcher.flags.includes("v")));
16790
+ const point = input.codePointAt(index);
16791
+ await setSandboxProperty(matcher, "lastIndex", index + (unicode && point !== void 0 && point > 65535 ? 2 : 1), budget, true, context);
16792
+ }
16793
+ return { value: result, done: false };
16794
+ } finally {
16795
+ release();
16796
+ }
16797
+ }
16736
16798
  function getRegExpIteratorMember(property, budget) {
16737
16799
  if (property === Symbol.toStringTag) return "RegExp String Iterator";
16738
16800
  if (property === Symbol.iterator) return createSandboxClosure({
@@ -16748,7 +16810,7 @@ function getRegExpIteratorMember(property, budget) {
16748
16810
  const receiver = context?.thisValue;
16749
16811
  if (!isSandboxRegExpIterator(receiver))
16750
16812
  throw new TypeError("RegExp string iterator next requires a matching receiver.");
16751
- return nextRegExpIterator(receiver, budget);
16813
+ return context === void 0 ? nextRegExpIterator(receiver, budget) : nextObservableRegExpIterator(receiver, budget, context);
16752
16814
  }
16753
16815
  });
16754
16816
  }
@@ -16936,8 +16998,11 @@ function getSandboxIterator(value, budget, context) {
16936
16998
  }
16937
16999
  if (isSandboxCollectionIterator(value))
16938
17000
  return { next: () => nextCollectionIterator(value, budget), snapshotIndex: () => 0 };
16939
- if (isSandboxRegExpIterator(value))
17001
+ if (isSandboxRegExpIterator(value)) {
17002
+ if (context !== void 0 && budget !== void 0)
17003
+ return { asynchronous: true, next: () => nextObservableRegExpIterator(value, budget, context), snapshotIndex: () => 0 };
16940
17004
  return { next: () => nextRegExpIterator(value, budget), snapshotIndex: () => 0 };
17005
+ }
16941
17006
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
16942
17007
  if (isFloat32Array(value)) {
16943
17008
  return syncIterator(Float32Array.prototype.values.call(value));
@@ -17744,7 +17809,16 @@ function encodeReplayData(value, options = {}) {
17744
17809
  }
17745
17810
  let symbolIndex = 0;
17746
17811
  const symbolEntries = serializeSymbolProperties(entry, (value2) => encode(value2, depth + 1, [...path, { symbol: Math.floor(symbolIndex++ / 2) }]));
17747
- nodes[id] = { kind: "regexp-iterator", matcher: child(snapshot.matcher, "<matcher>"), input: child(snapshot.input, "<input>"), exhausted: snapshot.exhausted, properties, extensible: Object.isExtensible(entry), symbolEntries };
17812
+ nodes[id] = {
17813
+ kind: "regexp-iterator",
17814
+ matcher: child(snapshot.matcher, "<matcher>"),
17815
+ input: child(snapshot.input, "<input>"),
17816
+ exhausted: snapshot.exhausted,
17817
+ properties,
17818
+ extensible: Object.isExtensible(entry),
17819
+ symbolEntries,
17820
+ ...snapshot.global === void 0 ? {} : { global: snapshot.global, unicode: snapshot.unicode }
17821
+ };
17748
17822
  } else if (isSandboxCollectionIterator(entry)) {
17749
17823
  const snapshot = snapshotCollectionIterator(entry);
17750
17824
  const properties = /* @__PURE__ */ Object.create(null);
@@ -17942,9 +18016,15 @@ function decodeReplayData(input, options = {}, parent) {
17942
18016
  restored.set(id, result3);
17943
18017
  const matcher = child(own(node, "matcher"));
17944
18018
  const input2 = child(own(node, "input"));
17945
- if (matcher !== void 0 && !isSandboxRegex(matcher)) throw new TypeError("Invalid replay RegExp iterator matcher.");
18019
+ 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.");
18020
+ if (matcher !== void 0 && (node.global === void 0 ? !isSandboxRegex(matcher) : matcher === null || typeof matcher !== "object")) throw new TypeError("Invalid replay RegExp iterator matcher.");
17946
18021
  if (input2 !== void 0 && typeof input2 !== "string") throw new TypeError("Invalid replay RegExp iterator input.");
17947
- restoreSandboxRegExpIterator({ matcher, input: input2, exhausted }, result3);
18022
+ restoreSandboxRegExpIterator({
18023
+ matcher,
18024
+ input: input2,
18025
+ exhausted,
18026
+ ...node.global === void 0 ? {} : { global: node.global, unicode: node.unicode }
18027
+ }, result3);
17948
18028
  defineProperties(result3, record(own(node, "properties")), child, node.symbolEntries);
17949
18029
  if (!node.extensible) Object.preventExtensions(result3);
17950
18030
  return result3;
@@ -21461,7 +21541,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
21461
21541
  const copy = restoreSandboxRegExpIterator({ matcher: void 0, input: void 0, exhausted: true });
21462
21542
  state.seen.set(value, copy);
21463
21543
  const matcher = copyToSandbox(snapshot.matcher, state, `${path}.<matcher>`, true, depth + 1);
21464
- if (matcher !== void 0 && !isSandboxRegex(matcher)) throw new TypeError("Invalid RegExp iterator matcher.");
21544
+ if (matcher !== void 0 && (snapshot.global === void 0 ? !isSandboxRegex(matcher) : matcher === null || typeof matcher !== "object")) throw new TypeError("Invalid RegExp iterator matcher.");
21465
21545
  restoreSandboxRegExpIterator({ ...snapshot, matcher }, copy);
21466
21546
  for (const entry of getEnumerableObjectEntries(value, path)) {
21467
21547
  defineOwnDataProperty(copy, entry.key, copyToSandbox(entry.value, state, joinPath2(path, entry.key), true, depth + 1));
@@ -34442,6 +34522,15 @@ function createRegexGlobals(options) {
34442
34522
  };
34443
34523
  const constructor = createSandboxClosure({ guest: true, sandbox: true, name: "RegExp", length: 2, call: invoke(false), construct: invoke(true) });
34444
34524
  const prototype = /* @__PURE__ */ Object.create(null);
34525
+ Object.defineProperty(materializeFunctionProperties(constructor), Symbol.species, {
34526
+ get: accessorAdapter(createSandboxClosure({
34527
+ sandbox: true,
34528
+ name: "get [Symbol.species]",
34529
+ length: 0,
34530
+ call: (_args, context) => context?.thisValue
34531
+ }), "get"),
34532
+ configurable: true
34533
+ });
34445
34534
  Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
34446
34535
  Object.defineProperty(prototype, "constructor", { value: constructor, writable: true, configurable: true });
34447
34536
  Object.defineProperty(prototype, Symbol.search, {
@@ -34466,6 +34555,80 @@ function createRegexGlobals(options) {
34466
34555
  writable: true,
34467
34556
  configurable: true
34468
34557
  });
34558
+ Object.defineProperty(prototype, Symbol.replace, {
34559
+ value: createSandboxClosure({
34560
+ guest: true,
34561
+ sandbox: true,
34562
+ name: "[Symbol.replace]",
34563
+ length: 2,
34564
+ call: (args, context) => regexReplace(
34565
+ args[0],
34566
+ context?.thisValue,
34567
+ args[1],
34568
+ options.budget,
34569
+ (closure, values) => invokeBuiltinClosure(closure, values, options.budget, context, void 0),
34570
+ context
34571
+ )
34572
+ }),
34573
+ writable: true,
34574
+ configurable: true
34575
+ });
34576
+ Object.defineProperty(prototype, Symbol.matchAll, {
34577
+ value: createSandboxClosure({
34578
+ guest: true,
34579
+ sandbox: true,
34580
+ name: "[Symbol.matchAll]",
34581
+ length: 1,
34582
+ call: async (args, context) => {
34583
+ const target = context?.thisValue;
34584
+ if (target === null || typeof target !== "object") throw new TypeError("RegExp matchAll requires an object receiver.");
34585
+ let input = args[0];
34586
+ let string;
34587
+ let species;
34588
+ let field;
34589
+ let flags;
34590
+ let matcher;
34591
+ const release = retainValues(options.budget, () => [target, input, string, species, field, flags, matcher]);
34592
+ const read = (value, key) => {
34593
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
34594
+ const descriptor = getSandboxPropertyDescriptor(value, key, options.budget);
34595
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
34596
+ };
34597
+ try {
34598
+ string = await sandboxString(input, options.budget, context);
34599
+ input = void 0;
34600
+ field = await read(target, "constructor");
34601
+ species = constructor;
34602
+ if (field !== void 0) {
34603
+ if (field === null || typeof field !== "object") throw new TypeError("Invalid RegExp species constructor.");
34604
+ species = await read(field, Symbol.species);
34605
+ if (species === null || species === void 0) species = constructor;
34606
+ }
34607
+ field = void 0;
34608
+ if (!isSandboxClosure(species) || species.construct === void 0) throw new TypeError("RegExp species must be a constructor.");
34609
+ field = await read(target, "flags");
34610
+ flags = await sandboxString(field, options.budget, context);
34611
+ field = void 0;
34612
+ matcher = await invokeBuiltinClosure(species, [target, flags], options.budget, context, void 0, true);
34613
+ field = await read(target, "lastIndex");
34614
+ const cursor = normalizeLastIndex(await sandboxNumber(field, options.budget, context));
34615
+ field = void 0;
34616
+ await setSandboxProperty(matcher, "lastIndex", cursor, options.budget, true, context);
34617
+ return restoreSandboxRegExpIterator({
34618
+ matcher,
34619
+ input: string,
34620
+ exhausted: false,
34621
+ global: flags.includes("g"),
34622
+ unicode: flags.includes("u") || flags.includes("v")
34623
+ });
34624
+ } finally {
34625
+ release();
34626
+ }
34627
+ }
34628
+ }),
34629
+ writable: true,
34630
+ configurable: true
34631
+ });
34469
34632
  for (const name of ["exec", "test", "toString"]) {
34470
34633
  Object.defineProperty(prototype, name, {
34471
34634
  value: createSandboxClosure({
@@ -36810,4 +36973,4 @@ export {
36810
36973
  FileSnapshotBackend,
36811
36974
  run
36812
36975
  };
36813
- //# sourceMappingURL=chunk-LX5FI3OX.js.map
36976
+ //# sourceMappingURL=chunk-DXCKCEDV.js.map