@poe-platform/safe-js 0.1.177 → 0.1.179

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-B5ZSXQUJ.js";
30
+ } from "./chunk-GF7KHTVI.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-OCQHXDRF.js.map
8252
+ //# sourceMappingURL=chunk-AQQ5HET5.js.map
@@ -9511,11 +9511,33 @@ var regexFlagProperties = {
9511
9511
  function isRegexMethodName(property) {
9512
9512
  return typeof property === "string" && regexMethodNames.has(property);
9513
9513
  }
9514
- function getRegexMember(target, property, budget) {
9514
+ function getRegexMember(target, property, budget, context) {
9515
9515
  if (property === "source") return escapeRegexSource(target.source, budget);
9516
9516
  if (property === "flags") {
9517
- const flags = [..."gims"].filter((flag) => target.flags.includes(flag)).join("");
9518
- return budget === void 0 ? flags : budget.allocateString(flags);
9517
+ let flags = "";
9518
+ const entries = Object.entries(regexFlagProperties);
9519
+ const release = retainValues(budget, () => [target, flags]);
9520
+ const read = (index) => {
9521
+ if (index === entries.length) return budget.allocateString(flags);
9522
+ budget.visitNode();
9523
+ const [key, flag] = entries[index];
9524
+ const descriptor = context?.getProperty === void 0 ? getSandboxPropertyDescriptor(target, key, budget) : void 0;
9525
+ const value = context?.getProperty !== void 0 ? context.getProperty(target, key) : descriptor !== void 0 ? readPropertyDescriptor(descriptor, target, context) : target.flags.includes(flag);
9526
+ const append = (value2) => {
9527
+ if (value2) flags += flag;
9528
+ return read(index + 1);
9529
+ };
9530
+ return value instanceof Promise ? value.then(append) : append(value);
9531
+ };
9532
+ try {
9533
+ const result = read(0);
9534
+ if (result instanceof Promise) return result.finally(release);
9535
+ release();
9536
+ return result;
9537
+ } catch (error) {
9538
+ release();
9539
+ throw error;
9540
+ }
9519
9541
  }
9520
9542
  if (property === "lastIndex") return target.lastIndex;
9521
9543
  if (Object.hasOwn(regexFlagProperties, property)) return target.flags.includes(regexFlagProperties[property]);
@@ -9525,7 +9547,7 @@ function getRegexMember(target, property, budget) {
9525
9547
  return createSandboxClosure({
9526
9548
  sandbox: true,
9527
9549
  name: property === "toString" ? "toString" : `RegExp#${property}`,
9528
- call: (args, context) => callRegexMethod(context?.thisValue, property, args, budget, context)
9550
+ call: (args, context2) => callRegexMethod(context2?.thisValue, property, args, budget, context2)
9529
9551
  });
9530
9552
  }
9531
9553
  function escapeRegexSource(source, budget) {
@@ -9594,7 +9616,7 @@ async function regexToString(target, budget, context) {
9594
9616
  if (context?.getProperty !== void 0) return context.getProperty(target, key);
9595
9617
  const descriptor = getSandboxPropertyDescriptor(target, key, budget);
9596
9618
  if (descriptor !== void 0) return readPropertyDescriptor(descriptor, target, context);
9597
- return isSandboxRegex(target) ? getRegexMember(target, key, budget) : void 0;
9619
+ return isSandboxRegex(target) ? getRegexMember(target, key, budget, context) : void 0;
9598
9620
  };
9599
9621
  let sourceValue;
9600
9622
  let flagsValue;
@@ -10555,7 +10577,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
10555
10577
  if (symbol !== void 0 && types6.isRegExp(pattern))
10556
10578
  throw new TypeError(`String#${methodName} does not accept unbranded host RegExp values.`);
10557
10579
  if (symbol === void 0 || pattern === null || pattern === void 0) return fallback();
10558
- const readProperty = (key) => context?.getProperty !== void 0 ? context.getProperty(pattern, key) : key === "flags" && isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, key, budget) === void 0 ? pattern.flags : getSandboxDataProperty(pattern, key, budget);
10580
+ const readProperty = (key) => context?.getProperty !== void 0 ? context.getProperty(pattern, key) : key === "flags" && isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, key, budget) === void 0 ? getRegexMember(pattern, key, budget, context) : getSandboxDataProperty(pattern, key, budget);
10559
10581
  const dispatch = () => {
10560
10582
  const overriddenRegex = isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, symbol, budget) !== void 0;
10561
10583
  const applyHook = (hook2) => {
@@ -10625,7 +10647,7 @@ function callStringMethodBody(value, methodName, args, budget, parent, context)
10625
10647
  return budget.allocateString(result + value.slice(spanStart));
10626
10648
  }
10627
10649
  const regex = args[0];
10628
- if (isSandboxRegex(regex) && regex.lastIndex !== null && typeof regex.lastIndex === "object" && (methodName === "match" && !regex.flags.includes("g") || methodName === "matchAll")) {
10650
+ if (isSandboxRegex(regex) && (methodName === "matchAll" || methodName === "match" && !regex.flags.includes("g") && regex.lastIndex !== null && typeof regex.lastIndex === "object")) {
10629
10651
  return callStringRegexCursor(value, methodName, regex, budget, parent, context);
10630
10652
  }
10631
10653
  if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
@@ -10972,19 +10994,57 @@ async function callStringPattern(value, methodName, pattern, budget, parent, con
10972
10994
  operation.release();
10973
10995
  }
10974
10996
  }
10975
- async function callStringRegexCursor(value, methodName, regex, budget, parent, context) {
10997
+ function callStringRegexCursor(value, methodName, regex, budget, parent, context) {
10976
10998
  const operation = budget.acquireCompileOwner(false, parent?.owner);
10977
10999
  const compilation = new CompileScope(operation.owner);
10978
- const cursor = regex.lastIndex;
11000
+ let cursor;
11001
+ let flagsValue;
11002
+ let flags;
11003
+ let matcher;
10979
11004
  const retained = {};
10980
- budget.setRetainedValues(retained, () => [value, regex, cursor]);
10981
- try {
10982
- const lastIndex = await sandboxNumber(cursor, budget, context);
10983
- return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex);
10984
- } finally {
11005
+ budget.setRetainedValues(retained, () => [value, regex, cursor, flagsValue, flags, matcher]);
11006
+ const release = () => {
10985
11007
  budget.setRetainedValues(retained, void 0);
10986
11008
  compilation.dispose();
10987
11009
  operation.release();
11010
+ };
11011
+ const readCursor = () => {
11012
+ cursor = regex.lastIndex;
11013
+ const finish = (lastIndex2) => {
11014
+ if (matcher !== void 0) {
11015
+ matcher.lastIndex = normalizeLastIndex(lastIndex2);
11016
+ return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false });
11017
+ }
11018
+ return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex2);
11019
+ };
11020
+ const lastIndex = sandboxNumber(cursor, budget, context);
11021
+ return lastIndex instanceof Promise ? lastIndex.then(finish) : finish(lastIndex);
11022
+ };
11023
+ const clone = (text) => {
11024
+ flags = text;
11025
+ flagsValue = void 0;
11026
+ matcher = createSandboxRegex(regex.source, flags, 0, compilation);
11027
+ flags = void 0;
11028
+ return readCursor();
11029
+ };
11030
+ const convertFlags = (value2) => {
11031
+ flagsValue = value2;
11032
+ const text = sandboxString(value2, budget, context);
11033
+ return text instanceof Promise ? text.then(clone) : clone(text);
11034
+ };
11035
+ try {
11036
+ let result;
11037
+ if (methodName === "matchAll") {
11038
+ const descriptor = context?.getProperty === void 0 ? getSandboxPropertyDescriptor(regex, "flags", budget) : void 0;
11039
+ const value2 = context?.getProperty !== void 0 ? context.getProperty(regex, "flags") : descriptor !== void 0 ? readPropertyDescriptor(descriptor, regex, context) : getRegexMember(regex, "flags", budget, context);
11040
+ result = value2 instanceof Promise ? value2.then(convertFlags) : convertFlags(value2);
11041
+ } else result = readCursor();
11042
+ if (result instanceof Promise) return result.finally(release);
11043
+ release();
11044
+ return result;
11045
+ } catch (error) {
11046
+ release();
11047
+ throw error;
10988
11048
  }
10989
11049
  }
10990
11050
  function callMatchLikeMethod(value, methodName, args, compilation, lastIndex) {
@@ -15905,7 +15965,7 @@ function getPropertyValue(target, property, context, receiver = target) {
15905
15965
  if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
15906
15966
  if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
15907
15967
  if (isSandboxPromise(target)) return getPromiseMember(property, context.budget);
15908
- if (isSandboxRegex(target)) return getRegexMember(target, property, context.budget);
15968
+ if (isSandboxRegex(target)) return getRegexMember(target, property, context.budget, createCoercionContext(context));
15909
15969
  if (!isIndexableSandboxValue(target)) {
15910
15970
  throw new TypeError("Attempted to read a property from a non-object value.");
15911
15971
  }
@@ -36436,4 +36496,4 @@ export {
36436
36496
  FileSnapshotBackend,
36437
36497
  run
36438
36498
  };
36439
- //# sourceMappingURL=chunk-B5ZSXQUJ.js.map
36499
+ //# sourceMappingURL=chunk-GF7KHTVI.js.map