@poe-platform/safe-js 0.1.178 → 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-BM7QYQOS.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-S43OS5GO.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.");
@@ -10577,7 +10588,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
10577
10588
  if (symbol !== void 0 && types6.isRegExp(pattern))
10578
10589
  throw new TypeError(`String#${methodName} does not accept unbranded host RegExp values.`);
10579
10590
  if (symbol === void 0 || pattern === null || pattern === void 0) return fallback();
10580
- 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);
10591
+ 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);
10581
10592
  const dispatch = () => {
10582
10593
  const overriddenRegex = isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, symbol, budget) !== void 0;
10583
10594
  const applyHook = (hook2) => {
@@ -10647,7 +10658,9 @@ 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];
10650
- if (isSandboxRegex(regex) && regex.lastIndex !== null && typeof regex.lastIndex === "object" && (methodName === "match" && !regex.flags.includes("g") || methodName === "matchAll")) {
10661
+ if (methodName === "match" && isSandboxRegex(regex) && getSandboxPropertyDescriptor(regex, "exec", budget) !== void 0)
10662
+ return callCustomRegexMatch(value, regex, budget, context);
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
  }
10653
10666
  if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
@@ -10994,19 +11007,97 @@ async function callStringPattern(value, methodName, pattern, budget, parent, con
10994
11007
  operation.release();
10995
11008
  }
10996
11009
  }
10997
- async function callStringRegexCursor(value, methodName, regex, budget, parent, context) {
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
+ }
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);
11000
- const cursor = regex.lastIndex;
11053
+ let cursor;
11054
+ let flagsValue;
11055
+ let flags;
11056
+ let matcher;
11001
11057
  const retained = {};
11002
- budget.setRetainedValues(retained, () => [value, regex, cursor]);
11003
- try {
11004
- const lastIndex = await sandboxNumber(cursor, budget, context);
11005
- return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex);
11006
- } finally {
11058
+ budget.setRetainedValues(retained, () => [value, regex, cursor, flagsValue, flags, matcher]);
11059
+ const release = () => {
11007
11060
  budget.setRetainedValues(retained, void 0);
11008
11061
  compilation.dispose();
11009
11062
  operation.release();
11063
+ };
11064
+ const readCursor = () => {
11065
+ cursor = regex.lastIndex;
11066
+ const finish = (lastIndex2) => {
11067
+ if (matcher !== void 0) {
11068
+ matcher.lastIndex = normalizeLastIndex(lastIndex2);
11069
+ return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false });
11070
+ }
11071
+ return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex2);
11072
+ };
11073
+ const lastIndex = sandboxNumber(cursor, budget, context);
11074
+ return lastIndex instanceof Promise ? lastIndex.then(finish) : finish(lastIndex);
11075
+ };
11076
+ const clone = (text) => {
11077
+ flags = text;
11078
+ flagsValue = void 0;
11079
+ matcher = createSandboxRegex(regex.source, flags, 0, compilation);
11080
+ flags = void 0;
11081
+ return readCursor();
11082
+ };
11083
+ const convertFlags = (value2) => {
11084
+ flagsValue = value2;
11085
+ const text = sandboxString(value2, budget, context);
11086
+ return text instanceof Promise ? text.then(clone) : clone(text);
11087
+ };
11088
+ try {
11089
+ let result;
11090
+ if (methodName === "matchAll") {
11091
+ const descriptor = context?.getProperty === void 0 ? getSandboxPropertyDescriptor(regex, "flags", budget) : void 0;
11092
+ const value2 = context?.getProperty !== void 0 ? context.getProperty(regex, "flags") : descriptor !== void 0 ? readPropertyDescriptor(descriptor, regex, context) : getRegexMember(regex, "flags", budget, context);
11093
+ result = value2 instanceof Promise ? value2.then(convertFlags) : convertFlags(value2);
11094
+ } else result = readCursor();
11095
+ if (result instanceof Promise) return result.finally(release);
11096
+ release();
11097
+ return result;
11098
+ } catch (error) {
11099
+ release();
11100
+ throw error;
11010
11101
  }
11011
11102
  }
11012
11103
  function callMatchLikeMethod(value, methodName, args, compilation, lastIndex) {
@@ -36458,4 +36549,4 @@ export {
36458
36549
  FileSnapshotBackend,
36459
36550
  run
36460
36551
  };
36461
- //# sourceMappingURL=chunk-BM7QYQOS.js.map
36552
+ //# sourceMappingURL=chunk-V2ZFZP6Y.js.map