@poe-platform/safe-js 0.1.117 → 0.1.118

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.
@@ -24950,7 +24950,8 @@ function getStringMember(value, property, budget) {
24950
24950
  args,
24951
24951
  budget,
24952
24952
  (closure, closureArgs) => invokeBuiltinClosure(closure, closureArgs, budget, context, void 0),
24953
- context?.compilation
24953
+ context?.compilation,
24954
+ context
24954
24955
  );
24955
24956
  } finally {
24956
24957
  budget.setRetainedValues(retainedReceiver, void 0);
@@ -24970,7 +24971,7 @@ function isStringMethodName(property) {
24970
24971
  }
24971
24972
  function validateStringMethodArguments(_methodName, _args) {
24972
24973
  }
24973
- function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent) {
24974
+ function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
24974
24975
  if (methodName === "isWellFormed") {
24975
24976
  for (let index = 0; index < value.length; index++) {
24976
24977
  const codeUnit = value.charCodeAt(index);
@@ -25009,6 +25010,9 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
25009
25010
  if (methodName === "replace" || methodName === "replaceAll") {
25010
25011
  return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
25011
25012
  }
25013
+ if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
25014
+ return callStringPattern(value, methodName, args[0], budget, parent, context);
25015
+ }
25012
25016
  const operation = budget.acquireCompileOwner(false, parent?.owner);
25013
25017
  const compilation = new CompileScope(operation.owner);
25014
25018
  try {
@@ -25279,6 +25283,21 @@ function callSplit(value, args, budget, compilation) {
25279
25283
  budget.allocateArrayLength(result.length);
25280
25284
  return result;
25281
25285
  }
25286
+ async function callStringPattern(value, methodName, pattern, budget, parent, context) {
25287
+ const operation = budget.acquireCompileOwner(false, parent?.owner);
25288
+ const compilation = new CompileScope(operation.owner);
25289
+ const retainedPattern = {};
25290
+ budget.setRetainedValues(retainedPattern, () => [pattern]);
25291
+ try {
25292
+ const source = pattern === void 0 ? "" : await sandboxString(pattern, budget, context);
25293
+ const regex = createSandboxRegex(source, methodName === "matchAll" ? "g" : "", 0, compilation);
25294
+ return callMatchLikeMethod(value, methodName, [regex], compilation);
25295
+ } finally {
25296
+ budget.setRetainedValues(retainedPattern, void 0);
25297
+ compilation.dispose();
25298
+ operation.release();
25299
+ }
25300
+ }
25282
25301
  function callMatchLikeMethod(value, methodName, args, compilation) {
25283
25302
  const regex = args[0];
25284
25303
  if (!isSandboxRegex(regex))
@@ -25296,15 +25315,16 @@ function callMatchLikeMethod(value, methodName, args, compilation) {
25296
25315
  return toMatchArray(executeRegex(regex, value), value);
25297
25316
  if (methodName === "match") regex.lastIndex = 0;
25298
25317
  const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, regex.lastIndex, compilation) : regex;
25299
- const matches = collectRegexMatches(matcher, value, true);
25318
+ const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget);
25300
25319
  if (methodName === "match" && matches.length === 0) return null;
25301
25320
  return methodName === "match" ? matches.map((match) => match.text) : matches.map((match) => toMatchArray(match, value));
25302
25321
  }
25303
- function collectRegexMatches(regex, value, all) {
25322
+ function collectRegexMatches(regex, value, all, budget) {
25304
25323
  const matches = [];
25305
25324
  do {
25306
25325
  const match = executeRegex(regex, value);
25307
25326
  if (match === null) break;
25327
+ budget?.allocateArrayLength(matches.length + 1);
25308
25328
  matches.push(match);
25309
25329
  if (all && match.text.length === 0) regex.lastIndex += 1;
25310
25330
  } while (all);
@@ -28161,7 +28181,8 @@ async function evaluateStringMethodCall(node, target, methodName, context) {
28161
28181
  args.value,
28162
28182
  context.budget,
28163
28183
  (closure, closureArgs) => invokeSandboxClosure(closure, closureArgs, context, context.callStack),
28164
- context.compilation
28184
+ context.compilation,
28185
+ createCoercionContext(context)
28165
28186
  )
28166
28187
  };
28167
28188
  } catch (error) {
@@ -33296,4 +33317,4 @@ export {
33296
33317
  FileSnapshotBackend,
33297
33318
  run
33298
33319
  };
33299
- //# sourceMappingURL=chunk-L7PHF62H.js.map
33320
+ //# sourceMappingURL=chunk-7FCWZM6I.js.map