@poe-platform/safe-js 0.1.385 → 0.1.386

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-4M2UASWA.js";
30
+ } from "./chunk-XJL73BPS.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-C2JQFCZY.js.map
8252
+ //# sourceMappingURL=chunk-IZEDCQDW.js.map
@@ -7349,11 +7349,12 @@ function arrayIteratorState(value) {
7349
7349
  }
7350
7350
 
7351
7351
  // packages/safe-js/src/interp/regexp-iterator.ts
7352
+ var regexpIteratorPrototypes = /* @__PURE__ */ new WeakMap();
7352
7353
  var states3 = /* @__PURE__ */ new WeakMap();
7353
7354
  function isSandboxRegExpIterator(value) {
7354
7355
  return typeof value === "object" && value !== null && states3.has(value);
7355
7356
  }
7356
- function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.create(null)) {
7357
+ function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.create(null), budget) {
7357
7358
  if ((state.global !== void 0 || state.unicode !== void 0) && (typeof state.global !== "boolean" || typeof state.unicode !== "boolean"))
7358
7359
  throw new TypeError("Invalid RegExp iterator modes.");
7359
7360
  if (state.matcher !== void 0 && (state.matcher === null || typeof state.matcher !== "object"))
@@ -7361,6 +7362,8 @@ function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.cre
7361
7362
  if (!state.exhausted && (state.matcher === void 0 || state.input === void 0))
7362
7363
  throw new TypeError("A live RegExp iterator requires its matcher and input.");
7363
7364
  states3.set(target, state.exhausted ? { ...state, matcher: void 0, input: void 0, exhausted: true } : { ...state });
7365
+ const prototype = budget === void 0 ? void 0 : regexpIteratorPrototypes.get(budget);
7366
+ if (prototype !== void 0) setSandboxPrototype(target, prototype, budget);
7364
7367
  return target;
7365
7368
  }
7366
7369
  function regexpIteratorState(value) {
@@ -9751,8 +9754,10 @@ function getRegExpIteratorMember(property, budget) {
9751
9754
  });
9752
9755
  if (property !== "next") return void 0;
9753
9756
  return createSandboxClosure({
9757
+ guest: true,
9754
9758
  sandbox: true,
9755
9759
  name: "next",
9760
+ length: 0,
9756
9761
  call: (_args, context) => {
9757
9762
  const receiver = context?.thisValue;
9758
9763
  if (!isSandboxRegExpIterator(receiver))
@@ -9993,6 +9998,8 @@ function getSandboxIterator(value, budget, context) {
9993
9998
  snapshotIndex: () => 0,
9994
9999
  snapshot: () => ({ kind: "builtin", value, index: 0 })
9995
10000
  };
10001
+ if (isSandboxRegExpIterator(value) && hasExplicitSandboxPrototype(value))
10002
+ return context?.getProperty === void 0 ? guestProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9996
10003
  if (isSandboxRegExpIterator(value)) {
9997
10004
  if (context !== void 0 && budget !== void 0)
9998
10005
  return {
@@ -13244,7 +13251,7 @@ function callStringRegexCursor(value, methodName, regex, budget, parent, context
13244
13251
  const finish = (lastIndex2) => {
13245
13252
  if (matcher !== void 0) {
13246
13253
  matcher.lastIndex = normalizeLastIndex(lastIndex2);
13247
- return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false });
13254
+ return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false }, void 0, budget);
13248
13255
  }
13249
13256
  return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex2);
13250
13257
  };
@@ -13294,7 +13301,7 @@ function callMatchLikeMethod(value, methodName, args, compilation, lastIndex) {
13294
13301
  if (methodName === "match") regex.lastIndex = 0;
13295
13302
  const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, normalizeLastIndex(lastIndex ?? Number(regex.lastIndex)), compilation) : regex;
13296
13303
  if (methodName === "matchAll")
13297
- return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false });
13304
+ return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false }, void 0, compilation.owner?.budget);
13298
13305
  const matches = collectRegexMatches(matcher, value, matcher.flags.includes("g"), compilation.owner?.budget, Number(matcher.lastIndex));
13299
13306
  return matches.length === 0 ? null : matches.map((match) => match.text);
13300
13307
  }
@@ -18673,7 +18680,7 @@ function getPropertyValue(target, property, context, receiver = target) {
18673
18680
  const descriptor = getSandboxPropertyDescriptor(target, property, context.budget);
18674
18681
  if (descriptor !== void 0)
18675
18682
  return readPropertyDescriptor(descriptor, receiver, createCoercionContext(context), true);
18676
- if (isSandboxRegExpIterator(target)) return getRegExpIteratorMember(property, context.budget);
18683
+ if (isSandboxRegExpIterator(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getRegExpIteratorMember(property, context.budget);
18677
18684
  if (typeof target === "symbol" || typeof target === "bigint") {
18678
18685
  const prototype = getBoxedPrototype(target, context.budget);
18679
18686
  return prototype === void 0 ? void 0 : getPropertyValue(prototype, property, context, receiver);
@@ -22041,6 +22048,17 @@ function captureGuestHeapNode(value, encode) {
22041
22048
  state: captureObjectState(value, encode)
22042
22049
  };
22043
22050
  }
22051
+ if (isSandboxRegExpIterator(value) && hasGuestObjectState(value)) {
22052
+ const cursor = regexpIteratorState(value);
22053
+ return {
22054
+ kind: "guest-regexp-iterator",
22055
+ matcher: encode(cursor.matcher),
22056
+ input: encode(cursor.input),
22057
+ exhausted: cursor.exhausted,
22058
+ ...cursor.global === void 0 ? {} : { global: cursor.global, unicode: cursor.unicode },
22059
+ state: captureObjectState(value, encode)
22060
+ };
22061
+ }
22044
22062
  if (isRawJson(value)) return { kind: "raw-json", text: value.rawJSON };
22045
22063
  const intrinsic = getIntrinsicIdentity(value);
22046
22064
  if (intrinsic !== void 0) {
@@ -25762,6 +25780,17 @@ async function regexSplit(target, input, limit, constructor, budget, context) {
25762
25780
  }
25763
25781
 
25764
25782
  // packages/safe-js/src/interp/globals/regex.ts
25783
+ function installRegExpIteratorPrototype(budget) {
25784
+ const prototype = /* @__PURE__ */ Object.create(null);
25785
+ setSandboxPrototype(prototype, resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]'));
25786
+ Object.defineProperties(prototype, {
25787
+ next: { value: getRegExpIteratorMember("next", budget), writable: true, configurable: true },
25788
+ [Symbol.toStringTag]: { value: "RegExp String Iterator", configurable: true }
25789
+ });
25790
+ regexpIteratorPrototypes.set(budget, prototype);
25791
+ registerBuiltinIdentities(budget, { "%RegExpStringIteratorPrototype%": prototype });
25792
+ registerIntrinsicObject(budget, prototype);
25793
+ }
25765
25794
  function createRegexGlobals(options) {
25766
25795
  const invoke = (construct) => async (args, context) => {
25767
25796
  const selected = options.compileOwner ?? context?.compilation?.owner;
@@ -25963,7 +25992,7 @@ function createRegexGlobals(options) {
25963
25992
  exhausted: false,
25964
25993
  global: flags.includes("g"),
25965
25994
  unicode: flags.includes("u") || flags.includes("v")
25966
- });
25995
+ }, void 0, options.budget);
25967
25996
  } finally {
25968
25997
  release();
25969
25998
  }
@@ -26949,6 +26978,7 @@ function createBuiltinBindings(options) {
26949
26978
  ...createRegexGlobals(options)
26950
26979
  };
26951
26980
  installCollectionIteratorPrototypes(options.budget);
26981
+ installRegExpIteratorPrototype(options.budget);
26952
26982
  createFunctionPrototype(options.budget, options.functionHasInstance);
26953
26983
  if (options.typedArrayPrototypes !== false) createNumericTypedArrayPrototypes(options.budget, bindings);
26954
26984
  if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
@@ -27016,7 +27046,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27016
27046
  createRawJson(node.text);
27017
27047
  return true;
27018
27048
  }
27019
- if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "string-iterator", "guest-collection-iterator", "map", "set"].includes(String(node.kind))) return false;
27049
+ if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "string-iterator", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
27020
27050
  const reference = (value, kinds) => {
27021
27051
  const ref = record3(value);
27022
27052
  fields(ref, ["kind", "id"]);
@@ -27074,6 +27104,20 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27074
27104
  fields(node, ["kind", "id"], ["state"]);
27075
27105
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
27076
27106
  if (Object.hasOwn(node, "state")) state(node.state);
27107
+ } else if (node.kind === "guest-regexp-iterator") {
27108
+ fields(node, ["kind", "matcher", "input", "exhausted", "state"], ["global", "unicode"]);
27109
+ if (typeof node.exhausted !== "boolean" || typeof node.input !== "string" && !absent(node.input))
27110
+ throw new TypeError("Invalid RegExp iterator state.");
27111
+ if ((Object.hasOwn(node, "global") || Object.hasOwn(node, "unicode")) && (typeof node.global !== "boolean" || typeof node.unicode !== "boolean"))
27112
+ throw new TypeError("Invalid RegExp iterator modes.");
27113
+ if (absent(node.matcher)) {
27114
+ if (!node.exhausted) throw new TypeError("Live RegExp iterator requires a matcher.");
27115
+ } else {
27116
+ const matcher = reference(node.matcher);
27117
+ if (matcher.kind === "symbol" || matcher.kind === "scope-frame") throw new TypeError("Invalid RegExp iterator matcher.");
27118
+ }
27119
+ if (!node.exhausted && absent(node.input)) throw new TypeError("Live RegExp iterator requires input.");
27120
+ state(node.state);
27077
27121
  } else if (node.kind === "guest-collection-iterator") {
27078
27122
  fields(node, ["kind", "collectionKind", "method", "collection", "index", "exhausted", "state"]);
27079
27123
  if (!["map", "set"].includes(String(node.collectionKind)) || !["keys", "values", "entries"].includes(String(node.method)) || typeof node.exhausted !== "boolean")
@@ -29091,6 +29135,7 @@ function measureSandboxData(values, options = {}) {
29091
29135
  for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
29092
29136
  usage += key.length + 1;
29093
29137
  if ("value" in descriptor) visit(descriptor.value, depth + 1);
29138
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
29094
29139
  }
29095
29140
  return;
29096
29141
  }
@@ -29287,8 +29332,8 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
29287
29332
  throw new TypeError("Array iterators require a portable guest snapshot, not a data copy.");
29288
29333
  }
29289
29334
  if (isSandboxRegExpIterator(value)) {
29290
- if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29291
29335
  if (!cloneSandboxCollections) return value;
29336
+ if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29292
29337
  const existing = state.seen.get(value);
29293
29338
  if (existing !== void 0) return existing;
29294
29339
  const snapshot = regexpIteratorState(value);
@@ -44148,4 +44193,4 @@ export {
44148
44193
  FileSnapshotBackend,
44149
44194
  run
44150
44195
  };
44151
- //# sourceMappingURL=chunk-4M2UASWA.js.map
44196
+ //# sourceMappingURL=chunk-XJL73BPS.js.map