@poe-platform/safe-js 0.1.116 → 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.
@@ -24935,14 +24935,28 @@ function getStringMember(value, property, budget) {
24935
24935
  name: `String#${property}`,
24936
24936
  ...property === "localeCompare" ? { length: 1 } : {},
24937
24937
  ...property === "isWellFormed" || property === "toWellFormed" ? { length: 0 } : {},
24938
- call: (args, context) => callStringMethod(
24939
- value,
24940
- property,
24941
- args,
24942
- budget,
24943
- context === void 0 ? void 0 : async (closure, closureArgs) => await closure.call(closureArgs, { ...context, thisValue: void 0 }),
24944
- context?.compilation
24945
- )
24938
+ call: async (args, context) => {
24939
+ const receiver = context?.thisValue;
24940
+ if (receiver === null || receiver === void 0) {
24941
+ throw new TypeError(`String#${property} requires a non-null receiver.`);
24942
+ }
24943
+ const retainedReceiver = {};
24944
+ budget.setRetainedValues(retainedReceiver, () => [receiver]);
24945
+ try {
24946
+ const string = await sandboxString(receiver, budget, context);
24947
+ return await callStringMethod(
24948
+ string,
24949
+ property,
24950
+ args,
24951
+ budget,
24952
+ (closure, closureArgs) => invokeBuiltinClosure(closure, closureArgs, budget, context, void 0),
24953
+ context?.compilation,
24954
+ context
24955
+ );
24956
+ } finally {
24957
+ budget.setRetainedValues(retainedReceiver, void 0);
24958
+ }
24959
+ }
24946
24960
  });
24947
24961
  }
24948
24962
  function getStringIndex(property) {
@@ -24957,7 +24971,7 @@ function isStringMethodName(property) {
24957
24971
  }
24958
24972
  function validateStringMethodArguments(_methodName, _args) {
24959
24973
  }
24960
- 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) {
24961
24975
  if (methodName === "isWellFormed") {
24962
24976
  for (let index = 0; index < value.length; index++) {
24963
24977
  const codeUnit = value.charCodeAt(index);
@@ -24996,6 +25010,9 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
24996
25010
  if (methodName === "replace" || methodName === "replaceAll") {
24997
25011
  return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
24998
25012
  }
25013
+ if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
25014
+ return callStringPattern(value, methodName, args[0], budget, parent, context);
25015
+ }
24999
25016
  const operation = budget.acquireCompileOwner(false, parent?.owner);
25000
25017
  const compilation = new CompileScope(operation.owner);
25001
25018
  try {
@@ -25266,6 +25283,21 @@ function callSplit(value, args, budget, compilation) {
25266
25283
  budget.allocateArrayLength(result.length);
25267
25284
  return result;
25268
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
+ }
25269
25301
  function callMatchLikeMethod(value, methodName, args, compilation) {
25270
25302
  const regex = args[0];
25271
25303
  if (!isSandboxRegex(regex))
@@ -25283,15 +25315,16 @@ function callMatchLikeMethod(value, methodName, args, compilation) {
25283
25315
  return toMatchArray(executeRegex(regex, value), value);
25284
25316
  if (methodName === "match") regex.lastIndex = 0;
25285
25317
  const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, regex.lastIndex, compilation) : regex;
25286
- const matches = collectRegexMatches(matcher, value, true);
25318
+ const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget);
25287
25319
  if (methodName === "match" && matches.length === 0) return null;
25288
25320
  return methodName === "match" ? matches.map((match) => match.text) : matches.map((match) => toMatchArray(match, value));
25289
25321
  }
25290
- function collectRegexMatches(regex, value, all) {
25322
+ function collectRegexMatches(regex, value, all, budget) {
25291
25323
  const matches = [];
25292
25324
  do {
25293
25325
  const match = executeRegex(regex, value);
25294
25326
  if (match === null) break;
25327
+ budget?.allocateArrayLength(matches.length + 1);
25295
25328
  matches.push(match);
25296
25329
  if (all && match.text.length === 0) regex.lastIndex += 1;
25297
25330
  } while (all);
@@ -28148,7 +28181,8 @@ async function evaluateStringMethodCall(node, target, methodName, context) {
28148
28181
  args.value,
28149
28182
  context.budget,
28150
28183
  (closure, closureArgs) => invokeSandboxClosure(closure, closureArgs, context, context.callStack),
28151
- context.compilation
28184
+ context.compilation,
28185
+ createCoercionContext(context)
28152
28186
  )
28153
28187
  };
28154
28188
  } catch (error) {
@@ -33283,4 +33317,4 @@ export {
33283
33317
  FileSnapshotBackend,
33284
33318
  run
33285
33319
  };
33286
- //# sourceMappingURL=chunk-VDFW3EKS.js.map
33320
+ //# sourceMappingURL=chunk-7FCWZM6I.js.map