@poe-platform/safe-js 0.1.384 → 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-N3C4UP54.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-4OTKJDYX.js.map
8252
+ //# sourceMappingURL=chunk-IZEDCQDW.js.map
@@ -7272,12 +7272,16 @@ function copySandboxArgumentProperties(source, target, copyValue) {
7272
7272
  }
7273
7273
 
7274
7274
  // packages/safe-js/src/interp/collection-iterator.ts
7275
+ var collectionIteratorPrototypes = /* @__PURE__ */ new WeakMap();
7275
7276
  var states = /* @__PURE__ */ new WeakMap();
7276
7277
  function isSandboxCollectionIterator(value) {
7277
7278
  return typeof value === "object" && value !== null && states.has(value);
7278
7279
  }
7279
- function createSandboxCollectionIterator(collection, method) {
7280
- return restoreSandboxCollectionIterator({ collection, collectionKind: collection.kind, method, index: 0, exhausted: false });
7280
+ function createSandboxCollectionIterator(collection, method, budget) {
7281
+ const iterator = restoreSandboxCollectionIterator({ collection, collectionKind: collection.kind, method, index: 0, exhausted: false });
7282
+ const prototype = budget === void 0 ? void 0 : collectionIteratorPrototypes.get(budget)?.[collection.kind];
7283
+ if (prototype !== void 0) setSandboxPrototype(iterator, prototype, budget);
7284
+ return iterator;
7281
7285
  }
7282
7286
  function restoreSandboxCollectionIterator(snapshot, target = /* @__PURE__ */ Object.create(null)) {
7283
7287
  const { collection, collectionKind, method, index, exhausted } = snapshot;
@@ -7345,11 +7349,12 @@ function arrayIteratorState(value) {
7345
7349
  }
7346
7350
 
7347
7351
  // packages/safe-js/src/interp/regexp-iterator.ts
7352
+ var regexpIteratorPrototypes = /* @__PURE__ */ new WeakMap();
7348
7353
  var states3 = /* @__PURE__ */ new WeakMap();
7349
7354
  function isSandboxRegExpIterator(value) {
7350
7355
  return typeof value === "object" && value !== null && states3.has(value);
7351
7356
  }
7352
- function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.create(null)) {
7357
+ function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.create(null), budget) {
7353
7358
  if ((state.global !== void 0 || state.unicode !== void 0) && (typeof state.global !== "boolean" || typeof state.unicode !== "boolean"))
7354
7359
  throw new TypeError("Invalid RegExp iterator modes.");
7355
7360
  if (state.matcher !== void 0 && (state.matcher === null || typeof state.matcher !== "object"))
@@ -7357,6 +7362,8 @@ function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.cre
7357
7362
  if (!state.exhausted && (state.matcher === void 0 || state.input === void 0))
7358
7363
  throw new TypeError("A live RegExp iterator requires its matcher and input.");
7359
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);
7360
7367
  return target;
7361
7368
  }
7362
7369
  function regexpIteratorState(value) {
@@ -9747,8 +9754,10 @@ function getRegExpIteratorMember(property, budget) {
9747
9754
  });
9748
9755
  if (property !== "next") return void 0;
9749
9756
  return createSandboxClosure({
9757
+ guest: true,
9750
9758
  sandbox: true,
9751
9759
  name: "next",
9760
+ length: 0,
9752
9761
  call: (_args, context) => {
9753
9762
  const receiver = context?.thisValue;
9754
9763
  if (!isSandboxRegExpIterator(receiver))
@@ -9787,7 +9796,7 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9787
9796
  if (!hasExplicitSandboxPrototype(value) && value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
9788
9797
  return guestIterator(value, await context.getProperty(value, "next"), asyncProtocol, budget, context, signal);
9789
9798
  }
9790
- if (!asyncProtocol && (typeof value === "string" ? lookupTarget !== void 0 : (Array.isArray(value) || isSandboxBox(value) || isSandboxMap(value) || isSandboxSet(value)) && (hasExplicitSandboxPrototype(value) || getSandboxPrototype(value, budget) !== null))) return void 0;
9799
+ if (!asyncProtocol && (typeof value === "string" ? lookupTarget !== void 0 : (Array.isArray(value) || isSandboxBox(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value)) && (hasExplicitSandboxPrototype(value) || getSandboxPrototype(value, budget) !== null))) return void 0;
9791
9800
  if (!asyncProtocol) return getSandboxIterator(value, budget, context);
9792
9801
  if (isSandboxGenerator(value) && value.async && !hasExplicitSandboxPrototype(value))
9793
9802
  return getSandboxAsyncIterator(value, budget, context, signal);
@@ -9981,12 +9990,16 @@ function getSandboxIterator(value, budget, context) {
9981
9990
  }
9982
9991
  };
9983
9992
  }
9993
+ if (isSandboxCollectionIterator(value) && hasExplicitSandboxPrototype(value))
9994
+ return context?.getProperty === void 0 ? guestProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9984
9995
  if (isSandboxCollectionIterator(value))
9985
9996
  return {
9986
9997
  next: () => nextCollectionIterator(value, budget),
9987
9998
  snapshotIndex: () => 0,
9988
9999
  snapshot: () => ({ kind: "builtin", value, index: 0 })
9989
10000
  };
10001
+ if (isSandboxRegExpIterator(value) && hasExplicitSandboxPrototype(value))
10002
+ return context?.getProperty === void 0 ? guestProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9990
10003
  if (isSandboxRegExpIterator(value)) {
9991
10004
  if (context !== void 0 && budget !== void 0)
9992
10005
  return {
@@ -13238,7 +13251,7 @@ function callStringRegexCursor(value, methodName, regex, budget, parent, context
13238
13251
  const finish = (lastIndex2) => {
13239
13252
  if (matcher !== void 0) {
13240
13253
  matcher.lastIndex = normalizeLastIndex(lastIndex2);
13241
- return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false });
13254
+ return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false }, void 0, budget);
13242
13255
  }
13243
13256
  return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex2);
13244
13257
  };
@@ -13288,7 +13301,7 @@ function callMatchLikeMethod(value, methodName, args, compilation, lastIndex) {
13288
13301
  if (methodName === "match") regex.lastIndex = 0;
13289
13302
  const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, normalizeLastIndex(lastIndex ?? Number(regex.lastIndex)), compilation) : regex;
13290
13303
  if (methodName === "matchAll")
13291
- return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false });
13304
+ return restoreSandboxRegExpIterator({ matcher, input: value, exhausted: false }, void 0, compilation.owner?.budget);
13292
13305
  const matches = collectRegexMatches(matcher, value, matcher.flags.includes("g"), compilation.owner?.budget, Number(matcher.lastIndex));
13293
13306
  return matches.length === 0 ? null : matches.map((match) => match.text);
13294
13307
  }
@@ -16087,7 +16100,7 @@ async function callMapMethod(target, methodName, args, options, stack = []) {
16087
16100
  case "keys":
16088
16101
  case "values":
16089
16102
  case "entries":
16090
- return createSandboxCollectionIterator(target, methodName);
16103
+ return createSandboxCollectionIterator(target, methodName, options.budget);
16091
16104
  }
16092
16105
  }
16093
16106
 
@@ -16188,7 +16201,7 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
16188
16201
  case "keys":
16189
16202
  case "values":
16190
16203
  case "entries":
16191
- return createSandboxCollectionIterator(target, methodName);
16204
+ return createSandboxCollectionIterator(target, methodName, options.budget);
16192
16205
  }
16193
16206
  }
16194
16207
 
@@ -18667,7 +18680,7 @@ function getPropertyValue(target, property, context, receiver = target) {
18667
18680
  const descriptor = getSandboxPropertyDescriptor(target, property, context.budget);
18668
18681
  if (descriptor !== void 0)
18669
18682
  return readPropertyDescriptor(descriptor, receiver, createCoercionContext(context), true);
18670
- if (isSandboxRegExpIterator(target)) return getRegExpIteratorMember(property, context.budget);
18683
+ if (isSandboxRegExpIterator(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getRegExpIteratorMember(property, context.budget);
18671
18684
  if (typeof target === "symbol" || typeof target === "bigint") {
18672
18685
  const prototype = getBoxedPrototype(target, context.budget);
18673
18686
  return prototype === void 0 ? void 0 : getPropertyValue(prototype, property, context, receiver);
@@ -18689,7 +18702,7 @@ function getPropertyValue(target, property, context, receiver = target) {
18689
18702
  if (isSandboxMap(target)) return getSandboxPrototype(target, context.budget) === null ? getMapMember(target, property, createMapMethodOptions(context)) : void 0;
18690
18703
  if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
18691
18704
  if (isSandboxCollectionIterator(target))
18692
- return getCollectionIteratorMember(target, property, context.budget);
18705
+ return hasExplicitSandboxPrototype(target) ? void 0 : getCollectionIteratorMember(target, property, context.budget);
18693
18706
  if (isSandboxGenerator(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getGeneratorMember(target, property, context.budget);
18694
18707
  if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
18695
18708
  if (isSandboxPromise(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getPromiseMember(property, context.budget);
@@ -22023,6 +22036,29 @@ function captureGuestHeapNode(value, encode) {
22023
22036
  const cursor = stringIteratorState(value);
22024
22037
  return { kind: "string-iterator", input: encode(cursor.input), index: cursor.index, state: captureObjectState(value, encode) };
22025
22038
  }
22039
+ if (isSandboxCollectionIterator(value) && hasGuestObjectState(value)) {
22040
+ const cursor = snapshotCollectionIterator(value);
22041
+ return {
22042
+ kind: "guest-collection-iterator",
22043
+ collectionKind: cursor.collectionKind,
22044
+ method: cursor.method,
22045
+ collection: encode(cursor.collection),
22046
+ index: cursor.index,
22047
+ exhausted: cursor.exhausted,
22048
+ state: captureObjectState(value, encode)
22049
+ };
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
+ }
22026
22062
  if (isRawJson(value)) return { kind: "raw-json", text: value.rawJSON };
22027
22063
  const intrinsic = getIntrinsicIdentity(value);
22028
22064
  if (intrinsic !== void 0) {
@@ -25208,6 +25244,34 @@ function installCollectionPrototypes(budget, mapConstructor, setConstructor) {
25208
25244
  for (const method of /* @__PURE__ */ new Set([...Object.values(methods2), size, species])) registerIntrinsicFunction(budget, method);
25209
25245
  }
25210
25246
  }
25247
+ function installCollectionIteratorPrototypes(budget) {
25248
+ for (const name of ["Map", "Set"]) {
25249
+ const iteratorPrototype = /* @__PURE__ */ Object.create(null);
25250
+ const kind = name === "Map" ? "map" : "set";
25251
+ const next = createSandboxClosure({
25252
+ guest: true,
25253
+ sandbox: true,
25254
+ name: "next",
25255
+ length: 0,
25256
+ call: (_args, context) => {
25257
+ const receiver = context?.thisValue;
25258
+ if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== kind)
25259
+ throw new TypeError("Iterator next requires a matching collection iterator receiver.");
25260
+ return nextCollectionIterator(receiver, budget);
25261
+ }
25262
+ });
25263
+ setSandboxPrototype(iteratorPrototype, resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]'));
25264
+ Object.defineProperties(iteratorPrototype, {
25265
+ next: { value: next, writable: true, configurable: true },
25266
+ [Symbol.toStringTag]: { value: `${name} Iterator`, configurable: true }
25267
+ });
25268
+ const installed = collectionIteratorPrototypes.get(budget) ?? {};
25269
+ installed[kind] = iteratorPrototype;
25270
+ collectionIteratorPrototypes.set(budget, installed);
25271
+ registerBuiltinIdentities(budget, { [`%${name}IteratorPrototype%`]: iteratorPrototype });
25272
+ registerIntrinsicObject(budget, iteratorPrototype);
25273
+ }
25274
+ }
25211
25275
 
25212
25276
  // packages/safe-js/src/interp/globals/collections.ts
25213
25277
  var mapConstructors = /* @__PURE__ */ new WeakSet();
@@ -25716,6 +25780,17 @@ async function regexSplit(target, input, limit, constructor, budget, context) {
25716
25780
  }
25717
25781
 
25718
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
+ }
25719
25794
  function createRegexGlobals(options) {
25720
25795
  const invoke = (construct) => async (args, context) => {
25721
25796
  const selected = options.compileOwner ?? context?.compilation?.owner;
@@ -25917,7 +25992,7 @@ function createRegexGlobals(options) {
25917
25992
  exhausted: false,
25918
25993
  global: flags.includes("g"),
25919
25994
  unicode: flags.includes("u") || flags.includes("v")
25920
- });
25995
+ }, void 0, options.budget);
25921
25996
  } finally {
25922
25997
  release();
25923
25998
  }
@@ -26902,6 +26977,8 @@ function createBuiltinBindings(options) {
26902
26977
  ...createPromiseGlobals(options),
26903
26978
  ...createRegexGlobals(options)
26904
26979
  };
26980
+ installCollectionIteratorPrototypes(options.budget);
26981
+ installRegExpIteratorPrototype(options.budget);
26905
26982
  createFunctionPrototype(options.budget, options.functionHasInstance);
26906
26983
  if (options.typedArrayPrototypes !== false) createNumericTypedArrayPrototypes(options.budget, bindings);
26907
26984
  if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
@@ -26969,7 +27046,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
26969
27046
  createRawJson(node.text);
26970
27047
  return true;
26971
27048
  }
26972
- if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "string-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;
26973
27050
  const reference = (value, kinds) => {
26974
27051
  const ref = record3(value);
26975
27052
  fields(ref, ["kind", "id"]);
@@ -27027,6 +27104,29 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27027
27104
  fields(node, ["kind", "id"], ["state"]);
27028
27105
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
27029
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);
27121
+ } else if (node.kind === "guest-collection-iterator") {
27122
+ fields(node, ["kind", "collectionKind", "method", "collection", "index", "exhausted", "state"]);
27123
+ if (!["map", "set"].includes(String(node.collectionKind)) || !["keys", "values", "entries"].includes(String(node.method)) || typeof node.exhausted !== "boolean")
27124
+ throw new TypeError("Invalid collection iterator state.");
27125
+ integer(node.index);
27126
+ if (absent(node.collection)) {
27127
+ if (!node.exhausted || node.index !== 0) throw new TypeError("Invalid exhausted collection iterator.");
27128
+ } else reference(node.collection, [String(node.collectionKind)]);
27129
+ state(node.state);
27030
27130
  } else if (node.kind === "string-iterator") {
27031
27131
  fields(node, ["kind", "input", "index", "state"]);
27032
27132
  const index = integer(node.index);
@@ -29035,6 +29135,7 @@ function measureSandboxData(values, options = {}) {
29035
29135
  for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
29036
29136
  usage += key.length + 1;
29037
29137
  if ("value" in descriptor) visit(descriptor.value, depth + 1);
29138
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
29038
29139
  }
29039
29140
  return;
29040
29141
  }
@@ -29043,6 +29144,7 @@ function measureSandboxData(values, options = {}) {
29043
29144
  for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
29044
29145
  usage += key.length + 1;
29045
29146
  if ("value" in descriptor) visit(descriptor.value, depth + 1);
29147
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
29046
29148
  }
29047
29149
  return;
29048
29150
  }
@@ -29230,8 +29332,8 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
29230
29332
  throw new TypeError("Array iterators require a portable guest snapshot, not a data copy.");
29231
29333
  }
29232
29334
  if (isSandboxRegExpIterator(value)) {
29233
- if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29234
29335
  if (!cloneSandboxCollections) return value;
29336
+ if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29235
29337
  const existing = state.seen.get(value);
29236
29338
  if (existing !== void 0) return existing;
29237
29339
  const snapshot = regexpIteratorState(value);
@@ -29246,8 +29348,8 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
29246
29348
  return copy;
29247
29349
  }
29248
29350
  if (isSandboxCollectionIterator(value)) {
29249
- if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29250
29351
  if (!cloneSandboxCollections) return value;
29352
+ if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29251
29353
  const existing = state.seen.get(value);
29252
29354
  if (existing !== void 0) return existing;
29253
29355
  const snapshot = snapshotCollectionIterator(value);
@@ -44091,4 +44193,4 @@ export {
44091
44193
  FileSnapshotBackend,
44092
44194
  run
44093
44195
  };
44094
- //# sourceMappingURL=chunk-N3C4UP54.js.map
44196
+ //# sourceMappingURL=chunk-XJL73BPS.js.map