poe-code 14.0.49 → 14.0.50

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.
@@ -24528,7 +24528,11 @@ function getMapMember(target, property, options) {
24528
24528
  }
24529
24529
  return createSandboxClosure({
24530
24530
  sandbox: true,
24531
- call: (args, context) => callMapMethod(target, property, args, options, context?.stack ?? []),
24531
+ call: (args, context) => {
24532
+ const receiver = context?.thisValue;
24533
+ if (!isSandboxMap(receiver)) throw new TypeError(`Map#${property} requires a Map receiver.`);
24534
+ return callMapMethod(receiver, property, args, options, context?.stack ?? []);
24535
+ },
24532
24536
  name: property
24533
24537
  });
24534
24538
  }
@@ -25130,7 +25134,11 @@ function getSetMember(target, property, options) {
25130
25134
  }
25131
25135
  return createSandboxClosure({
25132
25136
  sandbox: true,
25133
- call: (args, context) => callSetMethod(target, property, args, options, context?.stack ?? []),
25137
+ call: (args, context) => {
25138
+ const receiver = context?.thisValue;
25139
+ if (!isSandboxSet(receiver)) throw new TypeError(`Set#${property} requires a Set receiver.`);
25140
+ return callSetMethod(receiver, property, args, options, context?.stack ?? []);
25141
+ },
25134
25142
  name: property
25135
25143
  });
25136
25144
  }
@@ -25362,6 +25370,20 @@ function typeTag(value) {
25362
25370
  return "Object";
25363
25371
  }
25364
25372
 
25373
+ // packages/safe-js/src/interp/data-checkpoint.ts
25374
+ function createDataCheckpoint(budget, context) {
25375
+ let estimatedDataSize = 0;
25376
+ return (value, growth = 0, force = false) => {
25377
+ const limit = budget.limits.dataSize;
25378
+ if (limit === void 0) return;
25379
+ estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
25380
+ if (!force && estimatedDataSize <= limit) return;
25381
+ if (context?.reconcileData !== void 0) context.reconcileData(value);
25382
+ else reconcileCompiledValues(budget, [value], context?.compilation);
25383
+ estimatedDataSize = budget.currentDataSize;
25384
+ };
25385
+ }
25386
+
25365
25387
  // packages/safe-js/src/interp/globals/collections.ts
25366
25388
  var mapConstructors = /* @__PURE__ */ new WeakSet();
25367
25389
  var setConstructors = /* @__PURE__ */ new WeakSet();
@@ -25371,12 +25393,27 @@ function createCollectionGlobals(options) {
25371
25393
  call: () => {
25372
25394
  throw new TypeError("Constructor Map requires 'new'.");
25373
25395
  },
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);
25396
+ construct: ([source], context) => {
25397
+ const map = createSandboxMap([]);
25398
+ let key;
25399
+ let value;
25400
+ return populateCollection(source, map, {
25401
+ name: "Map",
25402
+ budget: options.budget,
25403
+ context,
25404
+ retainedValues: () => [key, value],
25405
+ append: (entry) => {
25406
+ if (typeof entry !== "object" || entry === null) throw new TypeError("Map constructor requires entry objects.");
25407
+ key = context?.getProperty !== void 0 ? context.getProperty(entry, 0) : getSandboxDataProperty(entry, 0, options.budget);
25408
+ value = context?.getProperty !== void 0 ? context.getProperty(entry, 1) : getSandboxDataProperty(entry, 1, options.budget);
25409
+ const added = map.entries.has(key) ? 0 : 1;
25410
+ const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([key, value]));
25411
+ options.budget.allocateCollectionEntries(map.entries.size + added);
25412
+ map.entries.set(key, value);
25413
+ key = value = void 0;
25414
+ return growth;
25415
+ }
25416
+ });
25380
25417
  },
25381
25418
  name: "Map"
25382
25419
  });
@@ -25385,12 +25422,20 @@ function createCollectionGlobals(options) {
25385
25422
  call: () => {
25386
25423
  throw new TypeError("Constructor Set requires 'new'.");
25387
25424
  },
25388
- construct: ([source]) => {
25389
- const values = getSetValues(source);
25390
- if (values instanceof Promise) {
25391
- return values.then((resolved) => createBudgetedSet(resolved, options.budget));
25392
- }
25393
- return createBudgetedSet(values, options.budget);
25425
+ construct: ([source], context) => {
25426
+ const set = createSandboxSet([]);
25427
+ return populateCollection(source, set, {
25428
+ name: "Set",
25429
+ budget: options.budget,
25430
+ context,
25431
+ append: (value) => {
25432
+ const added = set.values.has(value) ? 0 : 1;
25433
+ const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([value]));
25434
+ options.budget.allocateCollectionEntries(set.values.size + added);
25435
+ set.values.add(value);
25436
+ return growth;
25437
+ }
25438
+ });
25394
25439
  },
25395
25440
  name: "Set"
25396
25441
  });
@@ -25404,71 +25449,68 @@ function isSandboxMapConstructor(value) {
25404
25449
  function isSandboxSetConstructor(value) {
25405
25450
  return typeof value === "object" && value !== null && setConstructors.has(value);
25406
25451
  }
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
- }
25452
+ function populateCollection(source, collection, { name, budget, context, append, retainedValues }) {
25453
+ budget.allocateCollectionEntries(0);
25454
+ if (source === void 0 || source === null) return collection;
25417
25455
  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);
25429
- }
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.");
25456
+ if (iterator === void 0) throw new TypeError(`${name} constructor requires an iterable.`);
25457
+ let entry;
25458
+ let failure;
25459
+ const retained = {};
25460
+ budget.setRetainedValues(retained, () => [source, collection, entry, failure, ...retainedValues?.() ?? []]);
25461
+ const checkData = createDataCheckpoint(budget, context);
25462
+ const closeOnThrow = (error) => {
25463
+ failure = isCapturedException(error) ? error.reason : error;
25464
+ const rethrow = (closeError) => {
25465
+ if (!isFatalSandboxError(error) && isFatalSandboxError(closeError)) throw closeError;
25466
+ throw error;
25467
+ };
25468
+ try {
25469
+ const closing = iterator.return?.();
25470
+ if (iterator.generator) return Promise.resolve(closing).then(() => {
25471
+ throw error;
25472
+ }, rethrow);
25473
+ } catch (closeError) {
25474
+ return rethrow(closeError);
25436
25475
  }
25437
- return [entry[0], entry[1]];
25438
- });
25439
- }
25440
- function getSetValues(source) {
25441
- if (source === void 0 || source === null) {
25442
- return [];
25443
- }
25444
- if (isSandboxSet(source)) {
25445
- return [...source.values];
25446
- }
25447
- if (typeof source === "string") return [...source];
25448
- if (Array.isArray(source)) return [...source];
25449
- const iterator = getSandboxIterator(source);
25450
- if (iterator?.generator === true) {
25451
- return collectSetValues(iterator);
25476
+ throw error;
25477
+ };
25478
+ const consume = (result) => {
25479
+ if (typeof result !== "object" || result === null) throw new TypeError("Iterator result must be an object.");
25480
+ if (result.done) return true;
25481
+ entry = result.value;
25482
+ try {
25483
+ budget.visitNode();
25484
+ const growth = append(entry);
25485
+ entry = void 0;
25486
+ checkData(collection, growth);
25487
+ } catch (error) {
25488
+ return closeOnThrow(error);
25489
+ }
25490
+ return false;
25491
+ };
25492
+ if (iterator.generator) {
25493
+ return (async () => {
25494
+ try {
25495
+ checkData(collection, 0, true);
25496
+ while (!await consume(await iterator.next())) {
25497
+ }
25498
+ checkData(collection, 0, true);
25499
+ return collection;
25500
+ } finally {
25501
+ budget.setRetainedValues(retained, void 0);
25502
+ }
25503
+ })();
25452
25504
  }
25453
- throw new TypeError("Set constructor argument must be an array, string, or Set.");
25454
- }
25455
- async function collectSetValues(iterator) {
25456
- const values = [];
25457
- while (true) {
25458
- const result = await iterator.next();
25459
- if (result.done) break;
25460
- values.push(result.value);
25505
+ try {
25506
+ checkData(collection, 0, true);
25507
+ while (!consume(iterator.next())) {
25508
+ }
25509
+ checkData(collection, 0, true);
25510
+ return collection;
25511
+ } finally {
25512
+ budget.setRetainedValues(retained, void 0);
25461
25513
  }
25462
- return values;
25463
- }
25464
- function createBudgetedMap(entries, budget) {
25465
- const map = createSandboxMap(entries);
25466
- budget.allocateCollectionEntries(map.entries.size);
25467
- return map;
25468
- }
25469
- function createBudgetedSet(values, budget) {
25470
- budget.allocateCollectionEntries(new Set(values).size);
25471
- return createSandboxSet(values);
25472
25514
  }
25473
25515
 
25474
25516
  // packages/safe-js/src/interp/globals/float32array.ts
@@ -30836,18 +30878,6 @@ async function arrayFromSandboxValues(args, budget, context) {
30836
30878
  budget.setRetainedValues(retained, void 0);
30837
30879
  }
30838
30880
  }
30839
- function createDataCheckpoint(budget, context) {
30840
- let estimatedDataSize = 0;
30841
- return (value, growth = 0, force = false) => {
30842
- const limit = budget.limits.dataSize;
30843
- if (limit === void 0) return;
30844
- estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
30845
- if (!force && estimatedDataSize <= limit) return;
30846
- if (context?.reconcileData !== void 0) context.reconcileData(value);
30847
- else reconcileCompiledValues(budget, [value], context?.compilation);
30848
- estimatedDataSize = budget.currentDataSize;
30849
- };
30850
- }
30851
30881
  function createArrayFromConstructorArgs(args, budget) {
30852
30882
  if (args.length !== 1) {
30853
30883
  return budgetSandboxValue2(Reflect.apply(Array, Array, [...args]), budget);
@@ -33023,4 +33053,4 @@ export {
33023
33053
  FileSnapshotBackend,
33024
33054
  run
33025
33055
  };
33026
- //# sourceMappingURL=chunk-FV3SMFMZ.js.map
33056
+ //# sourceMappingURL=chunk-7AIY5C3F.js.map