@poe-platform/safe-js 0.1.385 → 0.1.387

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-KSILYYRR.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-D6I4WNJU.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
  }
@@ -26318,6 +26347,48 @@ function createGeneratorPrototypes(budget) {
26318
26347
  generatorPrototypes.set(budget, state);
26319
26348
  }
26320
26349
 
26350
+ // packages/safe-js/src/interp/globals/iterator.ts
26351
+ function createIteratorGlobal(budget) {
26352
+ const prototype = resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]');
26353
+ const constructor = createSandboxClosure({
26354
+ guest: true,
26355
+ sandbox: true,
26356
+ name: "Iterator",
26357
+ length: 0,
26358
+ call: () => {
26359
+ throw new TypeError("Iterator is an abstract constructor.");
26360
+ },
26361
+ construct: async (_args, context) => {
26362
+ const target = context?.newTarget;
26363
+ if (target === void 0 || target === constructor)
26364
+ throw new TypeError("Iterator is an abstract constructor.");
26365
+ const parent = context?.getProperty !== void 0 ? await context.getProperty(target, "prototype") : await readPropertyDescriptor(getSandboxPropertyDescriptor(target, "prototype", budget) ?? { value: void 0 }, target, context);
26366
+ const instance = /* @__PURE__ */ Object.create(null);
26367
+ setSandboxPrototype(instance, parent !== null && typeof parent === "object" ? parent : prototype, budget);
26368
+ createDataCheckpoint(budget, context)(instance, 0, true);
26369
+ return instance;
26370
+ }
26371
+ });
26372
+ Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
26373
+ const getter = createSandboxClosure({ guest: true, sandbox: true, name: "get constructor", length: 0, call: () => constructor });
26374
+ const setter = createSandboxClosure({ guest: true, sandbox: true, name: "set constructor", length: 1, call: async ([value], context) => {
26375
+ const receiver = context?.thisValue;
26376
+ if (receiver === prototype || receiver === null || typeof receiver !== "object")
26377
+ throw new TypeError("Iterator constructor setter requires a distinct object receiver.");
26378
+ const properties = objectProperties(receiver, true);
26379
+ if (Object.hasOwn(properties, "constructor")) await setSandboxProperty(receiver, "constructor", value, budget, true, context);
26380
+ else defineOwnDataProperty(properties, "constructor", value);
26381
+ createDataCheckpoint(budget, context)(receiver, 0, true);
26382
+ return void 0;
26383
+ } });
26384
+ Object.defineProperty(prototype, "constructor", { get: accessorAdapter(getter, "get"), set: accessorAdapter(setter, "set"), configurable: true });
26385
+ registerIntrinsicFunction(budget, getter);
26386
+ registerIntrinsicFunction(budget, setter);
26387
+ registerIntrinsicFunction(budget, constructor);
26388
+ registerIntrinsicObject(budget, prototype);
26389
+ return constructor;
26390
+ }
26391
+
26321
26392
  // packages/safe-js/src/interp/globals/symbol.ts
26322
26393
  var registries = /* @__PURE__ */ new WeakMap();
26323
26394
  function createSymbolGlobal(budget) {
@@ -26940,6 +27011,7 @@ function createBuiltinBindings(options) {
26940
27011
  ...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
26941
27012
  ...createMathGlobals({ random: options.random, budget: options.budget }),
26942
27013
  ...createObjectArrayGlobals(options),
27014
+ Iterator: createIteratorGlobal(options.budget),
26943
27015
  Reflect: createReflectGlobal(options.budget),
26944
27016
  ArrayBuffer: createArrayBufferGlobal(options.budget),
26945
27017
  DataView: createDataViewGlobal(options.budget),
@@ -26949,6 +27021,7 @@ function createBuiltinBindings(options) {
26949
27021
  ...createRegexGlobals(options)
26950
27022
  };
26951
27023
  installCollectionIteratorPrototypes(options.budget);
27024
+ installRegExpIteratorPrototype(options.budget);
26952
27025
  createFunctionPrototype(options.budget, options.functionHasInstance);
26953
27026
  if (options.typedArrayPrototypes !== false) createNumericTypedArrayPrototypes(options.budget, bindings);
26954
27027
  if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
@@ -27016,7 +27089,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27016
27089
  createRawJson(node.text);
27017
27090
  return true;
27018
27091
  }
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;
27092
+ 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
27093
  const reference = (value, kinds) => {
27021
27094
  const ref = record3(value);
27022
27095
  fields(ref, ["kind", "id"]);
@@ -27074,6 +27147,20 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27074
27147
  fields(node, ["kind", "id"], ["state"]);
27075
27148
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
27076
27149
  if (Object.hasOwn(node, "state")) state(node.state);
27150
+ } else if (node.kind === "guest-regexp-iterator") {
27151
+ fields(node, ["kind", "matcher", "input", "exhausted", "state"], ["global", "unicode"]);
27152
+ if (typeof node.exhausted !== "boolean" || typeof node.input !== "string" && !absent(node.input))
27153
+ throw new TypeError("Invalid RegExp iterator state.");
27154
+ if ((Object.hasOwn(node, "global") || Object.hasOwn(node, "unicode")) && (typeof node.global !== "boolean" || typeof node.unicode !== "boolean"))
27155
+ throw new TypeError("Invalid RegExp iterator modes.");
27156
+ if (absent(node.matcher)) {
27157
+ if (!node.exhausted) throw new TypeError("Live RegExp iterator requires a matcher.");
27158
+ } else {
27159
+ const matcher = reference(node.matcher);
27160
+ if (matcher.kind === "symbol" || matcher.kind === "scope-frame") throw new TypeError("Invalid RegExp iterator matcher.");
27161
+ }
27162
+ if (!node.exhausted && absent(node.input)) throw new TypeError("Live RegExp iterator requires input.");
27163
+ state(node.state);
27077
27164
  } else if (node.kind === "guest-collection-iterator") {
27078
27165
  fields(node, ["kind", "collectionKind", "method", "collection", "index", "exhausted", "state"]);
27079
27166
  if (!["map", "set"].includes(String(node.collectionKind)) || !["keys", "values", "entries"].includes(String(node.method)) || typeof node.exhausted !== "boolean")
@@ -29091,6 +29178,7 @@ function measureSandboxData(values, options = {}) {
29091
29178
  for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
29092
29179
  usage += key.length + 1;
29093
29180
  if ("value" in descriptor) visit(descriptor.value, depth + 1);
29181
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
29094
29182
  }
29095
29183
  return;
29096
29184
  }
@@ -29287,8 +29375,8 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
29287
29375
  throw new TypeError("Array iterators require a portable guest snapshot, not a data copy.");
29288
29376
  }
29289
29377
  if (isSandboxRegExpIterator(value)) {
29290
- if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29291
29378
  if (!cloneSandboxCollections) return value;
29379
+ if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29292
29380
  const existing = state.seen.get(value);
29293
29381
  if (existing !== void 0) return existing;
29294
29382
  const snapshot = regexpIteratorState(value);
@@ -31646,6 +31734,7 @@ var KNOWN_RUNTIME_GLOBALS = [
31646
31734
  "Infinity",
31647
31735
  "isFinite",
31648
31736
  "isNaN",
31737
+ "Iterator",
31649
31738
  "JSON",
31650
31739
  "Map",
31651
31740
  ...Object.keys(numericTypedArrayConstructors),
@@ -44148,4 +44237,4 @@ export {
44148
44237
  FileSnapshotBackend,
44149
44238
  run
44150
44239
  };
44151
- //# sourceMappingURL=chunk-4M2UASWA.js.map
44240
+ //# sourceMappingURL=chunk-KSILYYRR.js.map