@poe-platform/safe-js 0.1.107 → 0.1.109

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-SLQJGSFH.js";
30
+ } from "./chunk-OCJ6MUNL.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8245,4 +8245,4 @@ export {
8245
8245
  parseMcpConfig,
8246
8246
  makeMcpModule
8247
8247
  };
8248
- //# sourceMappingURL=chunk-INJEHRIX.js.map
8248
+ //# sourceMappingURL=chunk-FPFTLLMZ.js.map
@@ -25385,7 +25385,28 @@ function createCollectionGlobals(options) {
25385
25385
  call: () => {
25386
25386
  throw new TypeError("Constructor Map requires 'new'.");
25387
25387
  },
25388
- construct: ([source], context) => constructMap(source, options.budget, context),
25388
+ construct: ([source], context) => {
25389
+ const map = createSandboxMap([]);
25390
+ let key;
25391
+ let value;
25392
+ return populateCollection(source, map, {
25393
+ name: "Map",
25394
+ budget: options.budget,
25395
+ context,
25396
+ retainedValues: () => [key, value],
25397
+ append: (entry) => {
25398
+ if (typeof entry !== "object" || entry === null) throw new TypeError("Map constructor requires entry objects.");
25399
+ key = context?.getProperty !== void 0 ? context.getProperty(entry, 0) : getSandboxDataProperty(entry, 0, options.budget);
25400
+ value = context?.getProperty !== void 0 ? context.getProperty(entry, 1) : getSandboxDataProperty(entry, 1, options.budget);
25401
+ const added = map.entries.has(key) ? 0 : 1;
25402
+ const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([key, value]));
25403
+ options.budget.allocateCollectionEntries(map.entries.size + added);
25404
+ map.entries.set(key, value);
25405
+ key = value = void 0;
25406
+ return growth;
25407
+ }
25408
+ });
25409
+ },
25389
25410
  name: "Map"
25390
25411
  });
25391
25412
  const setConstructor = createSandboxClosure({
@@ -25393,12 +25414,20 @@ function createCollectionGlobals(options) {
25393
25414
  call: () => {
25394
25415
  throw new TypeError("Constructor Set requires 'new'.");
25395
25416
  },
25396
- construct: ([source]) => {
25397
- const values = getSetValues(source);
25398
- if (values instanceof Promise) {
25399
- return values.then((resolved) => createBudgetedSet(resolved, options.budget));
25400
- }
25401
- return createBudgetedSet(values, options.budget);
25417
+ construct: ([source], context) => {
25418
+ const set = createSandboxSet([]);
25419
+ return populateCollection(source, set, {
25420
+ name: "Set",
25421
+ budget: options.budget,
25422
+ context,
25423
+ append: (value) => {
25424
+ const added = set.values.has(value) ? 0 : 1;
25425
+ const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([value]));
25426
+ options.budget.allocateCollectionEntries(set.values.size + added);
25427
+ set.values.add(value);
25428
+ return growth;
25429
+ }
25430
+ });
25402
25431
  },
25403
25432
  name: "Set"
25404
25433
  });
@@ -25412,18 +25441,15 @@ function isSandboxMapConstructor(value) {
25412
25441
  function isSandboxSetConstructor(value) {
25413
25442
  return typeof value === "object" && value !== null && setConstructors.has(value);
25414
25443
  }
25415
- function constructMap(source, budget, context) {
25416
- const map = createSandboxMap([]);
25444
+ function populateCollection(source, collection, { name, budget, context, append, retainedValues }) {
25417
25445
  budget.allocateCollectionEntries(0);
25418
- if (source === void 0 || source === null) return map;
25446
+ if (source === void 0 || source === null) return collection;
25419
25447
  const iterator = getSandboxIterator(source);
25420
- if (iterator === void 0) throw new TypeError("Map constructor requires an iterable.");
25448
+ if (iterator === void 0) throw new TypeError(`${name} constructor requires an iterable.`);
25421
25449
  let entry;
25422
- let key;
25423
- let value;
25424
25450
  let failure;
25425
25451
  const retained = {};
25426
- budget.setRetainedValues(retained, () => [source, map, entry, key, value, failure]);
25452
+ budget.setRetainedValues(retained, () => [source, collection, entry, failure, ...retainedValues?.() ?? []]);
25427
25453
  const checkData = createDataCheckpoint(budget, context);
25428
25454
  const closeOnThrow = (error) => {
25429
25455
  failure = isCapturedException(error) ? error.reason : error;
@@ -25447,15 +25473,9 @@ function constructMap(source, budget, context) {
25447
25473
  entry = result.value;
25448
25474
  try {
25449
25475
  budget.visitNode();
25450
- if (typeof entry !== "object" || entry === null) throw new TypeError("Map constructor requires entry objects.");
25451
- key = context?.getProperty !== void 0 ? context.getProperty(entry, 0) : getSandboxDataProperty(entry, 0, budget);
25452
- value = context?.getProperty !== void 0 ? context.getProperty(entry, 1) : getSandboxDataProperty(entry, 1, budget);
25453
- const added = map.entries.has(key) ? 0 : 1;
25454
- const growth = added + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([key, value]));
25455
- budget.allocateCollectionEntries(map.entries.size + added);
25456
- map.entries.set(key, value);
25457
- entry = key = value = void 0;
25458
- checkData(map, growth);
25476
+ const growth = append(entry);
25477
+ entry = void 0;
25478
+ checkData(collection, growth);
25459
25479
  } catch (error) {
25460
25480
  return closeOnThrow(error);
25461
25481
  }
@@ -25464,54 +25484,26 @@ function constructMap(source, budget, context) {
25464
25484
  if (iterator.generator) {
25465
25485
  return (async () => {
25466
25486
  try {
25467
- checkData(map, 0, true);
25487
+ checkData(collection, 0, true);
25468
25488
  while (!await consume(await iterator.next())) {
25469
25489
  }
25470
- checkData(map, 0, true);
25471
- return map;
25490
+ checkData(collection, 0, true);
25491
+ return collection;
25472
25492
  } finally {
25473
25493
  budget.setRetainedValues(retained, void 0);
25474
25494
  }
25475
25495
  })();
25476
25496
  }
25477
25497
  try {
25478
- checkData(map, 0, true);
25498
+ checkData(collection, 0, true);
25479
25499
  while (!consume(iterator.next())) {
25480
25500
  }
25481
- checkData(map, 0, true);
25482
- return map;
25501
+ checkData(collection, 0, true);
25502
+ return collection;
25483
25503
  } finally {
25484
25504
  budget.setRetainedValues(retained, void 0);
25485
25505
  }
25486
25506
  }
25487
- function getSetValues(source) {
25488
- if (source === void 0 || source === null) {
25489
- return [];
25490
- }
25491
- if (isSandboxSet(source)) {
25492
- return [...source.values];
25493
- }
25494
- if (typeof source === "string") return [...source];
25495
- if (Array.isArray(source)) return [...source];
25496
- const iterator = getSandboxIterator(source);
25497
- if (iterator?.generator === true) {
25498
- return collectSetValues(iterator);
25499
- }
25500
- throw new TypeError("Set constructor argument must be an array, string, or Set.");
25501
- }
25502
- async function collectSetValues(iterator) {
25503
- const values = [];
25504
- while (true) {
25505
- const result = await iterator.next();
25506
- if (result.done) break;
25507
- values.push(result.value);
25508
- }
25509
- return values;
25510
- }
25511
- function createBudgetedSet(values, budget) {
25512
- budget.allocateCollectionEntries(new Set(values).size);
25513
- return createSandboxSet(values);
25514
- }
25515
25507
 
25516
25508
  // packages/safe-js/src/interp/globals/float32array.ts
25517
25509
  var constructors = /* @__PURE__ */ new WeakSet();
@@ -33053,4 +33045,4 @@ export {
33053
33045
  FileSnapshotBackend,
33054
33046
  run
33055
33047
  };
33056
- //# sourceMappingURL=chunk-SLQJGSFH.js.map
33048
+ //# sourceMappingURL=chunk-OCJ6MUNL.js.map