@poe-platform/safe-js 0.1.118 → 0.1.120

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-7FCWZM6I.js";
30
+ } from "./chunk-XI33TU4X.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8245,4 +8245,4 @@ export {
8245
8245
  parseMcpConfig,
8246
8246
  makeMcpModule
8247
8247
  };
8248
- //# sourceMappingURL=chunk-UPKTG5MR.js.map
8248
+ //# sourceMappingURL=chunk-XEFVZTJ7.js.map
@@ -8524,7 +8524,7 @@ function getRegexMember(target, property, budget) {
8524
8524
  return createSandboxClosure({
8525
8525
  sandbox: true,
8526
8526
  name: `RegExp#${property}`,
8527
- call: (args) => callRegexMethod(target, property, args)
8527
+ call: (args, context) => callRegexMethod(context?.thisValue, property, args, budget, context)
8528
8528
  });
8529
8529
  }
8530
8530
  function escapeRegexSource(source, budget) {
@@ -8554,9 +8554,30 @@ function setRegexMember(target, property, value) {
8554
8554
  }
8555
8555
  target.lastIndex = Number(value);
8556
8556
  }
8557
- function callRegexMethod(target, methodName, args) {
8558
- const match = executeRegex(target, String(args[0]));
8559
- return methodName === "test" ? match !== null : toMatchArray(match, String(args[0]));
8557
+ async function callRegexMethod(target, methodName, args, budget, context) {
8558
+ if (target === null || typeof target !== "object" || methodName === "exec" && !isSandboxRegex(target)) {
8559
+ throw new TypeError(`RegExp#${methodName} requires ${methodName === "exec" ? "a regex" : "an object"} receiver.`);
8560
+ }
8561
+ const retained = {};
8562
+ budget.setRetainedValues(retained, () => [target, ...args]);
8563
+ try {
8564
+ const input = await sandboxString(args[0], budget, context);
8565
+ if (methodName === "test") {
8566
+ const exec = context?.getProperty === void 0 ? getSandboxDataProperty(target, "exec", budget) : context.getProperty(target, "exec");
8567
+ if (isSandboxClosure(exec)) {
8568
+ const result = await invokeBuiltinClosure(exec, [input], budget, context, target);
8569
+ if (result !== null && typeof result !== "object") {
8570
+ throw new TypeError("RegExp#test exec must return an object or null.");
8571
+ }
8572
+ return result !== null;
8573
+ }
8574
+ }
8575
+ if (!isSandboxRegex(target)) throw new TypeError("RegExp execution requires a regex receiver.");
8576
+ const match = executeRegex(target, input);
8577
+ return methodName === "test" ? match !== null : toMatchArray(match, input);
8578
+ } finally {
8579
+ budget.setRetainedValues(retained, void 0);
8580
+ }
8560
8581
  }
8561
8582
  function executeRegex(target, input) {
8562
8583
  const pattern = getSandboxRegexPattern(target);
@@ -30612,32 +30633,43 @@ function defineDataProperty(target, key, value) {
30612
30633
  }
30613
30634
 
30614
30635
  // packages/safe-js/src/interp/globals/regex.ts
30615
- function createRegexGlobals(owner) {
30616
- const construct = (args, context) => {
30617
- const selected = owner ?? context?.compilation?.owner;
30636
+ function createRegexGlobals(options) {
30637
+ const invoke = (construct) => async (args, context) => {
30638
+ const selected = options.compileOwner ?? context?.compilation?.owner;
30618
30639
  if (context?.compilation?.owner !== void 0 && selected !== context.compilation.owner) {
30619
30640
  throw new SandboxError("reentry");
30620
30641
  }
30621
- const operation = selected?.budget.acquireCompileOwner(false, selected);
30622
- const compilation = context?.compilation ?? new CompileScope(selected);
30642
+ const operation = options.budget.acquireCompileOwner(false, selected);
30643
+ const compilation = context?.compilation?.owner === operation.owner ? context.compilation : new CompileScope(operation.owner);
30644
+ let source = "";
30645
+ const retained = {};
30646
+ options.budget.setRetainedValues(retained, () => [...args, source]);
30623
30647
  try {
30648
+ const pattern = args[0];
30649
+ const flags = args[1];
30650
+ if (!construct && isSandboxRegex(pattern) && flags === void 0) return pattern;
30651
+ const sourceValue = isSandboxRegex(pattern) ? pattern.source : pattern;
30652
+ const flagsValue = isSandboxRegex(pattern) && flags === void 0 ? pattern.flags : flags;
30653
+ source = sourceValue === void 0 ? "" : await sandboxString(sourceValue, options.budget, context);
30654
+ const flagText = flagsValue === void 0 ? "" : await sandboxString(flagsValue, options.budget, context);
30624
30655
  const regex = createSandboxRegex(
30625
- String(args[0] ?? ""),
30626
- String(args[1] ?? ""),
30656
+ source,
30657
+ flagText,
30627
30658
  0,
30628
30659
  compilation
30629
30660
  );
30630
- if (context?.compilation === void 0 && selected !== void 0) {
30631
- reconcileCompiledValues(selected.budget, [regex], compilation);
30661
+ if (compilation !== context?.compilation) {
30662
+ reconcileCompiledValues(options.budget, [regex], compilation);
30632
30663
  }
30633
30664
  return regex;
30634
30665
  } finally {
30635
- if (context?.compilation === void 0) compilation.dispose();
30636
- operation?.release();
30666
+ options.budget.setRetainedValues(retained, void 0);
30667
+ if (compilation !== context?.compilation) compilation.dispose();
30668
+ operation.release();
30637
30669
  }
30638
30670
  };
30639
30671
  return {
30640
- RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: construct, construct })
30672
+ RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: invoke(false), construct: invoke(true) })
30641
30673
  };
30642
30674
  }
30643
30675
 
@@ -31194,7 +31226,7 @@ function createBuiltinBindings(options) {
31194
31226
  ...createObjectArrayGlobals(options),
31195
31227
  ...createMiscGlobals(options),
31196
31228
  ...createPromiseGlobals(options),
31197
- ...createRegexGlobals(options.compileOwner)
31229
+ ...createRegexGlobals(options)
31198
31230
  };
31199
31231
  }
31200
31232
 
@@ -33317,4 +33349,4 @@ export {
33317
33349
  FileSnapshotBackend,
33318
33350
  run
33319
33351
  };
33320
- //# sourceMappingURL=chunk-7FCWZM6I.js.map
33352
+ //# sourceMappingURL=chunk-XI33TU4X.js.map