poe-code 14.0.54 → 14.0.55

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.
package/dist/index.js CHANGED
@@ -145168,7 +145168,8 @@ function getStringMember(value, property, budget) {
145168
145168
  args,
145169
145169
  budget,
145170
145170
  (closure, closureArgs) => invokeBuiltinClosure(closure, closureArgs, budget, context, void 0),
145171
- context?.compilation
145171
+ context?.compilation,
145172
+ context
145172
145173
  );
145173
145174
  } finally {
145174
145175
  budget.setRetainedValues(retainedReceiver, void 0);
@@ -145188,7 +145189,7 @@ function isStringMethodName(property) {
145188
145189
  }
145189
145190
  function validateStringMethodArguments(_methodName, _args) {
145190
145191
  }
145191
- function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent) {
145192
+ function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
145192
145193
  if (methodName === "isWellFormed") {
145193
145194
  for (let index = 0; index < value.length; index++) {
145194
145195
  const codeUnit = value.charCodeAt(index);
@@ -145227,6 +145228,9 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
145227
145228
  if (methodName === "replace" || methodName === "replaceAll") {
145228
145229
  return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
145229
145230
  }
145231
+ if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
145232
+ return callStringPattern(value, methodName, args[0], budget, parent, context);
145233
+ }
145230
145234
  const operation = budget.acquireCompileOwner(false, parent?.owner);
145231
145235
  const compilation = new CompileScope(operation.owner);
145232
145236
  try {
@@ -145497,6 +145501,21 @@ function callSplit(value, args, budget, compilation) {
145497
145501
  budget.allocateArrayLength(result.length);
145498
145502
  return result;
145499
145503
  }
145504
+ async function callStringPattern(value, methodName, pattern, budget, parent, context) {
145505
+ const operation = budget.acquireCompileOwner(false, parent?.owner);
145506
+ const compilation = new CompileScope(operation.owner);
145507
+ const retainedPattern = {};
145508
+ budget.setRetainedValues(retainedPattern, () => [pattern]);
145509
+ try {
145510
+ const source = pattern === void 0 ? "" : await sandboxString(pattern, budget, context);
145511
+ const regex = createSandboxRegex(source, methodName === "matchAll" ? "g" : "", 0, compilation);
145512
+ return callMatchLikeMethod(value, methodName, [regex], compilation);
145513
+ } finally {
145514
+ budget.setRetainedValues(retainedPattern, void 0);
145515
+ compilation.dispose();
145516
+ operation.release();
145517
+ }
145518
+ }
145500
145519
  function callMatchLikeMethod(value, methodName, args, compilation) {
145501
145520
  const regex = args[0];
145502
145521
  if (!isSandboxRegex(regex))
@@ -145514,15 +145533,16 @@ function callMatchLikeMethod(value, methodName, args, compilation) {
145514
145533
  return toMatchArray(executeRegex(regex, value), value);
145515
145534
  if (methodName === "match") regex.lastIndex = 0;
145516
145535
  const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, regex.lastIndex, compilation) : regex;
145517
- const matches = collectRegexMatches(matcher, value, true);
145536
+ const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget);
145518
145537
  if (methodName === "match" && matches.length === 0) return null;
145519
145538
  return methodName === "match" ? matches.map((match) => match.text) : matches.map((match) => toMatchArray(match, value));
145520
145539
  }
145521
- function collectRegexMatches(regex, value, all) {
145540
+ function collectRegexMatches(regex, value, all, budget) {
145522
145541
  const matches = [];
145523
145542
  do {
145524
145543
  const match = executeRegex(regex, value);
145525
145544
  if (match === null) break;
145545
+ budget?.allocateArrayLength(matches.length + 1);
145526
145546
  matches.push(match);
145527
145547
  if (all && match.text.length === 0) regex.lastIndex += 1;
145528
145548
  } while (all);
@@ -148455,7 +148475,8 @@ async function evaluateStringMethodCall(node, target, methodName, context) {
148455
148475
  args.value,
148456
148476
  context.budget,
148457
148477
  (closure, closureArgs) => invokeSandboxClosure(closure, closureArgs, context, context.callStack),
148458
- context.compilation
148478
+ context.compilation,
148479
+ createCoercionContext(context)
148459
148480
  )
148460
148481
  };
148461
148482
  } catch (error3) {
@@ -151013,32 +151034,43 @@ var init_math = __esm({
151013
151034
  });
151014
151035
 
151015
151036
  // packages/safe-js/src/interp/globals/regex.ts
151016
- function createRegexGlobals(owner) {
151017
- const construct = (args, context) => {
151018
- const selected = owner ?? context?.compilation?.owner;
151037
+ function createRegexGlobals(options) {
151038
+ const invoke2 = (construct) => async (args, context) => {
151039
+ const selected = options.compileOwner ?? context?.compilation?.owner;
151019
151040
  if (context?.compilation?.owner !== void 0 && selected !== context.compilation.owner) {
151020
151041
  throw new SandboxError("reentry");
151021
151042
  }
151022
- const operation = selected?.budget.acquireCompileOwner(false, selected);
151023
- const compilation = context?.compilation ?? new CompileScope(selected);
151043
+ const operation = options.budget.acquireCompileOwner(false, selected);
151044
+ const compilation = context?.compilation?.owner === operation.owner ? context.compilation : new CompileScope(operation.owner);
151045
+ let source = "";
151046
+ const retained = {};
151047
+ options.budget.setRetainedValues(retained, () => [...args, source]);
151024
151048
  try {
151049
+ const pattern = args[0];
151050
+ const flags = args[1];
151051
+ if (!construct && isSandboxRegex(pattern) && flags === void 0) return pattern;
151052
+ const sourceValue = isSandboxRegex(pattern) ? pattern.source : pattern;
151053
+ const flagsValue = isSandboxRegex(pattern) && flags === void 0 ? pattern.flags : flags;
151054
+ source = sourceValue === void 0 ? "" : await sandboxString(sourceValue, options.budget, context);
151055
+ const flagText = flagsValue === void 0 ? "" : await sandboxString(flagsValue, options.budget, context);
151025
151056
  const regex = createSandboxRegex(
151026
- String(args[0] ?? ""),
151027
- String(args[1] ?? ""),
151057
+ source,
151058
+ flagText,
151028
151059
  0,
151029
151060
  compilation
151030
151061
  );
151031
- if (context?.compilation === void 0 && selected !== void 0) {
151032
- reconcileCompiledValues(selected.budget, [regex], compilation);
151062
+ if (compilation !== context?.compilation) {
151063
+ reconcileCompiledValues(options.budget, [regex], compilation);
151033
151064
  }
151034
151065
  return regex;
151035
151066
  } finally {
151036
- if (context?.compilation === void 0) compilation.dispose();
151037
- operation?.release();
151067
+ options.budget.setRetainedValues(retained, void 0);
151068
+ if (compilation !== context?.compilation) compilation.dispose();
151069
+ operation.release();
151038
151070
  }
151039
151071
  };
151040
151072
  return {
151041
- RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: construct, construct })
151073
+ RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: invoke2(false), construct: invoke2(true) })
151042
151074
  };
151043
151075
  }
151044
151076
  var init_regex2 = __esm({
@@ -151047,6 +151079,7 @@ var init_regex2 = __esm({
151047
151079
  init_values();
151048
151080
  init_compile_guard();
151049
151081
  init_budget2();
151082
+ init_string_coercion();
151050
151083
  }
151051
151084
  });
151052
151085
 
@@ -151630,7 +151663,7 @@ function createBuiltinBindings(options) {
151630
151663
  ...createObjectArrayGlobals(options),
151631
151664
  ...createMiscGlobals(options),
151632
151665
  ...createPromiseGlobals(options),
151633
- ...createRegexGlobals(options.compileOwner)
151666
+ ...createRegexGlobals(options)
151634
151667
  };
151635
151668
  }
151636
151669
  var init_globals = __esm({