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.
package/dist/index.js CHANGED
@@ -144659,7 +144659,11 @@ function getMapMember(target, property, options) {
144659
144659
  }
144660
144660
  return createSandboxClosure({
144661
144661
  sandbox: true,
144662
- call: (args, context) => callMapMethod(target, property, args, options, context?.stack ?? []),
144662
+ call: (args, context) => {
144663
+ const receiver = context?.thisValue;
144664
+ if (!isSandboxMap(receiver)) throw new TypeError(`Map#${property} requires a Map receiver.`);
144665
+ return callMapMethod(receiver, property, args, options, context?.stack ?? []);
144666
+ },
144663
144667
  name: property
144664
144668
  });
144665
144669
  }
@@ -145295,7 +145299,11 @@ function getSetMember(target, property, options) {
145295
145299
  }
145296
145300
  return createSandboxClosure({
145297
145301
  sandbox: true,
145298
- call: (args, context) => callSetMethod(target, property, args, options, context?.stack ?? []),
145302
+ call: (args, context) => {
145303
+ const receiver = context?.thisValue;
145304
+ if (!isSandboxSet(receiver)) throw new TypeError(`Set#${property} requires a Set receiver.`);
145305
+ return callSetMethod(receiver, property, args, options, context?.stack ?? []);
145306
+ },
145299
145307
  name: property
145300
145308
  });
145301
145309
  }
@@ -145567,6 +145575,26 @@ var init_object2 = __esm({
145567
145575
  }
145568
145576
  });
145569
145577
 
145578
+ // packages/safe-js/src/interp/data-checkpoint.ts
145579
+ function createDataCheckpoint(budget, context) {
145580
+ let estimatedDataSize = 0;
145581
+ return (value, growth = 0, force = false) => {
145582
+ const limit = budget.limits.dataSize;
145583
+ if (limit === void 0) return;
145584
+ estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
145585
+ if (!force && estimatedDataSize <= limit) return;
145586
+ if (context?.reconcileData !== void 0) context.reconcileData(value);
145587
+ else reconcileCompiledValues(budget, [value], context?.compilation);
145588
+ estimatedDataSize = budget.currentDataSize;
145589
+ };
145590
+ }
145591
+ var init_data_checkpoint = __esm({
145592
+ "packages/safe-js/src/interp/data-checkpoint.ts"() {
145593
+ "use strict";
145594
+ init_values();
145595
+ }
145596
+ });
145597
+
145570
145598
  // packages/safe-js/src/interp/globals/collections.ts
145571
145599
  function createCollectionGlobals(options) {
145572
145600
  const mapConstructor = createSandboxClosure({
@@ -145574,12 +145602,27 @@ function createCollectionGlobals(options) {
145574
145602
  call: () => {
145575
145603
  throw new TypeError("Constructor Map requires 'new'.");
145576
145604
  },
145577
- construct: ([source]) => {
145578
- const entries = getMapEntries(source);
145579
- if (entries instanceof Promise) {
145580
- return entries.then((resolved) => createBudgetedMap(resolved, options.budget));
145581
- }
145582
- return createBudgetedMap(entries, options.budget);
145605
+ construct: ([source], context) => {
145606
+ const map = createSandboxMap([]);
145607
+ let key3;
145608
+ let value;
145609
+ return populateCollection(source, map, {
145610
+ name: "Map",
145611
+ budget: options.budget,
145612
+ context,
145613
+ retainedValues: () => [key3, value],
145614
+ append: (entry) => {
145615
+ if (typeof entry !== "object" || entry === null) throw new TypeError("Map constructor requires entry objects.");
145616
+ key3 = context?.getProperty !== void 0 ? context.getProperty(entry, 0) : getSandboxDataProperty(entry, 0, options.budget);
145617
+ value = context?.getProperty !== void 0 ? context.getProperty(entry, 1) : getSandboxDataProperty(entry, 1, options.budget);
145618
+ const added = map.entries.has(key3) ? 0 : 1;
145619
+ const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([key3, value]));
145620
+ options.budget.allocateCollectionEntries(map.entries.size + added);
145621
+ map.entries.set(key3, value);
145622
+ key3 = value = void 0;
145623
+ return growth;
145624
+ }
145625
+ });
145583
145626
  },
145584
145627
  name: "Map"
145585
145628
  });
@@ -145588,12 +145631,20 @@ function createCollectionGlobals(options) {
145588
145631
  call: () => {
145589
145632
  throw new TypeError("Constructor Set requires 'new'.");
145590
145633
  },
145591
- construct: ([source]) => {
145592
- const values = getSetValues(source);
145593
- if (values instanceof Promise) {
145594
- return values.then((resolved) => createBudgetedSet(resolved, options.budget));
145595
- }
145596
- return createBudgetedSet(values, options.budget);
145634
+ construct: ([source], context) => {
145635
+ const set = createSandboxSet([]);
145636
+ return populateCollection(source, set, {
145637
+ name: "Set",
145638
+ budget: options.budget,
145639
+ context,
145640
+ append: (value) => {
145641
+ const added = set.values.has(value) ? 0 : 1;
145642
+ const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([value]));
145643
+ options.budget.allocateCollectionEntries(set.values.size + added);
145644
+ set.values.add(value);
145645
+ return growth;
145646
+ }
145647
+ });
145597
145648
  },
145598
145649
  name: "Set"
145599
145650
  });
@@ -145607,77 +145658,78 @@ function isSandboxMapConstructor(value) {
145607
145658
  function isSandboxSetConstructor(value) {
145608
145659
  return typeof value === "object" && value !== null && setConstructors.has(value);
145609
145660
  }
145610
- function getMapEntries(source) {
145611
- if (source === void 0 || source === null) {
145612
- return [];
145613
- }
145614
- if (isSandboxMap(source)) {
145615
- return [...source.entries];
145616
- }
145617
- if (Array.isArray(source)) {
145618
- return validateMapEntries(source);
145619
- }
145661
+ function populateCollection(source, collection, { name, budget, context, append, retainedValues }) {
145662
+ budget.allocateCollectionEntries(0);
145663
+ if (source === void 0 || source === null) return collection;
145620
145664
  const iterator = getSandboxIterator(source);
145621
- if (iterator?.generator !== true) {
145622
- throw new TypeError("Map constructor argument must be an array of pairs or a Map.");
145623
- }
145624
- return collectMapEntries(iterator);
145625
- }
145626
- async function collectMapEntries(iterator) {
145627
- const sourceEntries = [];
145628
- while (true) {
145629
- const result = await iterator.next();
145630
- if (result.done) break;
145631
- sourceEntries.push(result.value);
145632
- }
145633
- return validateMapEntries(sourceEntries);
145634
- }
145635
- function validateMapEntries(sourceEntries) {
145636
- return sourceEntries.map((entry) => {
145637
- if (!Array.isArray(entry)) {
145638
- throw new TypeError("Map constructor entries must be arrays.");
145665
+ if (iterator === void 0) throw new TypeError(`${name} constructor requires an iterable.`);
145666
+ let entry;
145667
+ let failure;
145668
+ const retained = {};
145669
+ budget.setRetainedValues(retained, () => [source, collection, entry, failure, ...retainedValues?.() ?? []]);
145670
+ const checkData = createDataCheckpoint(budget, context);
145671
+ const closeOnThrow = (error3) => {
145672
+ failure = isCapturedException(error3) ? error3.reason : error3;
145673
+ const rethrow = (closeError) => {
145674
+ if (!isFatalSandboxError(error3) && isFatalSandboxError(closeError)) throw closeError;
145675
+ throw error3;
145676
+ };
145677
+ try {
145678
+ const closing = iterator.return?.();
145679
+ if (iterator.generator) return Promise.resolve(closing).then(() => {
145680
+ throw error3;
145681
+ }, rethrow);
145682
+ } catch (closeError) {
145683
+ return rethrow(closeError);
145639
145684
  }
145640
- return [entry[0], entry[1]];
145641
- });
145642
- }
145643
- function getSetValues(source) {
145644
- if (source === void 0 || source === null) {
145645
- return [];
145646
- }
145647
- if (isSandboxSet(source)) {
145648
- return [...source.values];
145649
- }
145650
- if (typeof source === "string") return [...source];
145651
- if (Array.isArray(source)) return [...source];
145652
- const iterator = getSandboxIterator(source);
145653
- if (iterator?.generator === true) {
145654
- return collectSetValues(iterator);
145685
+ throw error3;
145686
+ };
145687
+ const consume = (result) => {
145688
+ if (typeof result !== "object" || result === null) throw new TypeError("Iterator result must be an object.");
145689
+ if (result.done) return true;
145690
+ entry = result.value;
145691
+ try {
145692
+ budget.visitNode();
145693
+ const growth = append(entry);
145694
+ entry = void 0;
145695
+ checkData(collection, growth);
145696
+ } catch (error3) {
145697
+ return closeOnThrow(error3);
145698
+ }
145699
+ return false;
145700
+ };
145701
+ if (iterator.generator) {
145702
+ return (async () => {
145703
+ try {
145704
+ checkData(collection, 0, true);
145705
+ while (!await consume(await iterator.next())) {
145706
+ }
145707
+ checkData(collection, 0, true);
145708
+ return collection;
145709
+ } finally {
145710
+ budget.setRetainedValues(retained, void 0);
145711
+ }
145712
+ })();
145655
145713
  }
145656
- throw new TypeError("Set constructor argument must be an array, string, or Set.");
145657
- }
145658
- async function collectSetValues(iterator) {
145659
- const values = [];
145660
- while (true) {
145661
- const result = await iterator.next();
145662
- if (result.done) break;
145663
- values.push(result.value);
145714
+ try {
145715
+ checkData(collection, 0, true);
145716
+ while (!consume(iterator.next())) {
145717
+ }
145718
+ checkData(collection, 0, true);
145719
+ return collection;
145720
+ } finally {
145721
+ budget.setRetainedValues(retained, void 0);
145664
145722
  }
145665
- return values;
145666
- }
145667
- function createBudgetedMap(entries, budget) {
145668
- const map = createSandboxMap(entries);
145669
- budget.allocateCollectionEntries(map.entries.size);
145670
- return map;
145671
- }
145672
- function createBudgetedSet(values, budget) {
145673
- budget.allocateCollectionEntries(new Set(values).size);
145674
- return createSandboxSet(values);
145675
145723
  }
145676
145724
  var mapConstructors, setConstructors;
145677
145725
  var init_collections = __esm({
145678
145726
  "packages/safe-js/src/interp/globals/collections.ts"() {
145679
145727
  "use strict";
145728
+ init_budget2();
145729
+ init_data_checkpoint();
145730
+ init_exceptions();
145680
145731
  init_iteration();
145732
+ init_object_model();
145681
145733
  init_values();
145682
145734
  mapConstructors = /* @__PURE__ */ new WeakSet();
145683
145735
  setConstructors = /* @__PURE__ */ new WeakSet();
@@ -151164,18 +151216,6 @@ async function arrayFromSandboxValues(args, budget, context) {
151164
151216
  budget.setRetainedValues(retained, void 0);
151165
151217
  }
151166
151218
  }
151167
- function createDataCheckpoint(budget, context) {
151168
- let estimatedDataSize = 0;
151169
- return (value, growth = 0, force = false) => {
151170
- const limit = budget.limits.dataSize;
151171
- if (limit === void 0) return;
151172
- estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
151173
- if (!force && estimatedDataSize <= limit) return;
151174
- if (context?.reconcileData !== void 0) context.reconcileData(value);
151175
- else reconcileCompiledValues(budget, [value], context?.compilation);
151176
- estimatedDataSize = budget.currentDataSize;
151177
- };
151178
- }
151179
151219
  function createArrayFromConstructorArgs(args, budget) {
151180
151220
  if (args.length !== 1) {
151181
151221
  return budgetSandboxValue2(Reflect.apply(Array, Array, [...args]), budget);
@@ -151230,6 +151270,7 @@ var init_object_array = __esm({
151230
151270
  "use strict";
151231
151271
  init_budget2();
151232
151272
  init_builtin_call();
151273
+ init_data_checkpoint();
151233
151274
  init_exceptions();
151234
151275
  init_date();
151235
151276
  init_date2();