@poe-platform/safe-js 0.1.179 → 0.1.180

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-GF7KHTVI.js";
30
+ } from "./chunk-V2ZFZP6Y.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-AQQ5HET5.js.map
8252
+ //# sourceMappingURL=chunk-TCWUH7BD.js.map
@@ -9590,25 +9590,36 @@ async function callRegexMethod(target, methodName, args, budget, context) {
9590
9590
  try {
9591
9591
  const input = await sandboxString(args[0], budget, context);
9592
9592
  if (methodName === "test") {
9593
- const exec = context?.getProperty === void 0 ? getSandboxDataProperty(target, "exec", budget) : await context.getProperty(target, "exec");
9594
- if (isSandboxClosure(exec)) {
9595
- const result = await invokeBuiltinClosure(exec, [input], budget, context, target);
9596
- if (result !== null && typeof result !== "object") {
9597
- throw new TypeError("RegExp#test exec must return an object or null.");
9598
- }
9599
- return result !== null;
9600
- }
9593
+ budget.setRetainedValues(retained, void 0);
9594
+ return await regexExec(target, input, budget, context) !== null;
9601
9595
  }
9602
- if (!isSandboxRegex(target)) throw new TypeError("RegExp execution requires a regex receiver.");
9603
9596
  if (typeof args[0] !== "string") convertedInput = input;
9597
+ if (!isSandboxRegex(target)) throw new TypeError("RegExp execution requires a regex receiver.");
9604
9598
  cursor = target.lastIndex;
9605
9599
  const lastIndex = await sandboxNumber(cursor, budget, context);
9606
9600
  const match = executeRegex(target, input, lastIndex);
9607
- return methodName === "test" ? match !== null : toMatchArray(match, input);
9601
+ return toMatchArray(match, input);
9608
9602
  } finally {
9609
9603
  budget.setRetainedValues(retained, void 0);
9610
9604
  }
9611
9605
  }
9606
+ async function regexExec(target, input, budget, context) {
9607
+ let exec;
9608
+ const release = retainValues(budget, () => [target, input, exec]);
9609
+ try {
9610
+ const descriptor = context?.getProperty === void 0 ? getSandboxPropertyDescriptor(target, "exec", budget) : void 0;
9611
+ exec = await (context?.getProperty !== void 0 ? context.getProperty(target, "exec") : descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, target, context));
9612
+ if (isSandboxClosure(exec)) {
9613
+ const result = await invokeBuiltinClosure(exec, [input], budget, context, target);
9614
+ if (result !== null && typeof result !== "object")
9615
+ throw new TypeError("RegExp exec must return an object or null.");
9616
+ return result;
9617
+ }
9618
+ return await callRegexMethod(target, "exec", [input], budget, context);
9619
+ } finally {
9620
+ release();
9621
+ }
9622
+ }
9612
9623
  async function regexToString(target, budget, context) {
9613
9624
  if (target === null || typeof target !== "object")
9614
9625
  throw new TypeError("RegExp#toString requires an object receiver.");
@@ -10647,6 +10658,8 @@ function callStringMethodBody(value, methodName, args, budget, parent, context)
10647
10658
  return budget.allocateString(result + value.slice(spanStart));
10648
10659
  }
10649
10660
  const regex = args[0];
10661
+ if (methodName === "match" && isSandboxRegex(regex) && getSandboxPropertyDescriptor(regex, "exec", budget) !== void 0)
10662
+ return callCustomRegexMatch(value, regex, budget, context);
10650
10663
  if (isSandboxRegex(regex) && (methodName === "matchAll" || methodName === "match" && !regex.flags.includes("g") && regex.lastIndex !== null && typeof regex.lastIndex === "object")) {
10651
10664
  return callStringRegexCursor(value, methodName, regex, budget, parent, context);
10652
10665
  }
@@ -10994,6 +11007,46 @@ async function callStringPattern(value, methodName, pattern, budget, parent, con
10994
11007
  operation.release();
10995
11008
  }
10996
11009
  }
11010
+ async function callCustomRegexMatch(value, regex, budget, context) {
11011
+ const matches = [];
11012
+ let result;
11013
+ let matched;
11014
+ let cursor;
11015
+ let flagsValue;
11016
+ let flags;
11017
+ const release = retainValues(budget, () => [value, regex, matches, result, matched, cursor, flagsValue, flags]);
11018
+ try {
11019
+ const descriptor = context?.getProperty === void 0 ? getSandboxPropertyDescriptor(regex, "flags", budget) : void 0;
11020
+ flagsValue = await (context?.getProperty !== void 0 ? context.getProperty(regex, "flags") : descriptor === void 0 ? getRegexMember(regex, "flags", budget, context) : readPropertyDescriptor(descriptor, regex, context));
11021
+ flags = await sandboxString(flagsValue, budget, context);
11022
+ flagsValue = void 0;
11023
+ if (!flags.includes("g")) return await regexExec(regex, value, budget, context);
11024
+ const fullUnicode = flags.includes("u") || flags.includes("v");
11025
+ flags = void 0;
11026
+ regex.lastIndex = 0;
11027
+ while (true) {
11028
+ budget.visitNode();
11029
+ result = await regexExec(regex, value, budget, context);
11030
+ if (result === null) return matches.length === 0 ? null : matches;
11031
+ const descriptor2 = context?.getProperty === void 0 ? getSandboxPropertyDescriptor(result, "0", budget) : void 0;
11032
+ matched = await (context?.getProperty !== void 0 ? context.getProperty(result, "0") : descriptor2 === void 0 ? void 0 : readPropertyDescriptor(descriptor2, result, context));
11033
+ const text = await sandboxString(matched, budget, context);
11034
+ matched = void 0;
11035
+ budget.allocateArrayLength(matches.length + 1);
11036
+ matches.push(text);
11037
+ if (text.length === 0) {
11038
+ cursor = regex.lastIndex;
11039
+ const index = normalizeLastIndex(await sandboxNumber(cursor, budget, context));
11040
+ const point = fullUnicode ? value.codePointAt(index) : void 0;
11041
+ regex.lastIndex = index + (point !== void 0 && point > 65535 ? 2 : 1);
11042
+ cursor = void 0;
11043
+ }
11044
+ result = void 0;
11045
+ }
11046
+ } finally {
11047
+ release();
11048
+ }
11049
+ }
10997
11050
  function callStringRegexCursor(value, methodName, regex, budget, parent, context) {
10998
11051
  const operation = budget.acquireCompileOwner(false, parent?.owner);
10999
11052
  const compilation = new CompileScope(operation.owner);
@@ -36496,4 +36549,4 @@ export {
36496
36549
  FileSnapshotBackend,
36497
36550
  run
36498
36551
  };
36499
- //# sourceMappingURL=chunk-GF7KHTVI.js.map
36552
+ //# sourceMappingURL=chunk-V2ZFZP6Y.js.map