@poe-platform/safe-js 0.1.117 → 0.1.119

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) {
@@ -30591,32 +30612,43 @@ function defineDataProperty(target, key, value) {
30591
30612
  }
30592
30613
 
30593
30614
  // packages/safe-js/src/interp/globals/regex.ts
30594
- function createRegexGlobals(owner) {
30595
- const construct = (args, context) => {
30596
- const selected = owner ?? context?.compilation?.owner;
30615
+ function createRegexGlobals(options) {
30616
+ const invoke = (construct) => async (args, context) => {
30617
+ const selected = options.compileOwner ?? context?.compilation?.owner;
30597
30618
  if (context?.compilation?.owner !== void 0 && selected !== context.compilation.owner) {
30598
30619
  throw new SandboxError("reentry");
30599
30620
  }
30600
- const operation = selected?.budget.acquireCompileOwner(false, selected);
30601
- const compilation = context?.compilation ?? new CompileScope(selected);
30621
+ const operation = options.budget.acquireCompileOwner(false, selected);
30622
+ const compilation = context?.compilation?.owner === operation.owner ? context.compilation : new CompileScope(operation.owner);
30623
+ let source = "";
30624
+ const retained = {};
30625
+ options.budget.setRetainedValues(retained, () => [...args, source]);
30602
30626
  try {
30627
+ const pattern = args[0];
30628
+ const flags = args[1];
30629
+ if (!construct && isSandboxRegex(pattern) && flags === void 0) return pattern;
30630
+ const sourceValue = isSandboxRegex(pattern) ? pattern.source : pattern;
30631
+ const flagsValue = isSandboxRegex(pattern) && flags === void 0 ? pattern.flags : flags;
30632
+ source = sourceValue === void 0 ? "" : await sandboxString(sourceValue, options.budget, context);
30633
+ const flagText = flagsValue === void 0 ? "" : await sandboxString(flagsValue, options.budget, context);
30603
30634
  const regex = createSandboxRegex(
30604
- String(args[0] ?? ""),
30605
- String(args[1] ?? ""),
30635
+ source,
30636
+ flagText,
30606
30637
  0,
30607
30638
  compilation
30608
30639
  );
30609
- if (context?.compilation === void 0 && selected !== void 0) {
30610
- reconcileCompiledValues(selected.budget, [regex], compilation);
30640
+ if (compilation !== context?.compilation) {
30641
+ reconcileCompiledValues(options.budget, [regex], compilation);
30611
30642
  }
30612
30643
  return regex;
30613
30644
  } finally {
30614
- if (context?.compilation === void 0) compilation.dispose();
30615
- operation?.release();
30645
+ options.budget.setRetainedValues(retained, void 0);
30646
+ if (compilation !== context?.compilation) compilation.dispose();
30647
+ operation.release();
30616
30648
  }
30617
30649
  };
30618
30650
  return {
30619
- RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: construct, construct })
30651
+ RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: invoke(false), construct: invoke(true) })
30620
30652
  };
30621
30653
  }
30622
30654
 
@@ -31173,7 +31205,7 @@ function createBuiltinBindings(options) {
31173
31205
  ...createObjectArrayGlobals(options),
31174
31206
  ...createMiscGlobals(options),
31175
31207
  ...createPromiseGlobals(options),
31176
- ...createRegexGlobals(options.compileOwner)
31208
+ ...createRegexGlobals(options)
31177
31209
  };
31178
31210
  }
31179
31211
 
@@ -33296,4 +33328,4 @@ export {
33296
33328
  FileSnapshotBackend,
33297
33329
  run
33298
33330
  };
33299
- //# sourceMappingURL=chunk-L7PHF62H.js.map
33331
+ //# sourceMappingURL=chunk-6LFWVA64.js.map