@poe-platform/safe-js 0.1.175 → 0.1.177

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.
@@ -9497,7 +9497,7 @@ function isLineTerminator(character) {
9497
9497
  }
9498
9498
 
9499
9499
  // packages/safe-js/src/interp/methods/regex.ts
9500
- var regexMethodNames = /* @__PURE__ */ new Set(["exec", "test"]);
9500
+ var regexMethodNames = /* @__PURE__ */ new Set(["exec", "test", "toString"]);
9501
9501
  var regexFlagProperties = {
9502
9502
  hasIndices: "d",
9503
9503
  global: "g",
@@ -9524,7 +9524,7 @@ function getRegexMember(target, property, budget) {
9524
9524
  }
9525
9525
  return createSandboxClosure({
9526
9526
  sandbox: true,
9527
- name: `RegExp#${property}`,
9527
+ name: property === "toString" ? "toString" : `RegExp#${property}`,
9528
9528
  call: (args, context) => callRegexMethod(context?.thisValue, property, args, budget, context)
9529
9529
  });
9530
9530
  }
@@ -9557,6 +9557,7 @@ function setRegexMember(target, property, value) {
9557
9557
  if (!Reflect.set(properties, property, value)) throw new TypeError(`RegExp#${String(property)} is not writable.`);
9558
9558
  }
9559
9559
  async function callRegexMethod(target, methodName, args, budget, context) {
9560
+ if (methodName === "toString") return regexToString(target, budget, context);
9560
9561
  if (target === null || typeof target !== "object" || methodName === "exec" && !isSandboxRegex(target)) {
9561
9562
  throw new TypeError(`RegExp#${methodName} requires ${methodName === "exec" ? "a regex" : "an object"} receiver.`);
9562
9563
  }
@@ -9586,6 +9587,32 @@ async function callRegexMethod(target, methodName, args, budget, context) {
9586
9587
  budget.setRetainedValues(retained, void 0);
9587
9588
  }
9588
9589
  }
9590
+ async function regexToString(target, budget, context) {
9591
+ if (target === null || typeof target !== "object")
9592
+ throw new TypeError("RegExp#toString requires an object receiver.");
9593
+ const read = (key) => {
9594
+ if (context?.getProperty !== void 0) return context.getProperty(target, key);
9595
+ const descriptor = getSandboxPropertyDescriptor(target, key, budget);
9596
+ if (descriptor !== void 0) return readPropertyDescriptor(descriptor, target, context);
9597
+ return isSandboxRegex(target) ? getRegexMember(target, key, budget) : void 0;
9598
+ };
9599
+ let sourceValue;
9600
+ let flagsValue;
9601
+ let source;
9602
+ let flags;
9603
+ const release = retainValues(budget, () => [target, sourceValue, flagsValue, source, flags]);
9604
+ try {
9605
+ sourceValue = await read("source");
9606
+ source = await sandboxString(sourceValue, budget, context);
9607
+ sourceValue = void 0;
9608
+ flagsValue = await read("flags");
9609
+ flags = await sandboxString(flagsValue, budget, context);
9610
+ flagsValue = void 0;
9611
+ return budget.allocateString(`/${source}/${flags}`);
9612
+ } finally {
9613
+ release();
9614
+ }
9615
+ }
9589
9616
  function executeRegex(target, input, lastIndex) {
9590
9617
  const pattern = getSandboxRegexPattern(target);
9591
9618
  const match = matchRegex(pattern, input, lastIndex);
@@ -10512,7 +10539,15 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
10512
10539
  if (value === null || value === void 0)
10513
10540
  throw new TypeError(`String#${methodName} requires a non-null receiver.`);
10514
10541
  const fallback = (coercePattern = false) => {
10515
- const apply = (string) => coercePattern && (methodName === "match" || methodName === "matchAll" || methodName === "search") ? callStringPattern(string, methodName, args[0], budget, parent, context) : callStringMethodBody(string, methodName, args, budget, callClosure, parent, context);
10542
+ const apply = (string) => {
10543
+ if (coercePattern && (methodName === "match" || methodName === "matchAll" || methodName === "search"))
10544
+ return callStringPattern(string, methodName, args[0], budget, parent, context);
10545
+ const useRegex = isSandboxRegex(args[0]) && !coercePattern;
10546
+ if (methodName === "replace" || methodName === "replaceAll")
10547
+ return callReplaceLikeMethod(string, methodName, args, budget, callClosure, useRegex, context);
10548
+ if (methodName === "split") return callSplit(string, args, budget, useRegex, parent, context);
10549
+ return callStringMethodBody(string, methodName, args, budget, parent, context);
10550
+ };
10516
10551
  return typeof value === "string" ? apply(value) : Promise.resolve(sandboxString(value, budget, context)).then(apply);
10517
10552
  };
10518
10553
  const symbol = methodName === "match" ? Symbol.match : methodName === "search" ? Symbol.search : methodName === "matchAll" ? Symbol.matchAll : methodName === "replace" || methodName === "replaceAll" ? Symbol.replace : methodName === "split" ? Symbol.split : void 0;
@@ -10550,7 +10585,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
10550
10585
  }
10551
10586
  return dispatch();
10552
10587
  }
10553
- function callStringMethodBody(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
10588
+ function callStringMethodBody(value, methodName, args, budget, parent, context) {
10554
10589
  if (methodName === "concat" && args.some((argument) => argument !== null && typeof argument === "object")) {
10555
10590
  return callConcat(value, args, budget, context);
10556
10591
  }
@@ -10589,10 +10624,6 @@ function callStringMethodBody(value, methodName, args, budget, callClosure = asy
10589
10624
  }
10590
10625
  return budget.allocateString(result + value.slice(spanStart));
10591
10626
  }
10592
- if (methodName === "replace" || methodName === "replaceAll") {
10593
- return callReplaceLikeMethod(value, methodName, args, budget, callClosure, context);
10594
- }
10595
- if (methodName === "split") return callSplit(value, args, budget, parent, context);
10596
10627
  const regex = args[0];
10597
10628
  if (isSandboxRegex(regex) && regex.lastIndex !== null && typeof regex.lastIndex === "object" && (methodName === "match" && !regex.flags.includes("g") || methodName === "matchAll")) {
10598
10629
  return callStringRegexCursor(value, methodName, regex, budget, parent, context);
@@ -10720,19 +10751,19 @@ async function callConcat(value, args, budget, context) {
10720
10751
  release();
10721
10752
  }
10722
10753
  }
10723
- function callReplaceLikeMethod(value, methodName, args, budget, callClosure, context) {
10754
+ function callReplaceLikeMethod(value, methodName, args, budget, callClosure, useRegex, context) {
10724
10755
  const search = args[0];
10725
10756
  const replacement = args[1];
10726
- const useRegex = isSandboxRegex(search) && getSandboxPropertyDescriptor(search, Symbol.replace, budget) === void 0;
10727
- if (!useRegex && typeof search !== "string" || typeof replacement !== "string" && !isSandboxClosure(replacement)) {
10757
+ const regexSearch = useRegex && isSandboxRegex(search);
10758
+ if (!regexSearch && typeof search !== "string" || typeof replacement !== "string" && !isSandboxClosure(replacement)) {
10728
10759
  return (async () => {
10729
10760
  let normalizedSearch;
10730
10761
  let normalizedReplacement;
10731
10762
  const release = retainValues(budget, () => [normalizedSearch, normalizedReplacement]);
10732
10763
  try {
10733
- normalizedSearch = useRegex ? search : await sandboxString(search, budget, context);
10764
+ normalizedSearch = regexSearch ? search : await sandboxString(search, budget, context);
10734
10765
  normalizedReplacement = isSandboxClosure(replacement) ? replacement : await sandboxString(replacement, budget, context);
10735
- return await callReplaceLikeMethod(value, methodName, [normalizedSearch, normalizedReplacement], budget, callClosure, context);
10766
+ return await callReplaceLikeMethod(value, methodName, [normalizedSearch, normalizedReplacement], budget, callClosure, useRegex, context);
10736
10767
  } finally {
10737
10768
  release();
10738
10769
  }
@@ -10856,9 +10887,8 @@ function findReplacementOffsets(value, searchValue, replaceAll) {
10856
10887
  }
10857
10888
  return offsets;
10858
10889
  }
10859
- function callSplit(value, args, budget, parent, context) {
10890
+ function callSplit(value, args, budget, useRegex, parent, context) {
10860
10891
  const pattern = args[0];
10861
- const useRegex = isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, Symbol.split, budget) === void 0;
10862
10892
  let separator;
10863
10893
  const release = retainValues(budget, () => [value, ...args, separator]);
10864
10894
  const withLimit = (number) => {
@@ -18975,11 +19005,7 @@ async function defaultToString(value, budget, context, joining) {
18975
19005
  if (isSandboxCollectionIterator(value))
18976
19006
  return collectionIteratorState(value).collectionKind === "map" ? "[object Map Iterator]" : "[object Set Iterator]";
18977
19007
  if (isSandboxGenerator(value)) return "[object Generator]";
18978
- if (isSandboxRegex(value)) {
18979
- return budget.allocateString(
18980
- `/${String(getRegexMember(value, "source", budget))}/${String(getRegexMember(value, "flags", budget))}`
18981
- );
18982
- }
19008
+ if (isSandboxRegex(value)) return regexToString(value, budget, context);
18983
19009
  if (isSandboxDate(value)) return budget.allocateString(dateString(value));
18984
19010
  if (Array.isArray(value) || isFloat32Array(value)) {
18985
19011
  if (Object.hasOwn(value, "join")) {
@@ -36410,4 +36436,4 @@ export {
36410
36436
  FileSnapshotBackend,
36411
36437
  run
36412
36438
  };
36413
- //# sourceMappingURL=chunk-PECCU43A.js.map
36439
+ //# sourceMappingURL=chunk-B5ZSXQUJ.js.map