poe-code 14.0.58 → 14.0.60

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.
@@ -22,7 +22,7 @@ import {
22
22
  resolveFsConfig,
23
23
  splitFrontmatter,
24
24
  withBrokenPipeGuard
25
- } from "./chunks/chunk-3VTLNK4E.js";
25
+ } from "./chunks/chunk-C7UCTQDN.js";
26
26
  import {
27
27
  Budget,
28
28
  SandboxError,
@@ -34,7 +34,7 @@ import {
34
34
  replaceErrorStack,
35
35
  restore,
36
36
  run
37
- } from "./chunks/chunk-DHD453E5.js";
37
+ } from "./chunks/chunk-MKJBQPBH.js";
38
38
  import "./chunks/chunk-UXMKEUH3.js";
39
39
  import "./chunks/chunk-5DYEOCT5.js";
40
40
  import "./chunks/chunk-4YIDX44G.js";
@@ -5,7 +5,7 @@ import {
5
5
  defineExtension,
6
6
  lint,
7
7
  run
8
- } from "./chunks/chunk-DHD453E5.js";
8
+ } from "./chunks/chunk-MKJBQPBH.js";
9
9
  import "./chunks/chunk-4YIDX44G.js";
10
10
  export {
11
11
  Budget,
@@ -26,7 +26,7 @@ import {
26
26
  runWithSpawnUsageAccumulator,
27
27
  splitFrontmatter,
28
28
  supportsSpawnMode
29
- } from "./chunks/chunk-3VTLNK4E.js";
29
+ } from "./chunks/chunk-C7UCTQDN.js";
30
30
  import {
31
31
  Budget,
32
32
  FileSnapshotBackend,
@@ -50,7 +50,7 @@ import {
50
50
  registerPendingHostCallPolicy,
51
51
  restore,
52
52
  run
53
- } from "./chunks/chunk-DHD453E5.js";
53
+ } from "./chunks/chunk-MKJBQPBH.js";
54
54
  import "./chunks/chunk-UXMKEUH3.js";
55
55
  import "./chunks/chunk-5DYEOCT5.js";
56
56
  import "./chunks/chunk-4YIDX44G.js";
@@ -273,89 +273,114 @@ async function evaluateEmptyStatement(_node, _context) {
273
273
  }
274
274
  async function evaluateArrayExpression(node, context) {
275
275
  const values = [];
276
- for (const element of node.elements) {
277
- if (element.type === "UndefinedLiteral" && element.elision === true) {
278
- values.length += 1;
279
- context.budget.allocateArrayLength(values.length);
280
- continue;
281
- }
282
- if (element.type === "SpreadElement") {
283
- const spreadValues = await evaluateSpreadElement(element, context);
284
- if (!spreadValues.ok) {
285
- return spreadValues.result;
276
+ const release = retainValues(context.budget, () => [values]);
277
+ try {
278
+ for (const element of node.elements) {
279
+ if (element.type === "UndefinedLiteral" && element.elision === true) {
280
+ values.length += 1;
281
+ context.budget.allocateArrayLength(values.length);
282
+ continue;
283
+ }
284
+ if (element.type === "SpreadElement") {
285
+ const spreadValues = await evaluateSpreadElement(element, context);
286
+ if (!spreadValues.ok) {
287
+ return spreadValues.result;
288
+ }
289
+ appendArrayValues(values, spreadValues.value);
290
+ context.budget.allocateArrayLength(values.length);
291
+ continue;
292
+ }
293
+ const result = await evaluateNode(element, context);
294
+ if (result.kind !== "normal") {
295
+ return result;
286
296
  }
287
- appendArrayValues(values, spreadValues.value);
297
+ values.push(result.value);
288
298
  context.budget.allocateArrayLength(values.length);
289
- continue;
290
- }
291
- const result = await evaluateNode(element, context);
292
- if (result.kind !== "normal") {
293
- return result;
294
299
  }
295
- values.push(result.value);
296
- context.budget.allocateArrayLength(values.length);
300
+ return {
301
+ kind: "normal",
302
+ hasValue: true,
303
+ value: values
304
+ };
305
+ }
306
+ finally {
307
+ release();
297
308
  }
298
- return {
299
- kind: "normal",
300
- hasValue: true,
301
- value: values
302
- };
303
309
  }
304
310
  async function evaluateObjectExpression(node, context) {
305
311
  const object = Object.create(null);
306
- for (const property of node.properties) {
307
- if (property.type === "SpreadElement") {
308
- const spreadEntries = await evaluateObjectSpread(property, context);
309
- if (!spreadEntries.ok) {
310
- return spreadEntries.result;
312
+ const release = retainValues(context.budget, () => [object]);
313
+ try {
314
+ for (const property of node.properties) {
315
+ if (property.type === "SpreadElement") {
316
+ const spreadEntries = await evaluateObjectSpread(property, context);
317
+ if (!spreadEntries.ok) {
318
+ return spreadEntries.result;
319
+ }
320
+ for (const [key, value] of spreadEntries.value) {
321
+ defineSandboxProperty(object, key, value);
322
+ }
323
+ continue;
311
324
  }
312
- for (const [key, value] of spreadEntries.value) {
313
- defineSandboxProperty(object, key, value);
325
+ const key = await evaluateObjectPropertyKey(property, context);
326
+ if (!key.ok) {
327
+ return key.result;
314
328
  }
315
- continue;
316
- }
317
- const key = await evaluateObjectPropertyKey(property, context);
318
- if (!key.ok) {
319
- return key.result;
320
- }
321
- const value = await evaluateNode(property.value, context);
322
- if (value.kind !== "normal") {
323
- return value;
324
- }
325
- if (isObjectPrototypeSetterProperty(property, key.value)) {
326
- if (value.value === null || typeof value.value === "object") {
327
- setSandboxPrototype(object, value.value, context.budget);
329
+ const releaseKey = retainValues(context.budget, () => [key.value]);
330
+ let value;
331
+ try {
332
+ value = await evaluateNode(property.value, context);
328
333
  }
329
- continue;
334
+ finally {
335
+ releaseKey();
336
+ }
337
+ if (value.kind !== "normal") {
338
+ return value;
339
+ }
340
+ if (isObjectPrototypeSetterProperty(property, key.value)) {
341
+ if (value.value === null || typeof value.value === "object") {
342
+ setSandboxPrototype(object, value.value, context.budget);
343
+ }
344
+ continue;
345
+ }
346
+ defineSandboxProperty(object, String(key.value), value.value);
330
347
  }
331
- defineSandboxProperty(object, String(key.value), value.value);
348
+ return {
349
+ kind: "normal",
350
+ hasValue: true,
351
+ value: object
352
+ };
353
+ }
354
+ finally {
355
+ release();
332
356
  }
333
- return {
334
- kind: "normal",
335
- hasValue: true,
336
- value: object
337
- };
338
357
  }
339
358
  function isObjectPrototypeSetterProperty(property, key) {
340
359
  return !property.computed && !property.shorthand && key === "__proto__";
341
360
  }
342
361
  async function evaluateTemplateLiteral(node, context) {
343
362
  let value = context.budget.allocateString(node.quasis[0]?.value.cooked ?? "");
344
- for (let index = 0; index < node.expressions.length; index += 1) {
345
- const expression = await evaluateNode(node.expressions[index], context);
346
- if (expression.kind !== "normal") {
347
- return expression;
363
+ const release = retainValues(context.budget, () => [value]);
364
+ try {
365
+ for (let index = 0; index < node.expressions.length; index += 1) {
366
+ const expression = await evaluateNode(node.expressions[index], context);
367
+ if (expression.kind !== "normal") {
368
+ return expression;
369
+ }
370
+ const expressionText = context.budget.allocateString(String(expression.value));
371
+ value = context.budget.allocateString(value + expressionText);
372
+ const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
373
+ value = context.budget.allocateString(value + quasiText);
348
374
  }
349
- const expressionText = context.budget.allocateString(String(expression.value));
350
- value = context.budget.allocateString(value + expressionText);
351
- const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
352
- value = context.budget.allocateString(value + quasiText);
375
+ return {
376
+ kind: "normal",
377
+ hasValue: true,
378
+ value
379
+ };
380
+ }
381
+ finally {
382
+ release();
353
383
  }
354
- return {
355
- kind: "normal",
356
- hasValue: true,
357
- value
358
- };
359
384
  }
360
385
  async function evaluateTaggedTemplateExpression(node, context) {
361
386
  const tag = await evaluateNode(node.tag, context);
@@ -377,20 +402,26 @@ async function evaluateTaggedTemplateExpression(node, context) {
377
402
  }
378
403
  async function evaluateTemplateExpressionValues(node, context) {
379
404
  const values = [];
380
- for (const expressionNode of node.expressions) {
381
- const expression = await evaluateNode(expressionNode, context);
382
- if (expression.kind !== "normal") {
383
- return {
384
- ok: false,
385
- result: expression
386
- };
405
+ const release = retainValues(context.budget, () => values);
406
+ try {
407
+ for (const expressionNode of node.expressions) {
408
+ const expression = await evaluateNode(expressionNode, context);
409
+ if (expression.kind !== "normal") {
410
+ return {
411
+ ok: false,
412
+ result: expression
413
+ };
414
+ }
415
+ values.push(expression.value);
387
416
  }
388
- values.push(expression.value);
417
+ return {
418
+ ok: true,
419
+ value: values
420
+ };
421
+ }
422
+ finally {
423
+ release();
389
424
  }
390
- return {
391
- ok: true,
392
- value: values
393
- };
394
425
  }
395
426
  function createTaggedTemplateStrings(node, context) {
396
427
  context.budget.allocateArrayLength(node.quasis.length);
@@ -430,23 +461,31 @@ async function evaluateBinaryExpression(node, context) {
430
461
  if (left.kind !== "normal") {
431
462
  return left;
432
463
  }
433
- const right = await evaluateNode(node.right, context);
434
- if (right.kind !== "normal") {
435
- return right;
436
- }
437
- let leftValue = left.value;
438
- if (node.operator === "in") {
439
- if (typeof right.value !== "object" || right.value === null) {
440
- throw new TypeError("Right-hand side of 'in' must be an object.");
464
+ let rightValue;
465
+ const release = retainValues(context.budget, () => [left.value, rightValue]);
466
+ try {
467
+ const right = await evaluateNode(node.right, context);
468
+ if (right.kind !== "normal") {
469
+ return right;
441
470
  }
442
- leftValue = await toPropertyKey(leftValue, context.budget, createCoercionContext(context));
471
+ rightValue = right.value;
472
+ let leftValue = left.value;
473
+ if (node.operator === "in") {
474
+ if (typeof right.value !== "object" || right.value === null) {
475
+ throw new TypeError("Right-hand side of 'in' must be an object.");
476
+ }
477
+ leftValue = await toPropertyKey(leftValue, context.budget, createCoercionContext(context));
478
+ }
479
+ const value = applyBinaryOperator(node, leftValue, right.value, context);
480
+ return {
481
+ kind: "normal",
482
+ hasValue: true,
483
+ value
484
+ };
485
+ }
486
+ finally {
487
+ release();
443
488
  }
444
- const value = applyBinaryOperator(node, leftValue, right.value, context);
445
- return {
446
- kind: "normal",
447
- hasValue: true,
448
- value
449
- };
450
489
  }
451
490
  async function evaluateAssignmentExpression(node, context) {
452
491
  if (node.left.type === "ArrayPattern" || node.left.type === "ObjectPattern") {
@@ -554,26 +593,35 @@ async function evaluateMemberAssignmentExpression(node, context) {
554
593
  value: current
555
594
  };
556
595
  }
557
- const right = await evaluateNode(node.right, context);
558
- if (right.kind !== "normal") {
559
- return right;
596
+ let operands = [current, property];
597
+ const release = retainValues(context.budget, () => operands);
598
+ try {
599
+ const right = await evaluateNode(node.right, context);
600
+ if (right.kind !== "normal") {
601
+ return right;
602
+ }
603
+ operands.push(right.value);
604
+ const value = node.operator === "=" ||
605
+ node.operator === "&&=" ||
606
+ node.operator === "||=" ||
607
+ node.operator === "??="
608
+ ? right.value
609
+ : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
610
+ if (member.object === null || member.object === undefined) {
611
+ throw new TypeError("Cannot assign properties of null or undefined.");
612
+ }
613
+ operands = [value];
614
+ property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
615
+ setSandboxProperty(member.object, property, value, context.budget);
616
+ return {
617
+ kind: "normal",
618
+ hasValue: true,
619
+ value
620
+ };
560
621
  }
561
- const value = node.operator === "=" ||
562
- node.operator === "&&=" ||
563
- node.operator === "||=" ||
564
- node.operator === "??="
565
- ? right.value
566
- : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
567
- if (member.object === null || member.object === undefined) {
568
- throw new TypeError("Cannot assign properties of null or undefined.");
622
+ finally {
623
+ release();
569
624
  }
570
- property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
571
- setSandboxProperty(member.object, property, value, context.budget);
572
- return {
573
- kind: "normal",
574
- hasValue: true,
575
- value
576
- };
577
625
  });
578
626
  }
579
627
  async function evaluateLogicalExpression(node, context) {
@@ -1768,12 +1816,8 @@ async function evaluateMemberAccess(node, context, consume) {
1768
1816
  if ((object.value === null || object.value === undefined) && node.optional) {
1769
1817
  return consume({ kind: "nullish" });
1770
1818
  }
1771
- const retained = {};
1772
1819
  let property;
1773
- context.budget.setRetainedValues(retained, () => [object.value, property]);
1774
- const release = () => context.budget.setRetainedValues(retained, undefined);
1775
- const pending = runResources.getStore()?.referenceReleases;
1776
- pending?.add(release);
1820
+ const release = retainValues(context.budget, () => [object.value, property]);
1777
1821
  try {
1778
1822
  const result = node.computed
1779
1823
  ? await evaluateNode(node.property, context)
@@ -1785,9 +1829,19 @@ async function evaluateMemberAccess(node, context, consume) {
1785
1829
  }
1786
1830
  finally {
1787
1831
  release();
1788
- pending?.delete(release);
1789
1832
  }
1790
1833
  }
1834
+ function retainValues(budget, values) {
1835
+ const retained = {};
1836
+ budget.setRetainedValues(retained, values);
1837
+ const pending = runResources.getStore()?.referenceReleases;
1838
+ const release = () => {
1839
+ budget.setRetainedValues(retained, undefined);
1840
+ pending?.delete(release);
1841
+ };
1842
+ pending?.add(release);
1843
+ return release;
1844
+ }
1791
1845
  async function evaluateMemberProperty(node, context) {
1792
1846
  const property = await evaluateNode(node, context);
1793
1847
  if (property.kind !== "normal") {
@@ -2538,30 +2592,36 @@ async function invokeSandboxClosure(callee, args, context, stack, span, thisValu
2538
2592
  }
2539
2593
  async function evaluateCallArguments(args, context) {
2540
2594
  const values = [];
2541
- for (const arg of args) {
2542
- if (arg.type === "SpreadElement") {
2543
- const spreadValues = await evaluateSpreadElement(arg, context);
2544
- if (!spreadValues.ok) {
2545
- return spreadValues;
2595
+ const release = retainValues(context.budget, () => values);
2596
+ try {
2597
+ for (const arg of args) {
2598
+ if (arg.type === "SpreadElement") {
2599
+ const spreadValues = await evaluateSpreadElement(arg, context);
2600
+ if (!spreadValues.ok) {
2601
+ return spreadValues;
2602
+ }
2603
+ appendArrayValues(values, spreadValues.value);
2604
+ context.budget.allocateArrayLength(values.length);
2605
+ continue;
2606
+ }
2607
+ const result = await evaluateNode(arg, context);
2608
+ if (result.kind !== "normal") {
2609
+ return {
2610
+ ok: false,
2611
+ result
2612
+ };
2546
2613
  }
2547
- appendArrayValues(values, spreadValues.value);
2614
+ values.push(result.value);
2548
2615
  context.budget.allocateArrayLength(values.length);
2549
- continue;
2550
- }
2551
- const result = await evaluateNode(arg, context);
2552
- if (result.kind !== "normal") {
2553
- return {
2554
- ok: false,
2555
- result
2556
- };
2557
2616
  }
2558
- values.push(result.value);
2559
- context.budget.allocateArrayLength(values.length);
2617
+ return {
2618
+ ok: true,
2619
+ value: values
2620
+ };
2621
+ }
2622
+ finally {
2623
+ release();
2560
2624
  }
2561
- return {
2562
- ok: true,
2563
- value: values
2564
- };
2565
2625
  }
2566
2626
  async function evaluateSpreadElement(node, context) {
2567
2627
  const value = await evaluateNode(node.argument, context);
@@ -2576,21 +2636,27 @@ async function evaluateSpreadElement(node, context) {
2576
2636
  throw new TypeError("Spread arguments must evaluate to an iterable.");
2577
2637
  }
2578
2638
  const spreadValues = [];
2579
- while (true) {
2580
- const next = await iterator.next();
2581
- if (typeof next !== "object" || next === null) {
2582
- throw new TypeError("Iterator result must be an object.");
2583
- }
2584
- if (next.done === true) {
2585
- break;
2639
+ const release = retainValues(context.budget, () => [value.value, ...spreadValues]);
2640
+ try {
2641
+ while (true) {
2642
+ const next = await iterator.next();
2643
+ if (typeof next !== "object" || next === null) {
2644
+ throw new TypeError("Iterator result must be an object.");
2645
+ }
2646
+ if (next.done === true) {
2647
+ break;
2648
+ }
2649
+ spreadValues.push(next.value);
2650
+ context.budget.allocateArrayLength(spreadValues.length);
2586
2651
  }
2587
- spreadValues.push(next.value);
2588
- context.budget.allocateArrayLength(spreadValues.length);
2652
+ return {
2653
+ ok: true,
2654
+ value: spreadValues
2655
+ };
2656
+ }
2657
+ finally {
2658
+ release();
2589
2659
  }
2590
- return {
2591
- ok: true,
2592
- value: spreadValues
2593
- };
2594
2660
  }
2595
2661
  async function evaluateObjectSpread(node, context) {
2596
2662
  const value = await evaluateNode(node.argument, context);