@poe-platform/safe-js 0.1.172 → 0.1.174

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-WVYGEWML.js";
30
+ } from "./chunk-KWMGOGFY.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-MKCG75T2.js.map
8252
+ //# sourceMappingURL=chunk-ECW7ILI7.js.map
@@ -10424,7 +10424,6 @@ function formatNumber(value, methodName, argument, budget) {
10424
10424
 
10425
10425
  // packages/safe-js/src/interp/methods/string.ts
10426
10426
  import { types as types6 } from "node:util";
10427
- var SPLIT_STRING_MESSAGE = "String#split only supports string separator values.";
10428
10427
  var stringMethodNames = /* @__PURE__ */ new Set([
10429
10428
  "at",
10430
10429
  "charAt",
@@ -10589,6 +10588,7 @@ function callStringMethodBody(value, methodName, args, budget, callClosure = asy
10589
10588
  if (methodName === "replace" || methodName === "replaceAll") {
10590
10589
  return callReplaceLikeMethod(value, methodName, args, budget, callClosure, context);
10591
10590
  }
10591
+ if (methodName === "split") return callSplit(value, args, budget, parent, context);
10592
10592
  const regex = args[0];
10593
10593
  if (isSandboxRegex(regex) && regex.lastIndex !== null && typeof regex.lastIndex === "object" && (methodName === "match" && !regex.flags.includes("g") || methodName === "matchAll")) {
10594
10594
  return callStringRegexCursor(value, methodName, regex, budget, parent, context);
@@ -10599,9 +10599,6 @@ function callStringMethodBody(value, methodName, args, budget, callClosure = asy
10599
10599
  const operation = budget.acquireCompileOwner(false, parent?.owner);
10600
10600
  const compilation = new CompileScope(operation.owner);
10601
10601
  try {
10602
- if (methodName === "split") {
10603
- return callSplit(value, args, budget, compilation);
10604
- }
10605
10602
  if (methodName === "match" || methodName === "matchAll" || methodName === "search") {
10606
10603
  return callMatchLikeMethod(value, methodName, args, compilation);
10607
10604
  }
@@ -10855,42 +10852,74 @@ function findReplacementOffsets(value, searchValue, replaceAll) {
10855
10852
  }
10856
10853
  return offsets;
10857
10854
  }
10858
- function callSplit(value, args, budget, compilation) {
10859
- if (args.some(isSandboxClosure))
10860
- throw new TypeError("String#split does not support function arguments.");
10861
- if (isSandboxRegex(args[0])) {
10862
- const regex = args[0];
10863
- const splitter = createSandboxRegex(
10864
- regex.source,
10865
- regex.flags.includes("g") ? regex.flags : `${regex.flags}g`,
10866
- 0,
10867
- compilation
10868
- );
10869
- const limit2 = asNumberOrUndefined(args[1]) ?? 2 ** 32 - 1;
10870
- const result2 = [];
10871
- let copiedThrough = 0;
10872
- let endedWithZeroWidthMatch = false;
10873
- for (const match of collectRegexMatches(splitter, value, true)) {
10874
- endedWithZeroWidthMatch = match.text.length === 0 && match.index === value.length;
10875
- if (match.text.length === 0 && (match.index === copiedThrough || match.index === value.length))
10876
- continue;
10877
- if (result2.length >= limit2) break;
10878
- result2.push(budget.allocateString(value.slice(copiedThrough, match.index)));
10879
- for (const capture of match.captures) {
10880
- if (result2.length >= limit2) break;
10881
- result2.push(capture === void 0 ? void 0 : budget.allocateString(capture));
10855
+ function callSplit(value, args, budget, parent, context) {
10856
+ const pattern = args[0];
10857
+ const useRegex = isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, Symbol.split, budget) === void 0;
10858
+ let separator;
10859
+ const release = retainValues(budget, () => [value, ...args, separator]);
10860
+ const withLimit = (number) => {
10861
+ const limit = number >>> 0;
10862
+ const converted = useRegex || pattern === void 0 ? pattern : sandboxString(pattern, budget, context);
10863
+ const split = (converted2) => {
10864
+ separator = converted2;
10865
+ return splitNormalized(value, converted2, limit, budget, parent);
10866
+ };
10867
+ return converted instanceof Promise ? converted.then(split) : split(converted);
10868
+ };
10869
+ try {
10870
+ const limit = args[1] === void 0 ? 2 ** 32 - 1 : sandboxNumber(args[1], budget, context);
10871
+ const result = limit instanceof Promise ? limit.then(withLimit) : withLimit(limit);
10872
+ if (result instanceof Promise) return result.finally(release);
10873
+ release();
10874
+ return result;
10875
+ } catch (error) {
10876
+ release();
10877
+ throw error;
10878
+ }
10879
+ }
10880
+ function splitNormalized(value, separator, limit, budget, parent) {
10881
+ if (limit === 0) return [];
10882
+ if (isSandboxRegex(separator)) {
10883
+ const regex = separator;
10884
+ const operation = budget.acquireCompileOwner(false, parent?.owner);
10885
+ const compilation = new CompileScope(operation.owner);
10886
+ try {
10887
+ const splitter = createSandboxRegex(
10888
+ regex.source,
10889
+ regex.flags.includes("g") ? regex.flags : `${regex.flags}g`,
10890
+ 0,
10891
+ compilation
10892
+ );
10893
+ const result2 = [];
10894
+ let copiedThrough = 0;
10895
+ let endedWithZeroWidthMatch = false;
10896
+ while (result2.length < limit) {
10897
+ const match = executeRegex(splitter, value, Number(splitter.lastIndex));
10898
+ if (match === null) break;
10899
+ if (match.text.length === 0) splitter.lastIndex = match.index + 1;
10900
+ endedWithZeroWidthMatch = match.text.length === 0 && match.index === value.length;
10901
+ if (match.text.length === 0 && (match.index === copiedThrough || match.index === value.length))
10902
+ continue;
10903
+ budget.allocateArrayLength(result2.length + 1);
10904
+ result2.push(budget.allocateString(value.slice(copiedThrough, match.index)));
10905
+ for (const capture of match.captures) {
10906
+ if (result2.length >= limit) break;
10907
+ budget.allocateArrayLength(result2.length + 1);
10908
+ result2.push(capture === void 0 ? void 0 : budget.allocateString(capture));
10909
+ }
10910
+ copiedThrough = match.index + match.text.length;
10882
10911
  }
10883
- copiedThrough = match.index + match.text.length;
10912
+ if (result2.length < limit && (value.length > 0 || !endedWithZeroWidthMatch)) {
10913
+ budget.allocateArrayLength(result2.length + 1);
10914
+ result2.push(budget.allocateString(value.slice(copiedThrough)));
10915
+ }
10916
+ return result2;
10917
+ } finally {
10918
+ compilation.dispose();
10919
+ operation.release();
10884
10920
  }
10885
- if (result2.length < limit2 && (value.length > 0 || !endedWithZeroWidthMatch))
10886
- result2.push(budget.allocateString(value.slice(copiedThrough)));
10887
- budget.allocateArrayLength(result2.length);
10888
- return result2;
10889
10921
  }
10890
- if (args[0] !== void 0 && typeof args[0] !== "string")
10891
- throw new TypeError(SPLIT_STRING_MESSAGE);
10892
- const limit = asNumberOrUndefined(args[1]);
10893
- const result = splitString(value, args[0], limit).map((part) => budget.allocateString(part));
10922
+ const result = splitString(value, separator, limit).map((part) => budget.allocateString(part));
10894
10923
  budget.allocateArrayLength(result.length);
10895
10924
  return result;
10896
10925
  }
@@ -36377,4 +36406,4 @@ export {
36377
36406
  FileSnapshotBackend,
36378
36407
  run
36379
36408
  };
36380
- //# sourceMappingURL=chunk-WVYGEWML.js.map
36409
+ //# sourceMappingURL=chunk-KWMGOGFY.js.map