@poe-platform/safe-js 0.1.191 → 0.1.192

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-DXCKCEDV.js";
30
+ } from "./chunk-SKWFZYFI.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-YGFHNJKK.js.map
8252
+ //# sourceMappingURL=chunk-Q6OWZDNT.js.map
@@ -2392,6 +2392,7 @@ function parseFlags(flags, guard) {
2392
2392
  guard.allocate(10);
2393
2393
  const parsed = {
2394
2394
  global: false,
2395
+ sticky: false,
2395
2396
  ignoreCase: false,
2396
2397
  multiline: false,
2397
2398
  dotAll: false
@@ -2400,7 +2401,8 @@ function parseFlags(flags, guard) {
2400
2401
  g: "global",
2401
2402
  i: "ignoreCase",
2402
2403
  m: "multiline",
2403
- s: "dotAll"
2404
+ s: "dotAll",
2405
+ y: "sticky"
2404
2406
  };
2405
2407
  for (let position = 0; position < flags.length; position += 1) {
2406
2408
  guard.work(1);
@@ -9299,7 +9301,7 @@ async function withRunResources(signal, execute) {
9299
9301
 
9300
9302
  // packages/safe-js/src/interp/regex/engine.ts
9301
9303
  function matchRegex(pattern, input, lastIndex = 0) {
9302
- const startIndex = pattern.flags.global ? normalizeLastIndex(lastIndex) : 0;
9304
+ const startIndex = pattern.flags.global || pattern.flags.sticky ? normalizeLastIndex(lastIndex) : 0;
9303
9305
  return matchRegexFrom(pattern, input, startIndex);
9304
9306
  }
9305
9307
  function matchRegexFrom(pattern, input, startIndex) {
@@ -9317,6 +9319,7 @@ function matchRegexFrom(pattern, input, startIndex) {
9317
9319
  if (!result.done) {
9318
9320
  return toRegexMatch(input, attempt, result.value);
9319
9321
  }
9322
+ if (pattern.flags.sticky) break;
9320
9323
  }
9321
9324
  return null;
9322
9325
  }
@@ -16716,7 +16719,7 @@ async function regexToString(target, budget, context) {
16716
16719
  function executeRegex(target, input, lastIndex) {
16717
16720
  const pattern = getSandboxRegexPattern(target);
16718
16721
  const match = matchRegex(pattern, input, lastIndex);
16719
- if (pattern.flags.global) {
16722
+ if (pattern.flags.global || pattern.flags.sticky) {
16720
16723
  target.lastIndex = match === null ? 0 : match.index + match.text.length;
16721
16724
  }
16722
16725
  return match;
@@ -34457,6 +34460,90 @@ function defineDataProperty2(target, key, value) {
34457
34460
  });
34458
34461
  }
34459
34462
 
34463
+ // packages/safe-js/src/interp/methods/regex-split.ts
34464
+ async function regexSplit(target, input, limit, constructor, budget, context) {
34465
+ if (target === null || typeof target !== "object") throw new TypeError("RegExp split requires an object receiver.");
34466
+ let string;
34467
+ let species;
34468
+ let field;
34469
+ let flags;
34470
+ let matcher;
34471
+ let match;
34472
+ const result = [];
34473
+ const release = retainValues(budget, () => [target, input, limit, string, species, field, flags, matcher, match, result]);
34474
+ const read = (value, key) => {
34475
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
34476
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
34477
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
34478
+ };
34479
+ const append = (value) => {
34480
+ budget.allocateArrayLength(result.length + 1);
34481
+ result.push(value);
34482
+ };
34483
+ try {
34484
+ string = await sandboxString(input, budget, context);
34485
+ input = void 0;
34486
+ field = await read(target, "constructor");
34487
+ species = constructor;
34488
+ if (field !== void 0) {
34489
+ if (field === null || typeof field !== "object") throw new TypeError("Invalid RegExp species constructor.");
34490
+ species = await read(field, Symbol.species);
34491
+ if (species === null || species === void 0) species = constructor;
34492
+ }
34493
+ field = void 0;
34494
+ if (!isSandboxClosure(species) || species.construct === void 0) throw new TypeError("RegExp species must be a constructor.");
34495
+ field = await read(target, "flags");
34496
+ flags = await sandboxString(field, budget, context);
34497
+ field = void 0;
34498
+ const unicode = flags.includes("u") || flags.includes("v");
34499
+ if (!flags.includes("y")) flags = budget.allocateString(flags + "y");
34500
+ matcher = await invokeBuiltinClosure(species, [target, flags], budget, context, void 0, true);
34501
+ const maximum = limit === void 0 ? 2 ** 32 - 1 : await sandboxNumber(limit, budget, context) >>> 0;
34502
+ limit = void 0;
34503
+ if (maximum === 0) return result;
34504
+ if (string.length === 0) {
34505
+ match = await regexExec(matcher, string, budget, context);
34506
+ if (match === null) append(string);
34507
+ return result;
34508
+ }
34509
+ let end = 0;
34510
+ let index = 0;
34511
+ while (index < string.length) {
34512
+ budget.visitNode();
34513
+ match = void 0;
34514
+ await setSandboxProperty(matcher, "lastIndex", index, budget, true, context);
34515
+ match = await regexExec(matcher, string, budget, context);
34516
+ if (match !== null) {
34517
+ field = await read(matcher, "lastIndex");
34518
+ const next = Math.min(normalizeLastIndex(await sandboxNumber(field, budget, context)), string.length);
34519
+ field = void 0;
34520
+ if (next !== end) {
34521
+ append(budget.allocateString(string.slice(end, index)));
34522
+ if (result.length === maximum) return result;
34523
+ end = next;
34524
+ field = await read(match, "length");
34525
+ const length = normalizeLastIndex(await sandboxNumber(field, budget, context));
34526
+ field = void 0;
34527
+ for (let capture = 1; capture < length; capture++) {
34528
+ budget.visitNode();
34529
+ field = await read(match, String(capture));
34530
+ append(field);
34531
+ field = void 0;
34532
+ if (result.length === maximum) return result;
34533
+ }
34534
+ index = end;
34535
+ continue;
34536
+ }
34537
+ }
34538
+ index += unicode && (string.codePointAt(index) ?? 0) > 65535 ? 2 : 1;
34539
+ }
34540
+ append(budget.allocateString(string.slice(end)));
34541
+ return result;
34542
+ } finally {
34543
+ release();
34544
+ }
34545
+ }
34546
+
34460
34547
  // packages/safe-js/src/interp/globals/regex.ts
34461
34548
  function createRegexGlobals(options) {
34462
34549
  const invoke = (construct) => async (args, context) => {
@@ -34629,6 +34716,17 @@ function createRegexGlobals(options) {
34629
34716
  writable: true,
34630
34717
  configurable: true
34631
34718
  });
34719
+ Object.defineProperty(prototype, Symbol.split, {
34720
+ value: createSandboxClosure({
34721
+ guest: true,
34722
+ sandbox: true,
34723
+ name: "[Symbol.split]",
34724
+ length: 2,
34725
+ call: (args, context) => regexSplit(context?.thisValue, args[0], args[1], constructor, options.budget, context)
34726
+ }),
34727
+ writable: true,
34728
+ configurable: true
34729
+ });
34632
34730
  for (const name of ["exec", "test", "toString"]) {
34633
34731
  Object.defineProperty(prototype, name, {
34634
34732
  value: createSandboxClosure({
@@ -36973,4 +37071,4 @@ export {
36973
37071
  FileSnapshotBackend,
36974
37072
  run
36975
37073
  };
36976
- //# sourceMappingURL=chunk-DXCKCEDV.js.map
37074
+ //# sourceMappingURL=chunk-SKWFZYFI.js.map