@poe-platform/safe-js 0.1.386 → 0.1.388

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-XJL73BPS.js";
30
+ } from "./chunk-VQ4F2UCI.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-IZEDCQDW.js.map
8252
+ //# sourceMappingURL=chunk-RLZ6CCXJ.js.map
@@ -8546,6 +8546,9 @@ function nextStringIterator(value, budget) {
8546
8546
  return { value: entry, done: false };
8547
8547
  }
8548
8548
 
8549
+ // packages/safe-js/src/interp/iterator-wrapper.ts
8550
+ var iteratorWrapperStates = /* @__PURE__ */ new WeakMap();
8551
+
8549
8552
  // packages/safe-js/src/interp/raw-json.ts
8550
8553
  var rawJsonValues = /* @__PURE__ */ new WeakSet();
8551
8554
  function createRawJson(text) {
@@ -22030,6 +22033,9 @@ function serializeCollectionProperties(value, encode, dataOnly = false) {
22030
22033
 
22031
22034
  // packages/safe-js/src/snapshot/guest-heap.ts
22032
22035
  function captureGuestHeapNode(value, encode) {
22036
+ const wrapper = iteratorWrapperStates.get(value);
22037
+ if (wrapper !== void 0)
22038
+ return { kind: "iterator-wrapper", iterator: encode(wrapper.iterator), next: encode(wrapper.next), state: captureObjectState(value, encode) };
22033
22039
  if (isSandboxModuleNamespace(value))
22034
22040
  return { kind: "module-namespace", entries: Object.keys(value).map((key) => [key, encode(value[key])]) };
22035
22041
  if (isSandboxStringIterator(value)) {
@@ -26347,6 +26353,105 @@ function createGeneratorPrototypes(budget) {
26347
26353
  generatorPrototypes.set(budget, state);
26348
26354
  }
26349
26355
 
26356
+ // packages/safe-js/src/interp/globals/iterator-from.ts
26357
+ function installIteratorFrom(constructor, budget) {
26358
+ const prototype = /* @__PURE__ */ Object.create(null);
26359
+ setSandboxPrototype(prototype, resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]'));
26360
+ for (const name of ["next", "return"]) {
26361
+ Object.defineProperty(prototype, name, { writable: true, configurable: true, value: createSandboxClosure({
26362
+ guest: true,
26363
+ sandbox: true,
26364
+ name,
26365
+ length: 0,
26366
+ call: async (_args, context) => {
26367
+ const receiver = context?.thisValue;
26368
+ const state = receiver !== null && typeof receiver === "object" ? iteratorWrapperStates.get(receiver) : void 0;
26369
+ if (state === void 0) throw new TypeError("Iterator wrapper method requires a branded receiver.");
26370
+ const method = name === "next" ? state.next : await read(state.iterator, "return", context);
26371
+ if (name === "return" && (method === void 0 || method === null)) return { value: void 0, done: true };
26372
+ if (!isSandboxClosure(method)) throw new TypeError("Iterator method must be callable.");
26373
+ return invokeBuiltinClosure(method, [], budget, context, state.iterator);
26374
+ }
26375
+ }) });
26376
+ }
26377
+ const from = createSandboxClosure({ guest: true, sandbox: true, name: "from", length: 1, call: async ([input], context) => {
26378
+ if (input === null || typeof input !== "object" && typeof input !== "string")
26379
+ throw new TypeError("Iterator.from requires an object or string.");
26380
+ let iterator = input;
26381
+ let next;
26382
+ const release = retainValues(budget, () => [input, iterator, next]);
26383
+ try {
26384
+ const method = await read(input, Symbol.iterator, context);
26385
+ if (method !== void 0 && method !== null) {
26386
+ if (!isSandboxClosure(method)) throw new TypeError("Symbol.iterator must be callable.");
26387
+ iterator = await invokeBuiltinClosure(method, [], budget, context, input);
26388
+ }
26389
+ if (iterator === null || typeof iterator !== "object") throw new TypeError("Iterator must be an object.");
26390
+ next = await read(iterator, "next", context);
26391
+ if (await ordinaryHasInstance(iterator, constructor, budget, context)) return iterator;
26392
+ const wrapper = /* @__PURE__ */ Object.create(null);
26393
+ iteratorWrapperStates.set(wrapper, { iterator, next });
26394
+ setSandboxPrototype(wrapper, prototype, budget);
26395
+ createDataCheckpoint(budget, context)(wrapper, 0, true);
26396
+ return wrapper;
26397
+ } finally {
26398
+ release();
26399
+ }
26400
+ } });
26401
+ Object.defineProperty(materializeFunctionProperties(constructor), "from", { value: from, writable: true, configurable: true });
26402
+ registerBuiltinIdentities(budget, { Iterator: constructor, "%WrapForValidIteratorPrototype%": prototype });
26403
+ registerIntrinsicFunction(budget, from);
26404
+ registerIntrinsicObject(budget, prototype);
26405
+ async function read(value, key, context) {
26406
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
26407
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
26408
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
26409
+ }
26410
+ }
26411
+
26412
+ // packages/safe-js/src/interp/globals/iterator.ts
26413
+ function createIteratorGlobal(budget) {
26414
+ const prototype = resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]');
26415
+ const constructor = createSandboxClosure({
26416
+ guest: true,
26417
+ sandbox: true,
26418
+ name: "Iterator",
26419
+ length: 0,
26420
+ call: () => {
26421
+ throw new TypeError("Iterator is an abstract constructor.");
26422
+ },
26423
+ construct: async (_args, context) => {
26424
+ const target = context?.newTarget;
26425
+ if (target === void 0 || target === constructor)
26426
+ throw new TypeError("Iterator is an abstract constructor.");
26427
+ const parent = context?.getProperty !== void 0 ? await context.getProperty(target, "prototype") : await readPropertyDescriptor(getSandboxPropertyDescriptor(target, "prototype", budget) ?? { value: void 0 }, target, context);
26428
+ const instance = /* @__PURE__ */ Object.create(null);
26429
+ setSandboxPrototype(instance, parent !== null && typeof parent === "object" ? parent : prototype, budget);
26430
+ createDataCheckpoint(budget, context)(instance, 0, true);
26431
+ return instance;
26432
+ }
26433
+ });
26434
+ Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
26435
+ const getter = createSandboxClosure({ guest: true, sandbox: true, name: "get constructor", length: 0, call: () => constructor });
26436
+ const setter = createSandboxClosure({ guest: true, sandbox: true, name: "set constructor", length: 1, call: async ([value], context) => {
26437
+ const receiver = context?.thisValue;
26438
+ if (receiver === prototype || receiver === null || typeof receiver !== "object")
26439
+ throw new TypeError("Iterator constructor setter requires a distinct object receiver.");
26440
+ const properties = objectProperties(receiver, true);
26441
+ if (Object.hasOwn(properties, "constructor")) await setSandboxProperty(receiver, "constructor", value, budget, true, context);
26442
+ else defineOwnDataProperty(properties, "constructor", value);
26443
+ createDataCheckpoint(budget, context)(receiver, 0, true);
26444
+ return void 0;
26445
+ } });
26446
+ Object.defineProperty(prototype, "constructor", { get: accessorAdapter(getter, "get"), set: accessorAdapter(setter, "set"), configurable: true });
26447
+ registerIntrinsicFunction(budget, getter);
26448
+ registerIntrinsicFunction(budget, setter);
26449
+ installIteratorFrom(constructor, budget);
26450
+ registerIntrinsicFunction(budget, constructor);
26451
+ registerIntrinsicObject(budget, prototype);
26452
+ return constructor;
26453
+ }
26454
+
26350
26455
  // packages/safe-js/src/interp/globals/symbol.ts
26351
26456
  var registries = /* @__PURE__ */ new WeakMap();
26352
26457
  function createSymbolGlobal(budget) {
@@ -26969,6 +27074,7 @@ function createBuiltinBindings(options) {
26969
27074
  ...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
26970
27075
  ...createMathGlobals({ random: options.random, budget: options.budget }),
26971
27076
  ...createObjectArrayGlobals(options),
27077
+ Iterator: createIteratorGlobal(options.budget),
26972
27078
  Reflect: createReflectGlobal(options.budget),
26973
27079
  ArrayBuffer: createArrayBufferGlobal(options.budget),
26974
27080
  DataView: createDataViewGlobal(options.budget),
@@ -27046,7 +27152,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27046
27152
  createRawJson(node.text);
27047
27153
  return true;
27048
27154
  }
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;
27155
+ if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "string-iterator", "iterator-wrapper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
27050
27156
  const reference = (value, kinds) => {
27051
27157
  const ref = record3(value);
27052
27158
  fields(ref, ["kind", "id"]);
@@ -27100,7 +27206,12 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
27100
27206
  });
27101
27207
  return false;
27102
27208
  }
27103
- if (node.kind === "intrinsic") {
27209
+ if (node.kind === "iterator-wrapper") {
27210
+ fields(node, ["kind", "iterator", "next", "state"]);
27211
+ const iterator = reference(node.iterator);
27212
+ if (iterator.kind === "symbol" || iterator.kind === "scope-frame") throw new TypeError("Invalid wrapped iterator.");
27213
+ state(node.state);
27214
+ } else if (node.kind === "intrinsic") {
27104
27215
  fields(node, ["kind", "id"], ["state"]);
27105
27216
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
27106
27217
  if (Object.hasOwn(node, "state")) state(node.state);
@@ -29065,6 +29176,11 @@ function measureSandboxData(values, options = {}) {
29065
29176
  }
29066
29177
  return;
29067
29178
  }
29179
+ const wrapperState = iteratorWrapperStates.get(value);
29180
+ if (wrapperState !== void 0) {
29181
+ visit(wrapperState.iterator, depth + 1);
29182
+ visit(wrapperState.next, depth + 1);
29183
+ }
29068
29184
  if (isSandboxDate(value)) usage += 8;
29069
29185
  if (isGuestHostObject(value)) {
29070
29186
  usage += measureHostObjectData(value);
@@ -31691,6 +31807,7 @@ var KNOWN_RUNTIME_GLOBALS = [
31691
31807
  "Infinity",
31692
31808
  "isFinite",
31693
31809
  "isNaN",
31810
+ "Iterator",
31694
31811
  "JSON",
31695
31812
  "Map",
31696
31813
  ...Object.keys(numericTypedArrayConstructors),
@@ -44193,4 +44310,4 @@ export {
44193
44310
  FileSnapshotBackend,
44194
44311
  run
44195
44312
  };
44196
- //# sourceMappingURL=chunk-XJL73BPS.js.map
44313
+ //# sourceMappingURL=chunk-VQ4F2UCI.js.map