@poe-platform/safe-js 0.1.388 → 0.1.389

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.
@@ -26409,6 +26409,103 @@ function installIteratorFrom(constructor, budget) {
26409
26409
  }
26410
26410
  }
26411
26411
 
26412
+ // packages/safe-js/src/interp/globals/iterator-consumers.ts
26413
+ function installIteratorConsumers(prototype, budget) {
26414
+ for (const name of ["toArray", "reduce", "forEach", "some", "every", "find"]) {
26415
+ Object.defineProperty(prototype, name, { writable: true, configurable: true, value: createSandboxClosure({
26416
+ guest: true,
26417
+ sandbox: true,
26418
+ name,
26419
+ length: name === "toArray" ? 0 : 1,
26420
+ call: async (args, context) => {
26421
+ const receiver = context?.thisValue;
26422
+ if (receiver === null || typeof receiver !== "object") throw new TypeError("Iterator consumer requires an object.");
26423
+ const callback = args[0];
26424
+ let next;
26425
+ let accumulator = args[1];
26426
+ let value;
26427
+ const values = [];
26428
+ const release = retainValues(budget, () => [receiver, callback, next, accumulator, value, values]);
26429
+ const checkpoint = createDataCheckpoint(budget, context);
26430
+ const iterator = {
26431
+ asynchronous: true,
26432
+ next: async () => {
26433
+ if (!isSandboxClosure(next)) throw new TypeError("Iterator next must be callable.");
26434
+ const result = await invokeBuiltinClosure(next, [], budget, context, receiver);
26435
+ if (result === null || typeof result !== "object") throw new TypeError("Iterator result must be an object.");
26436
+ return result;
26437
+ },
26438
+ getOperation: async () => {
26439
+ const method = await read(receiver, "return", context);
26440
+ if (method === void 0 || method === null) return void 0;
26441
+ if (!isSandboxClosure(method)) throw new TypeError("Iterator return must be callable.");
26442
+ return async () => await invokeBuiltinClosure(method, [], budget, context, receiver);
26443
+ }
26444
+ };
26445
+ try {
26446
+ if (name !== "toArray" && !isSandboxClosure(callback)) {
26447
+ await closeIterator(iterator, true);
26448
+ throw new TypeError("Iterator callback must be callable.");
26449
+ }
26450
+ next = await read(receiver, "next", context);
26451
+ let initialized = name !== "reduce" || args.length > 1;
26452
+ let index = 0;
26453
+ while (true) {
26454
+ budget.visitNode();
26455
+ const result = await iterator.next();
26456
+ if (await read(result, "done", context)) {
26457
+ if (!initialized) throw new TypeError("Cannot reduce an empty iterator without an initial value.");
26458
+ if (name === "toArray") return values;
26459
+ if (name === "reduce") return accumulator;
26460
+ if (name === "some") return false;
26461
+ if (name === "every") return true;
26462
+ return void 0;
26463
+ }
26464
+ value = await read(result, "value", context);
26465
+ if (name === "toArray") {
26466
+ values.push(value);
26467
+ checkpoint(values, 0, true);
26468
+ } else if (!initialized) {
26469
+ accumulator = value;
26470
+ initialized = true;
26471
+ } else {
26472
+ let selected;
26473
+ try {
26474
+ selected = await invokeBuiltinClosure(
26475
+ callback,
26476
+ name === "reduce" ? [accumulator, value, index] : [value, index],
26477
+ budget,
26478
+ context,
26479
+ void 0
26480
+ );
26481
+ } catch (error) {
26482
+ if (!isFatalSandboxError(error)) await closeIterator(iterator, true);
26483
+ throw error;
26484
+ }
26485
+ if (name === "reduce") accumulator = selected;
26486
+ else if ((name === "some" || name === "find") && selected || name === "every" && !selected) {
26487
+ await closeIterator(iterator);
26488
+ return name === "find" ? value : name === "some";
26489
+ }
26490
+ }
26491
+ value = void 0;
26492
+ index++;
26493
+ }
26494
+ } finally {
26495
+ release();
26496
+ }
26497
+ }
26498
+ }) });
26499
+ }
26500
+ registerBuiltinIdentities(budget, { "%IteratorPrototype%": prototype });
26501
+ registerIntrinsicObject(budget, prototype);
26502
+ async function read(value, key, context) {
26503
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
26504
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
26505
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
26506
+ }
26507
+ }
26508
+
26412
26509
  // packages/safe-js/src/interp/globals/iterator.ts
26413
26510
  function createIteratorGlobal(budget) {
26414
26511
  const prototype = resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]');
@@ -26447,6 +26544,7 @@ function createIteratorGlobal(budget) {
26447
26544
  registerIntrinsicFunction(budget, getter);
26448
26545
  registerIntrinsicFunction(budget, setter);
26449
26546
  installIteratorFrom(constructor, budget);
26547
+ installIteratorConsumers(prototype, budget);
26450
26548
  registerIntrinsicFunction(budget, constructor);
26451
26549
  registerIntrinsicObject(budget, prototype);
26452
26550
  return constructor;
@@ -44310,4 +44408,4 @@ export {
44310
44408
  FileSnapshotBackend,
44311
44409
  run
44312
44410
  };
44313
- //# sourceMappingURL=chunk-VQ4F2UCI.js.map
44411
+ //# sourceMappingURL=chunk-6Y27XODE.js.map