@poe-platform/safe-js 0.1.181 → 0.1.183

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.
@@ -10660,8 +10660,8 @@ function callStringMethodBody(value, methodName, args, budget, parent, context)
10660
10660
  const regex = args[0];
10661
10661
  if (methodName === "search" && isSandboxRegex(regex) && getSandboxPropertyDescriptor(regex, "exec", budget) !== void 0)
10662
10662
  return callCustomRegexSearch(value, regex, budget, context);
10663
- if (methodName === "match" && isSandboxRegex(regex) && getSandboxPropertyDescriptor(regex, "exec", budget) !== void 0)
10664
- return callCustomRegexMatch(value, regex, budget, context);
10663
+ if (methodName === "match" && isSandboxRegex(regex) && ["exec", "flags", ...Object.keys(regexFlagProperties)].some((key) => getSandboxPropertyDescriptor(regex, key, budget) !== void 0))
10664
+ return callObservableRegexMatch(value, regex, budget, context);
10665
10665
  if (isSandboxRegex(regex) && (methodName === "matchAll" || methodName === "match" && !regex.flags.includes("g") && regex.lastIndex !== null && typeof regex.lastIndex === "object")) {
10666
10666
  return callStringRegexCursor(value, methodName, regex, budget, parent, context);
10667
10667
  }
@@ -10827,23 +10827,26 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure, use
10827
10827
  replacement,
10828
10828
  methodName === "replaceAll",
10829
10829
  budget,
10830
- callClosure
10830
+ callClosure,
10831
+ context
10831
10832
  );
10832
10833
  }
10833
10834
  async function replaceRegex(value, regex, replacement, budget, callClosure, context) {
10834
10835
  if (regex.flags.includes("g")) regex.lastIndex = 0;
10835
10836
  const cursor = regex.lastIndex;
10837
+ let result = "";
10836
10838
  const retained = {};
10837
- budget.setRetainedValues(retained, () => [value, regex, cursor, replacement]);
10839
+ budget.setRetainedValues(retained, () => [value, regex, cursor, replacement, result]);
10838
10840
  try {
10839
10841
  const lastIndex = await sandboxNumber(cursor, budget, context);
10840
10842
  const matches = collectRegexMatches(regex, value, regex.flags.includes("g"), void 0, lastIndex);
10841
- let result = "";
10842
10843
  let copiedThrough = 0;
10843
10844
  for (const match of matches) {
10844
10845
  result += value.slice(copiedThrough, match.index);
10845
- result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : String(
10846
- await callClosure(replacement, [match.text, ...match.captures, match.index, value])
10846
+ result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : await sandboxString(
10847
+ await callClosure(replacement, [match.text, ...match.captures, match.index, value]),
10848
+ budget,
10849
+ context
10847
10850
  );
10848
10851
  copiedThrough = match.index + match.text.length;
10849
10852
  }
@@ -10893,17 +10896,22 @@ function expandReplacement(replacement, match, captures, input, matchIndex) {
10893
10896
  }
10894
10897
  return result;
10895
10898
  }
10896
- async function replaceWithClosure(value, searchValue, replacer, replaceAll, budget, callClosure) {
10899
+ async function replaceWithClosure(value, searchValue, replacer, replaceAll, budget, callClosure, context) {
10897
10900
  const offsets = findReplacementOffsets(value, searchValue, replaceAll);
10898
10901
  let result = "";
10899
10902
  let copiedThrough = 0;
10900
- for (const offset of offsets) {
10901
- result += value.slice(copiedThrough, offset);
10902
- result += String(await callClosure(replacer, [searchValue, offset, value]));
10903
- copiedThrough = offset + searchValue.length;
10903
+ const release = retainValues(budget, () => [value, searchValue, replacer, result]);
10904
+ try {
10905
+ for (const offset of offsets) {
10906
+ result += value.slice(copiedThrough, offset);
10907
+ result += await sandboxString(await callClosure(replacer, [searchValue, offset, value]), budget, context);
10908
+ copiedThrough = offset + searchValue.length;
10909
+ }
10910
+ result += value.slice(copiedThrough);
10911
+ return budget.allocateString(result);
10912
+ } finally {
10913
+ release();
10904
10914
  }
10905
- result += value.slice(copiedThrough);
10906
- return budget.allocateString(result);
10907
10915
  }
10908
10916
  function findReplacementOffsets(value, searchValue, replaceAll) {
10909
10917
  const firstOffset = value.indexOf(searchValue);
@@ -11025,7 +11033,7 @@ async function callCustomRegexSearch(value, regex, budget, context) {
11025
11033
  release();
11026
11034
  }
11027
11035
  }
11028
- async function callCustomRegexMatch(value, regex, budget, context) {
11036
+ async function callObservableRegexMatch(value, regex, budget, context) {
11029
11037
  const matches = [];
11030
11038
  let result;
11031
11039
  let matched;
@@ -36567,4 +36575,4 @@ export {
36567
36575
  FileSnapshotBackend,
36568
36576
  run
36569
36577
  };
36570
- //# sourceMappingURL=chunk-IJRSYEH5.js.map
36578
+ //# sourceMappingURL=chunk-7XAXYVOY.js.map