@poe-platform/safe-js 0.1.383 → 0.1.385

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.
@@ -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;
@@ -9787,7 +9791,7 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9787
9791
  if (!hasExplicitSandboxPrototype(value) && value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
9788
9792
  return guestIterator(value, await context.getProperty(value, "next"), asyncProtocol, budget, context, signal);
9789
9793
  }
9790
- if (!asyncProtocol && Array.isArray(value) && getSandboxPrototype(value, budget) !== null) return void 0;
9794
+ 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
9795
  if (!asyncProtocol) return getSandboxIterator(value, budget, context);
9792
9796
  if (isSandboxGenerator(value) && value.async && !hasExplicitSandboxPrototype(value))
9793
9797
  return getSandboxAsyncIterator(value, budget, context, signal);
@@ -9981,6 +9985,8 @@ function getSandboxIterator(value, budget, context) {
9981
9985
  }
9982
9986
  };
9983
9987
  }
9988
+ if (isSandboxCollectionIterator(value) && hasExplicitSandboxPrototype(value))
9989
+ return context?.getProperty === void 0 ? guestProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
9984
9990
  if (isSandboxCollectionIterator(value))
9985
9991
  return {
9986
9992
  next: () => nextCollectionIterator(value, budget),
@@ -16087,7 +16093,7 @@ async function callMapMethod(target, methodName, args, options, stack = []) {
16087
16093
  case "keys":
16088
16094
  case "values":
16089
16095
  case "entries":
16090
- return createSandboxCollectionIterator(target, methodName);
16096
+ return createSandboxCollectionIterator(target, methodName, options.budget);
16091
16097
  }
16092
16098
  }
16093
16099
 
@@ -16188,7 +16194,7 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
16188
16194
  case "keys":
16189
16195
  case "values":
16190
16196
  case "entries":
16191
- return createSandboxCollectionIterator(target, methodName);
16197
+ return createSandboxCollectionIterator(target, methodName, options.budget);
16192
16198
  }
16193
16199
  }
16194
16200
 
@@ -18689,7 +18695,7 @@ function getPropertyValue(target, property, context, receiver = target) {
18689
18695
  if (isSandboxMap(target)) return getSandboxPrototype(target, context.budget) === null ? getMapMember(target, property, createMapMethodOptions(context)) : void 0;
18690
18696
  if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
18691
18697
  if (isSandboxCollectionIterator(target))
18692
- return getCollectionIteratorMember(target, property, context.budget);
18698
+ return hasExplicitSandboxPrototype(target) ? void 0 : getCollectionIteratorMember(target, property, context.budget);
18693
18699
  if (isSandboxGenerator(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getGeneratorMember(target, property, context.budget);
18694
18700
  if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
18695
18701
  if (isSandboxPromise(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getPromiseMember(property, context.budget);
@@ -22023,6 +22029,18 @@ function captureGuestHeapNode(value, encode) {
22023
22029
  const cursor = stringIteratorState(value);
22024
22030
  return { kind: "string-iterator", input: encode(cursor.input), index: cursor.index, state: captureObjectState(value, encode) };
22025
22031
  }
22032
+ if (isSandboxCollectionIterator(value) && hasGuestObjectState(value)) {
22033
+ const cursor = snapshotCollectionIterator(value);
22034
+ return {
22035
+ kind: "guest-collection-iterator",
22036
+ collectionKind: cursor.collectionKind,
22037
+ method: cursor.method,
22038
+ collection: encode(cursor.collection),
22039
+ index: cursor.index,
22040
+ exhausted: cursor.exhausted,
22041
+ state: captureObjectState(value, encode)
22042
+ };
22043
+ }
22026
22044
  if (isRawJson(value)) return { kind: "raw-json", text: value.rawJSON };
22027
22045
  const intrinsic = getIntrinsicIdentity(value);
22028
22046
  if (intrinsic !== void 0) {
@@ -25208,6 +25226,34 @@ function installCollectionPrototypes(budget, mapConstructor, setConstructor) {
25208
25226
  for (const method of /* @__PURE__ */ new Set([...Object.values(methods2), size, species])) registerIntrinsicFunction(budget, method);
25209
25227
  }
25210
25228
  }
25229
+ function installCollectionIteratorPrototypes(budget) {
25230
+ for (const name of ["Map", "Set"]) {
25231
+ const iteratorPrototype = /* @__PURE__ */ Object.create(null);
25232
+ const kind = name === "Map" ? "map" : "set";
25233
+ const next = createSandboxClosure({
25234
+ guest: true,
25235
+ sandbox: true,
25236
+ name: "next",
25237
+ length: 0,
25238
+ call: (_args, context) => {
25239
+ const receiver = context?.thisValue;
25240
+ if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== kind)
25241
+ throw new TypeError("Iterator next requires a matching collection iterator receiver.");
25242
+ return nextCollectionIterator(receiver, budget);
25243
+ }
25244
+ });
25245
+ setSandboxPrototype(iteratorPrototype, resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]'));
25246
+ Object.defineProperties(iteratorPrototype, {
25247
+ next: { value: next, writable: true, configurable: true },
25248
+ [Symbol.toStringTag]: { value: `${name} Iterator`, configurable: true }
25249
+ });
25250
+ const installed = collectionIteratorPrototypes.get(budget) ?? {};
25251
+ installed[kind] = iteratorPrototype;
25252
+ collectionIteratorPrototypes.set(budget, installed);
25253
+ registerBuiltinIdentities(budget, { [`%${name}IteratorPrototype%`]: iteratorPrototype });
25254
+ registerIntrinsicObject(budget, iteratorPrototype);
25255
+ }
25256
+ }
25211
25257
 
25212
25258
  // packages/safe-js/src/interp/globals/collections.ts
25213
25259
  var mapConstructors = /* @__PURE__ */ new WeakSet();
@@ -26902,6 +26948,7 @@ function createBuiltinBindings(options) {
26902
26948
  ...createPromiseGlobals(options),
26903
26949
  ...createRegexGlobals(options)
26904
26950
  };
26951
+ installCollectionIteratorPrototypes(options.budget);
26905
26952
  createFunctionPrototype(options.budget, options.functionHasInstance);
26906
26953
  if (options.typedArrayPrototypes !== false) createNumericTypedArrayPrototypes(options.budget, bindings);
26907
26954
  if (options.errorPrototypes !== false) createErrorPrototypes(options.budget, bindings);
@@ -26969,7 +27016,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
26969
27016
  createRawJson(node.text);
26970
27017
  return true;
26971
27018
  }
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;
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;
26973
27020
  const reference = (value, kinds) => {
26974
27021
  const ref = record3(value);
26975
27022
  fields(ref, ["kind", "id"]);
@@ -27027,6 +27074,15 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27027
27074
  fields(node, ["kind", "id"], ["state"]);
27028
27075
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
27029
27076
  if (Object.hasOwn(node, "state")) state(node.state);
27077
+ } else if (node.kind === "guest-collection-iterator") {
27078
+ fields(node, ["kind", "collectionKind", "method", "collection", "index", "exhausted", "state"]);
27079
+ if (!["map", "set"].includes(String(node.collectionKind)) || !["keys", "values", "entries"].includes(String(node.method)) || typeof node.exhausted !== "boolean")
27080
+ throw new TypeError("Invalid collection iterator state.");
27081
+ integer(node.index);
27082
+ if (absent(node.collection)) {
27083
+ if (!node.exhausted || node.index !== 0) throw new TypeError("Invalid exhausted collection iterator.");
27084
+ } else reference(node.collection, [String(node.collectionKind)]);
27085
+ state(node.state);
27030
27086
  } else if (node.kind === "string-iterator") {
27031
27087
  fields(node, ["kind", "input", "index", "state"]);
27032
27088
  const index = integer(node.index);
@@ -29043,6 +29099,7 @@ function measureSandboxData(values, options = {}) {
29043
29099
  for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
29044
29100
  usage += key.length + 1;
29045
29101
  if ("value" in descriptor) visit(descriptor.value, depth + 1);
29102
+ else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
29046
29103
  }
29047
29104
  return;
29048
29105
  }
@@ -29246,8 +29303,8 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
29246
29303
  return copy;
29247
29304
  }
29248
29305
  if (isSandboxCollectionIterator(value)) {
29249
- if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29250
29306
  if (!cloneSandboxCollections) return value;
29307
+ if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
29251
29308
  const existing = state.seen.get(value);
29252
29309
  if (existing !== void 0) return existing;
29253
29310
  const snapshot = snapshotCollectionIterator(value);
@@ -44091,4 +44148,4 @@ export {
44091
44148
  FileSnapshotBackend,
44092
44149
  run
44093
44150
  };
44094
- //# sourceMappingURL=chunk-XIEVJEAG.js.map
44151
+ //# sourceMappingURL=chunk-4M2UASWA.js.map