poe-code 14.0.54 → 14.0.56

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
@@ -128502,7 +128502,7 @@ function getRegexMember(target, property, budget) {
128502
128502
  return createSandboxClosure({
128503
128503
  sandbox: true,
128504
128504
  name: `RegExp#${property}`,
128505
- call: (args) => callRegexMethod(target, property, args)
128505
+ call: (args, context) => callRegexMethod(context?.thisValue, property, args, budget, context)
128506
128506
  });
128507
128507
  }
128508
128508
  function escapeRegexSource(source, budget) {
@@ -128532,9 +128532,30 @@ function setRegexMember(target, property, value) {
128532
128532
  }
128533
128533
  target.lastIndex = Number(value);
128534
128534
  }
128535
- function callRegexMethod(target, methodName, args) {
128536
- const match = executeRegex(target, String(args[0]));
128537
- return methodName === "test" ? match !== null : toMatchArray(match, String(args[0]));
128535
+ async function callRegexMethod(target, methodName, args, budget, context) {
128536
+ if (target === null || typeof target !== "object" || methodName === "exec" && !isSandboxRegex(target)) {
128537
+ throw new TypeError(`RegExp#${methodName} requires ${methodName === "exec" ? "a regex" : "an object"} receiver.`);
128538
+ }
128539
+ const retained = {};
128540
+ budget.setRetainedValues(retained, () => [target, ...args]);
128541
+ try {
128542
+ const input = await sandboxString(args[0], budget, context);
128543
+ if (methodName === "test") {
128544
+ const exec2 = context?.getProperty === void 0 ? getSandboxDataProperty(target, "exec", budget) : context.getProperty(target, "exec");
128545
+ if (isSandboxClosure(exec2)) {
128546
+ const result = await invokeBuiltinClosure(exec2, [input], budget, context, target);
128547
+ if (result !== null && typeof result !== "object") {
128548
+ throw new TypeError("RegExp#test exec must return an object or null.");
128549
+ }
128550
+ return result !== null;
128551
+ }
128552
+ }
128553
+ if (!isSandboxRegex(target)) throw new TypeError("RegExp execution requires a regex receiver.");
128554
+ const match = executeRegex(target, input);
128555
+ return methodName === "test" ? match !== null : toMatchArray(match, input);
128556
+ } finally {
128557
+ budget.setRetainedValues(retained, void 0);
128558
+ }
128538
128559
  }
128539
128560
  function executeRegex(target, input) {
128540
128561
  const pattern = getSandboxRegexPattern(target);
@@ -128558,6 +128579,9 @@ var init_regex = __esm({
128558
128579
  "use strict";
128559
128580
  init_values();
128560
128581
  init_engine2();
128582
+ init_builtin_call();
128583
+ init_object_model();
128584
+ init_string_coercion();
128561
128585
  regexMethodNames = /* @__PURE__ */ new Set(["exec", "test"]);
128562
128586
  }
128563
128587
  });
@@ -145168,7 +145192,8 @@ function getStringMember(value, property, budget) {
145168
145192
  args,
145169
145193
  budget,
145170
145194
  (closure, closureArgs) => invokeBuiltinClosure(closure, closureArgs, budget, context, void 0),
145171
- context?.compilation
145195
+ context?.compilation,
145196
+ context
145172
145197
  );
145173
145198
  } finally {
145174
145199
  budget.setRetainedValues(retainedReceiver, void 0);
@@ -145188,7 +145213,7 @@ function isStringMethodName(property) {
145188
145213
  }
145189
145214
  function validateStringMethodArguments(_methodName, _args) {
145190
145215
  }
145191
- function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent) {
145216
+ function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
145192
145217
  if (methodName === "isWellFormed") {
145193
145218
  for (let index = 0; index < value.length; index++) {
145194
145219
  const codeUnit = value.charCodeAt(index);
@@ -145227,6 +145252,9 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
145227
145252
  if (methodName === "replace" || methodName === "replaceAll") {
145228
145253
  return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
145229
145254
  }
145255
+ if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
145256
+ return callStringPattern(value, methodName, args[0], budget, parent, context);
145257
+ }
145230
145258
  const operation = budget.acquireCompileOwner(false, parent?.owner);
145231
145259
  const compilation = new CompileScope(operation.owner);
145232
145260
  try {
@@ -145497,6 +145525,21 @@ function callSplit(value, args, budget, compilation) {
145497
145525
  budget.allocateArrayLength(result.length);
145498
145526
  return result;
145499
145527
  }
145528
+ async function callStringPattern(value, methodName, pattern, budget, parent, context) {
145529
+ const operation = budget.acquireCompileOwner(false, parent?.owner);
145530
+ const compilation = new CompileScope(operation.owner);
145531
+ const retainedPattern = {};
145532
+ budget.setRetainedValues(retainedPattern, () => [pattern]);
145533
+ try {
145534
+ const source = pattern === void 0 ? "" : await sandboxString(pattern, budget, context);
145535
+ const regex = createSandboxRegex(source, methodName === "matchAll" ? "g" : "", 0, compilation);
145536
+ return callMatchLikeMethod(value, methodName, [regex], compilation);
145537
+ } finally {
145538
+ budget.setRetainedValues(retainedPattern, void 0);
145539
+ compilation.dispose();
145540
+ operation.release();
145541
+ }
145542
+ }
145500
145543
  function callMatchLikeMethod(value, methodName, args, compilation) {
145501
145544
  const regex = args[0];
145502
145545
  if (!isSandboxRegex(regex))
@@ -145514,15 +145557,16 @@ function callMatchLikeMethod(value, methodName, args, compilation) {
145514
145557
  return toMatchArray(executeRegex(regex, value), value);
145515
145558
  if (methodName === "match") regex.lastIndex = 0;
145516
145559
  const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, regex.lastIndex, compilation) : regex;
145517
- const matches = collectRegexMatches(matcher, value, true);
145560
+ const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget);
145518
145561
  if (methodName === "match" && matches.length === 0) return null;
145519
145562
  return methodName === "match" ? matches.map((match) => match.text) : matches.map((match) => toMatchArray(match, value));
145520
145563
  }
145521
- function collectRegexMatches(regex, value, all) {
145564
+ function collectRegexMatches(regex, value, all, budget) {
145522
145565
  const matches = [];
145523
145566
  do {
145524
145567
  const match = executeRegex(regex, value);
145525
145568
  if (match === null) break;
145569
+ budget?.allocateArrayLength(matches.length + 1);
145526
145570
  matches.push(match);
145527
145571
  if (all && match.text.length === 0) regex.lastIndex += 1;
145528
145572
  } while (all);
@@ -148455,7 +148499,8 @@ async function evaluateStringMethodCall(node, target, methodName, context) {
148455
148499
  args.value,
148456
148500
  context.budget,
148457
148501
  (closure, closureArgs) => invokeSandboxClosure(closure, closureArgs, context, context.callStack),
148458
- context.compilation
148502
+ context.compilation,
148503
+ createCoercionContext(context)
148459
148504
  )
148460
148505
  };
148461
148506
  } catch (error3) {
@@ -151013,32 +151058,43 @@ var init_math = __esm({
151013
151058
  });
151014
151059
 
151015
151060
  // packages/safe-js/src/interp/globals/regex.ts
151016
- function createRegexGlobals(owner) {
151017
- const construct = (args, context) => {
151018
- const selected = owner ?? context?.compilation?.owner;
151061
+ function createRegexGlobals(options) {
151062
+ const invoke2 = (construct) => async (args, context) => {
151063
+ const selected = options.compileOwner ?? context?.compilation?.owner;
151019
151064
  if (context?.compilation?.owner !== void 0 && selected !== context.compilation.owner) {
151020
151065
  throw new SandboxError("reentry");
151021
151066
  }
151022
- const operation = selected?.budget.acquireCompileOwner(false, selected);
151023
- const compilation = context?.compilation ?? new CompileScope(selected);
151067
+ const operation = options.budget.acquireCompileOwner(false, selected);
151068
+ const compilation = context?.compilation?.owner === operation.owner ? context.compilation : new CompileScope(operation.owner);
151069
+ let source = "";
151070
+ const retained = {};
151071
+ options.budget.setRetainedValues(retained, () => [...args, source]);
151024
151072
  try {
151073
+ const pattern = args[0];
151074
+ const flags = args[1];
151075
+ if (!construct && isSandboxRegex(pattern) && flags === void 0) return pattern;
151076
+ const sourceValue = isSandboxRegex(pattern) ? pattern.source : pattern;
151077
+ const flagsValue = isSandboxRegex(pattern) && flags === void 0 ? pattern.flags : flags;
151078
+ source = sourceValue === void 0 ? "" : await sandboxString(sourceValue, options.budget, context);
151079
+ const flagText = flagsValue === void 0 ? "" : await sandboxString(flagsValue, options.budget, context);
151025
151080
  const regex = createSandboxRegex(
151026
- String(args[0] ?? ""),
151027
- String(args[1] ?? ""),
151081
+ source,
151082
+ flagText,
151028
151083
  0,
151029
151084
  compilation
151030
151085
  );
151031
- if (context?.compilation === void 0 && selected !== void 0) {
151032
- reconcileCompiledValues(selected.budget, [regex], compilation);
151086
+ if (compilation !== context?.compilation) {
151087
+ reconcileCompiledValues(options.budget, [regex], compilation);
151033
151088
  }
151034
151089
  return regex;
151035
151090
  } finally {
151036
- if (context?.compilation === void 0) compilation.dispose();
151037
- operation?.release();
151091
+ options.budget.setRetainedValues(retained, void 0);
151092
+ if (compilation !== context?.compilation) compilation.dispose();
151093
+ operation.release();
151038
151094
  }
151039
151095
  };
151040
151096
  return {
151041
- RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: construct, construct })
151097
+ RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: invoke2(false), construct: invoke2(true) })
151042
151098
  };
151043
151099
  }
151044
151100
  var init_regex2 = __esm({
@@ -151047,6 +151103,7 @@ var init_regex2 = __esm({
151047
151103
  init_values();
151048
151104
  init_compile_guard();
151049
151105
  init_budget2();
151106
+ init_string_coercion();
151050
151107
  }
151051
151108
  });
151052
151109
 
@@ -151630,7 +151687,7 @@ function createBuiltinBindings(options) {
151630
151687
  ...createObjectArrayGlobals(options),
151631
151688
  ...createMiscGlobals(options),
151632
151689
  ...createPromiseGlobals(options),
151633
- ...createRegexGlobals(options.compileOwner)
151690
+ ...createRegexGlobals(options)
151634
151691
  };
151635
151692
  }
151636
151693
  var init_globals = __esm({