@poe-platform/safe-js 0.1.105 → 0.1.107

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-G5X7KIU3.js";
30
+ } from "./chunk-SLQJGSFH.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-B365DJ6C.js.map
8248
+ //# sourceMappingURL=chunk-INJEHRIX.js.map
@@ -25362,6 +25362,20 @@ function typeTag(value) {
25362
25362
  return "Object";
25363
25363
  }
25364
25364
 
25365
+ // packages/safe-js/src/interp/data-checkpoint.ts
25366
+ function createDataCheckpoint(budget, context) {
25367
+ let estimatedDataSize = 0;
25368
+ return (value, growth = 0, force = false) => {
25369
+ const limit = budget.limits.dataSize;
25370
+ if (limit === void 0) return;
25371
+ estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
25372
+ if (!force && estimatedDataSize <= limit) return;
25373
+ if (context?.reconcileData !== void 0) context.reconcileData(value);
25374
+ else reconcileCompiledValues(budget, [value], context?.compilation);
25375
+ estimatedDataSize = budget.currentDataSize;
25376
+ };
25377
+ }
25378
+
25365
25379
  // packages/safe-js/src/interp/globals/collections.ts
25366
25380
  var mapConstructors = /* @__PURE__ */ new WeakSet();
25367
25381
  var setConstructors = /* @__PURE__ */ new WeakSet();
@@ -25371,13 +25385,7 @@ function createCollectionGlobals(options) {
25371
25385
  call: () => {
25372
25386
  throw new TypeError("Constructor Map requires 'new'.");
25373
25387
  },
25374
- construct: ([source]) => {
25375
- const entries = getMapEntries(source);
25376
- if (entries instanceof Promise) {
25377
- return entries.then((resolved) => createBudgetedMap(resolved, options.budget));
25378
- }
25379
- return createBudgetedMap(entries, options.budget);
25380
- },
25388
+ construct: ([source], context) => constructMap(source, options.budget, context),
25381
25389
  name: "Map"
25382
25390
  });
25383
25391
  const setConstructor = createSandboxClosure({
@@ -25404,38 +25412,77 @@ function isSandboxMapConstructor(value) {
25404
25412
  function isSandboxSetConstructor(value) {
25405
25413
  return typeof value === "object" && value !== null && setConstructors.has(value);
25406
25414
  }
25407
- function getMapEntries(source) {
25408
- if (source === void 0 || source === null) {
25409
- return [];
25410
- }
25411
- if (isSandboxMap(source)) {
25412
- return [...source.entries];
25413
- }
25414
- if (Array.isArray(source)) {
25415
- return validateMapEntries(source);
25416
- }
25415
+ function constructMap(source, budget, context) {
25416
+ const map = createSandboxMap([]);
25417
+ budget.allocateCollectionEntries(0);
25418
+ if (source === void 0 || source === null) return map;
25417
25419
  const iterator = getSandboxIterator(source);
25418
- if (iterator?.generator !== true) {
25419
- throw new TypeError("Map constructor argument must be an array of pairs or a Map.");
25420
- }
25421
- return collectMapEntries(iterator);
25422
- }
25423
- async function collectMapEntries(iterator) {
25424
- const sourceEntries = [];
25425
- while (true) {
25426
- const result = await iterator.next();
25427
- if (result.done) break;
25428
- sourceEntries.push(result.value);
25420
+ if (iterator === void 0) throw new TypeError("Map constructor requires an iterable.");
25421
+ let entry;
25422
+ let key;
25423
+ let value;
25424
+ let failure;
25425
+ const retained = {};
25426
+ budget.setRetainedValues(retained, () => [source, map, entry, key, value, failure]);
25427
+ const checkData = createDataCheckpoint(budget, context);
25428
+ const closeOnThrow = (error) => {
25429
+ failure = isCapturedException(error) ? error.reason : error;
25430
+ const rethrow = (closeError) => {
25431
+ if (!isFatalSandboxError(error) && isFatalSandboxError(closeError)) throw closeError;
25432
+ throw error;
25433
+ };
25434
+ try {
25435
+ const closing = iterator.return?.();
25436
+ if (iterator.generator) return Promise.resolve(closing).then(() => {
25437
+ throw error;
25438
+ }, rethrow);
25439
+ } catch (closeError) {
25440
+ return rethrow(closeError);
25441
+ }
25442
+ throw error;
25443
+ };
25444
+ const consume = (result) => {
25445
+ if (typeof result !== "object" || result === null) throw new TypeError("Iterator result must be an object.");
25446
+ if (result.done) return true;
25447
+ entry = result.value;
25448
+ try {
25449
+ 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);
25459
+ } catch (error) {
25460
+ return closeOnThrow(error);
25461
+ }
25462
+ return false;
25463
+ };
25464
+ if (iterator.generator) {
25465
+ return (async () => {
25466
+ try {
25467
+ checkData(map, 0, true);
25468
+ while (!await consume(await iterator.next())) {
25469
+ }
25470
+ checkData(map, 0, true);
25471
+ return map;
25472
+ } finally {
25473
+ budget.setRetainedValues(retained, void 0);
25474
+ }
25475
+ })();
25429
25476
  }
25430
- return validateMapEntries(sourceEntries);
25431
- }
25432
- function validateMapEntries(sourceEntries) {
25433
- return sourceEntries.map((entry) => {
25434
- if (!Array.isArray(entry)) {
25435
- throw new TypeError("Map constructor entries must be arrays.");
25477
+ try {
25478
+ checkData(map, 0, true);
25479
+ while (!consume(iterator.next())) {
25436
25480
  }
25437
- return [entry[0], entry[1]];
25438
- });
25481
+ checkData(map, 0, true);
25482
+ return map;
25483
+ } finally {
25484
+ budget.setRetainedValues(retained, void 0);
25485
+ }
25439
25486
  }
25440
25487
  function getSetValues(source) {
25441
25488
  if (source === void 0 || source === null) {
@@ -25461,11 +25508,6 @@ async function collectSetValues(iterator) {
25461
25508
  }
25462
25509
  return values;
25463
25510
  }
25464
- function createBudgetedMap(entries, budget) {
25465
- const map = createSandboxMap(entries);
25466
- budget.allocateCollectionEntries(map.entries.size);
25467
- return map;
25468
- }
25469
25511
  function createBudgetedSet(values, budget) {
25470
25512
  budget.allocateCollectionEntries(new Set(values).size);
25471
25513
  return createSandboxSet(values);
@@ -30819,12 +30861,11 @@ async function arrayFromSandboxValues(args, budget, context) {
30819
30861
  if (Array.isArray(result)) budget.allocateArrayLength(index + 1);
30820
30862
  if (mapFn !== void 0) currentValue = await invokeBuiltinClosure(mapFn, [currentValue, index], budget, context, thisValue);
30821
30863
  const key = String(index);
30822
- const growth = key.length + 1 + (Array.isArray(result) ? Math.max(0, index + 1 - result.length) : 0) + (typeof currentValue === "string" ? currentValue.length : 0);
30823
- const graphChanged = typeof currentValue === "object" && currentValue !== null || isSandboxClosure(result);
30864
+ const growth = key.length + 1 + (Array.isArray(result) ? Math.max(0, index + 1 - result.length) : 0) + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([currentValue]));
30824
30865
  budget.visitNode();
30825
30866
  defineOwnDataProperty(objectProperties(result, true), key, currentValue);
30826
30867
  currentValue = void 0;
30827
- checkData(result, growth, graphChanged);
30868
+ checkData(result, growth, isSandboxClosure(result));
30828
30869
  } catch (error) {
30829
30870
  await closeOnThrow(error);
30830
30871
  }
@@ -30837,18 +30878,6 @@ async function arrayFromSandboxValues(args, budget, context) {
30837
30878
  budget.setRetainedValues(retained, void 0);
30838
30879
  }
30839
30880
  }
30840
- function createDataCheckpoint(budget, context) {
30841
- let estimatedDataSize = 0;
30842
- return (value, growth = 0, force = false) => {
30843
- const limit = budget.limits.dataSize;
30844
- if (limit === void 0) return;
30845
- estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
30846
- if (!force && estimatedDataSize <= limit) return;
30847
- if (context?.reconcileData !== void 0) context.reconcileData(value);
30848
- else reconcileCompiledValues(budget, [value], context?.compilation);
30849
- estimatedDataSize = budget.currentDataSize;
30850
- };
30851
- }
30852
30881
  function createArrayFromConstructorArgs(args, budget) {
30853
30882
  if (args.length !== 1) {
30854
30883
  return budgetSandboxValue2(Reflect.apply(Array, Array, [...args]), budget);
@@ -33024,4 +33053,4 @@ export {
33024
33053
  FileSnapshotBackend,
33025
33054
  run
33026
33055
  };
33027
- //# sourceMappingURL=chunk-G5X7KIU3.js.map
33056
+ //# sourceMappingURL=chunk-SLQJGSFH.js.map