@poe-platform/safe-js 0.1.124 → 0.1.125

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-DHD453E5.js";
30
+ } from "./chunk-D4YY44EF.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-WKRFMSJA.js.map
8248
+ //# sourceMappingURL=chunk-AHZ74NTE.js.map
@@ -26595,89 +26595,110 @@ async function evaluateEmptyStatement(_node, _context) {
26595
26595
  }
26596
26596
  async function evaluateArrayExpression(node, context) {
26597
26597
  const values = [];
26598
- for (const element of node.elements) {
26599
- if (element.type === "UndefinedLiteral" && element.elision === true) {
26600
- values.length += 1;
26601
- context.budget.allocateArrayLength(values.length);
26602
- continue;
26603
- }
26604
- if (element.type === "SpreadElement") {
26605
- const spreadValues = await evaluateSpreadElement(element, context);
26606
- if (!spreadValues.ok) {
26607
- return spreadValues.result;
26598
+ const release = retainValues(context.budget, () => [values]);
26599
+ try {
26600
+ for (const element of node.elements) {
26601
+ if (element.type === "UndefinedLiteral" && element.elision === true) {
26602
+ values.length += 1;
26603
+ context.budget.allocateArrayLength(values.length);
26604
+ continue;
26605
+ }
26606
+ if (element.type === "SpreadElement") {
26607
+ const spreadValues = await evaluateSpreadElement(element, context);
26608
+ if (!spreadValues.ok) {
26609
+ return spreadValues.result;
26610
+ }
26611
+ appendArrayValues2(values, spreadValues.value);
26612
+ context.budget.allocateArrayLength(values.length);
26613
+ continue;
26608
26614
  }
26609
- appendArrayValues2(values, spreadValues.value);
26615
+ const result = await evaluateNode(element, context);
26616
+ if (result.kind !== "normal") {
26617
+ return result;
26618
+ }
26619
+ values.push(result.value);
26610
26620
  context.budget.allocateArrayLength(values.length);
26611
- continue;
26612
- }
26613
- const result = await evaluateNode(element, context);
26614
- if (result.kind !== "normal") {
26615
- return result;
26616
26621
  }
26617
- values.push(result.value);
26618
- context.budget.allocateArrayLength(values.length);
26622
+ return {
26623
+ kind: "normal",
26624
+ hasValue: true,
26625
+ value: values
26626
+ };
26627
+ } finally {
26628
+ release();
26619
26629
  }
26620
- return {
26621
- kind: "normal",
26622
- hasValue: true,
26623
- value: values
26624
- };
26625
26630
  }
26626
26631
  async function evaluateObjectExpression(node, context) {
26627
26632
  const object = /* @__PURE__ */ Object.create(null);
26628
- for (const property of node.properties) {
26629
- if (property.type === "SpreadElement") {
26630
- const spreadEntries = await evaluateObjectSpread(property, context);
26631
- if (!spreadEntries.ok) {
26632
- return spreadEntries.result;
26633
+ const release = retainValues(context.budget, () => [object]);
26634
+ try {
26635
+ for (const property of node.properties) {
26636
+ if (property.type === "SpreadElement") {
26637
+ const spreadEntries = await evaluateObjectSpread(property, context);
26638
+ if (!spreadEntries.ok) {
26639
+ return spreadEntries.result;
26640
+ }
26641
+ for (const [key2, value2] of spreadEntries.value) {
26642
+ defineSandboxProperty(object, key2, value2);
26643
+ }
26644
+ continue;
26633
26645
  }
26634
- for (const [key2, value2] of spreadEntries.value) {
26635
- defineSandboxProperty(object, key2, value2);
26646
+ const key = await evaluateObjectPropertyKey(property, context);
26647
+ if (!key.ok) {
26648
+ return key.result;
26636
26649
  }
26637
- continue;
26638
- }
26639
- const key = await evaluateObjectPropertyKey(property, context);
26640
- if (!key.ok) {
26641
- return key.result;
26642
- }
26643
- const value = await evaluateNode(property.value, context);
26644
- if (value.kind !== "normal") {
26645
- return value;
26646
- }
26647
- if (isObjectPrototypeSetterProperty(property, key.value)) {
26648
- if (value.value === null || typeof value.value === "object") {
26649
- setSandboxPrototype(object, value.value, context.budget);
26650
+ const releaseKey = retainValues(context.budget, () => [key.value]);
26651
+ let value;
26652
+ try {
26653
+ value = await evaluateNode(property.value, context);
26654
+ } finally {
26655
+ releaseKey();
26650
26656
  }
26651
- continue;
26657
+ if (value.kind !== "normal") {
26658
+ return value;
26659
+ }
26660
+ if (isObjectPrototypeSetterProperty(property, key.value)) {
26661
+ if (value.value === null || typeof value.value === "object") {
26662
+ setSandboxPrototype(object, value.value, context.budget);
26663
+ }
26664
+ continue;
26665
+ }
26666
+ defineSandboxProperty(object, String(key.value), value.value);
26652
26667
  }
26653
- defineSandboxProperty(object, String(key.value), value.value);
26668
+ return {
26669
+ kind: "normal",
26670
+ hasValue: true,
26671
+ value: object
26672
+ };
26673
+ } finally {
26674
+ release();
26654
26675
  }
26655
- return {
26656
- kind: "normal",
26657
- hasValue: true,
26658
- value: object
26659
- };
26660
26676
  }
26661
26677
  function isObjectPrototypeSetterProperty(property, key) {
26662
26678
  return !property.computed && !property.shorthand && key === "__proto__";
26663
26679
  }
26664
26680
  async function evaluateTemplateLiteral(node, context) {
26665
26681
  let value = context.budget.allocateString(node.quasis[0]?.value.cooked ?? "");
26666
- for (let index = 0; index < node.expressions.length; index += 1) {
26667
- const expression = await evaluateNode(node.expressions[index], context);
26668
- if (expression.kind !== "normal") {
26669
- return expression;
26682
+ const release = retainValues(context.budget, () => [value]);
26683
+ try {
26684
+ for (let index = 0; index < node.expressions.length; index += 1) {
26685
+ const expression = await evaluateNode(node.expressions[index], context);
26686
+ if (expression.kind !== "normal") {
26687
+ return expression;
26688
+ }
26689
+ const expressionText = context.budget.allocateString(String(expression.value));
26690
+ value = context.budget.allocateString(value + expressionText);
26691
+ const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
26692
+ value = context.budget.allocateString(value + quasiText);
26670
26693
  }
26671
- const expressionText = context.budget.allocateString(String(expression.value));
26672
- value = context.budget.allocateString(value + expressionText);
26673
- const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
26674
- value = context.budget.allocateString(value + quasiText);
26694
+ return {
26695
+ kind: "normal",
26696
+ hasValue: true,
26697
+ value
26698
+ };
26699
+ } finally {
26700
+ release();
26675
26701
  }
26676
- return {
26677
- kind: "normal",
26678
- hasValue: true,
26679
- value
26680
- };
26681
26702
  }
26682
26703
  async function evaluateTaggedTemplateExpression(node, context) {
26683
26704
  const tag = await evaluateNode(node.tag, context);
@@ -26704,20 +26725,25 @@ async function evaluateTaggedTemplateExpression(node, context) {
26704
26725
  }
26705
26726
  async function evaluateTemplateExpressionValues(node, context) {
26706
26727
  const values = [];
26707
- for (const expressionNode of node.expressions) {
26708
- const expression = await evaluateNode(expressionNode, context);
26709
- if (expression.kind !== "normal") {
26710
- return {
26711
- ok: false,
26712
- result: expression
26713
- };
26728
+ const release = retainValues(context.budget, () => values);
26729
+ try {
26730
+ for (const expressionNode of node.expressions) {
26731
+ const expression = await evaluateNode(expressionNode, context);
26732
+ if (expression.kind !== "normal") {
26733
+ return {
26734
+ ok: false,
26735
+ result: expression
26736
+ };
26737
+ }
26738
+ values.push(expression.value);
26714
26739
  }
26715
- values.push(expression.value);
26740
+ return {
26741
+ ok: true,
26742
+ value: values
26743
+ };
26744
+ } finally {
26745
+ release();
26716
26746
  }
26717
- return {
26718
- ok: true,
26719
- value: values
26720
- };
26721
26747
  }
26722
26748
  function createTaggedTemplateStrings(node, context) {
26723
26749
  context.budget.allocateArrayLength(node.quasis.length);
@@ -26765,23 +26791,30 @@ async function evaluateBinaryExpression(node, context) {
26765
26791
  if (left.kind !== "normal") {
26766
26792
  return left;
26767
26793
  }
26768
- const right = await evaluateNode(node.right, context);
26769
- if (right.kind !== "normal") {
26770
- return right;
26771
- }
26772
- let leftValue = left.value;
26773
- if (node.operator === "in") {
26774
- if (typeof right.value !== "object" || right.value === null) {
26775
- throw new TypeError("Right-hand side of 'in' must be an object.");
26794
+ let rightValue;
26795
+ const release = retainValues(context.budget, () => [left.value, rightValue]);
26796
+ try {
26797
+ const right = await evaluateNode(node.right, context);
26798
+ if (right.kind !== "normal") {
26799
+ return right;
26800
+ }
26801
+ rightValue = right.value;
26802
+ let leftValue = left.value;
26803
+ if (node.operator === "in") {
26804
+ if (typeof right.value !== "object" || right.value === null) {
26805
+ throw new TypeError("Right-hand side of 'in' must be an object.");
26806
+ }
26807
+ leftValue = await toPropertyKey(leftValue, context.budget, createCoercionContext(context));
26776
26808
  }
26777
- leftValue = await toPropertyKey(leftValue, context.budget, createCoercionContext(context));
26809
+ const value = applyBinaryOperator(node, leftValue, right.value, context);
26810
+ return {
26811
+ kind: "normal",
26812
+ hasValue: true,
26813
+ value
26814
+ };
26815
+ } finally {
26816
+ release();
26778
26817
  }
26779
- const value = applyBinaryOperator(node, leftValue, right.value, context);
26780
- return {
26781
- kind: "normal",
26782
- hasValue: true,
26783
- value
26784
- };
26785
26818
  }
26786
26819
  async function evaluateAssignmentExpression(node, context) {
26787
26820
  if (node.left.type === "ArrayPattern" || node.left.type === "ObjectPattern") {
@@ -26888,21 +26921,29 @@ async function evaluateMemberAssignmentExpression(node, context) {
26888
26921
  value: current
26889
26922
  };
26890
26923
  }
26891
- const right = await evaluateNode(node.right, context);
26892
- if (right.kind !== "normal") {
26893
- return right;
26894
- }
26895
- const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
26896
- if (member.object === null || member.object === void 0) {
26897
- throw new TypeError("Cannot assign properties of null or undefined.");
26924
+ let operands = [current, property];
26925
+ const release = retainValues(context.budget, () => operands);
26926
+ try {
26927
+ const right = await evaluateNode(node.right, context);
26928
+ if (right.kind !== "normal") {
26929
+ return right;
26930
+ }
26931
+ operands.push(right.value);
26932
+ const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
26933
+ if (member.object === null || member.object === void 0) {
26934
+ throw new TypeError("Cannot assign properties of null or undefined.");
26935
+ }
26936
+ operands = [value];
26937
+ property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
26938
+ setSandboxProperty(member.object, property, value, context.budget);
26939
+ return {
26940
+ kind: "normal",
26941
+ hasValue: true,
26942
+ value
26943
+ };
26944
+ } finally {
26945
+ release();
26898
26946
  }
26899
- property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
26900
- setSandboxProperty(member.object, property, value, context.budget);
26901
- return {
26902
- kind: "normal",
26903
- hasValue: true,
26904
- value
26905
- };
26906
26947
  });
26907
26948
  }
26908
26949
  async function evaluateLogicalExpression(node, context) {
@@ -28081,12 +28122,8 @@ async function evaluateMemberAccess(node, context, consume) {
28081
28122
  if ((object.value === null || object.value === void 0) && node.optional) {
28082
28123
  return consume({ kind: "nullish" });
28083
28124
  }
28084
- const retained = {};
28085
28125
  let property;
28086
- context.budget.setRetainedValues(retained, () => [object.value, property]);
28087
- const release = () => context.budget.setRetainedValues(retained, void 0);
28088
- const pending = runResources.getStore()?.referenceReleases;
28089
- pending?.add(release);
28126
+ const release = retainValues(context.budget, () => [object.value, property]);
28090
28127
  try {
28091
28128
  const result = node.computed ? await evaluateNode(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
28092
28129
  if (result.kind !== "normal") return result;
@@ -28094,9 +28131,19 @@ async function evaluateMemberAccess(node, context, consume) {
28094
28131
  return await consume({ kind: "resolved", object: object.value, property });
28095
28132
  } finally {
28096
28133
  release();
28097
- pending?.delete(release);
28098
28134
  }
28099
28135
  }
28136
+ function retainValues(budget, values) {
28137
+ const retained = {};
28138
+ budget.setRetainedValues(retained, values);
28139
+ const pending = runResources.getStore()?.referenceReleases;
28140
+ const release = () => {
28141
+ budget.setRetainedValues(retained, void 0);
28142
+ pending?.delete(release);
28143
+ };
28144
+ pending?.add(release);
28145
+ return release;
28146
+ }
28100
28147
  async function evaluateMemberProperty(node, context) {
28101
28148
  const property = await evaluateNode(node, context);
28102
28149
  if (property.kind !== "normal") {
@@ -28892,30 +28939,35 @@ async function invokeSandboxClosure(callee, args, context, stack, span, thisValu
28892
28939
  }
28893
28940
  async function evaluateCallArguments(args, context) {
28894
28941
  const values = [];
28895
- for (const arg of args) {
28896
- if (arg.type === "SpreadElement") {
28897
- const spreadValues = await evaluateSpreadElement(arg, context);
28898
- if (!spreadValues.ok) {
28899
- return spreadValues;
28942
+ const release = retainValues(context.budget, () => values);
28943
+ try {
28944
+ for (const arg of args) {
28945
+ if (arg.type === "SpreadElement") {
28946
+ const spreadValues = await evaluateSpreadElement(arg, context);
28947
+ if (!spreadValues.ok) {
28948
+ return spreadValues;
28949
+ }
28950
+ appendArrayValues2(values, spreadValues.value);
28951
+ context.budget.allocateArrayLength(values.length);
28952
+ continue;
28900
28953
  }
28901
- appendArrayValues2(values, spreadValues.value);
28954
+ const result = await evaluateNode(arg, context);
28955
+ if (result.kind !== "normal") {
28956
+ return {
28957
+ ok: false,
28958
+ result
28959
+ };
28960
+ }
28961
+ values.push(result.value);
28902
28962
  context.budget.allocateArrayLength(values.length);
28903
- continue;
28904
28963
  }
28905
- const result = await evaluateNode(arg, context);
28906
- if (result.kind !== "normal") {
28907
- return {
28908
- ok: false,
28909
- result
28910
- };
28911
- }
28912
- values.push(result.value);
28913
- context.budget.allocateArrayLength(values.length);
28964
+ return {
28965
+ ok: true,
28966
+ value: values
28967
+ };
28968
+ } finally {
28969
+ release();
28914
28970
  }
28915
- return {
28916
- ok: true,
28917
- value: values
28918
- };
28919
28971
  }
28920
28972
  async function evaluateSpreadElement(node, context) {
28921
28973
  const value = await evaluateNode(node.argument, context);
@@ -28930,21 +28982,26 @@ async function evaluateSpreadElement(node, context) {
28930
28982
  throw new TypeError("Spread arguments must evaluate to an iterable.");
28931
28983
  }
28932
28984
  const spreadValues = [];
28933
- while (true) {
28934
- const next = await iterator.next();
28935
- if (typeof next !== "object" || next === null) {
28936
- throw new TypeError("Iterator result must be an object.");
28937
- }
28938
- if (next.done === true) {
28939
- break;
28985
+ const release = retainValues(context.budget, () => [value.value, ...spreadValues]);
28986
+ try {
28987
+ while (true) {
28988
+ const next = await iterator.next();
28989
+ if (typeof next !== "object" || next === null) {
28990
+ throw new TypeError("Iterator result must be an object.");
28991
+ }
28992
+ if (next.done === true) {
28993
+ break;
28994
+ }
28995
+ spreadValues.push(next.value);
28996
+ context.budget.allocateArrayLength(spreadValues.length);
28940
28997
  }
28941
- spreadValues.push(next.value);
28942
- context.budget.allocateArrayLength(spreadValues.length);
28998
+ return {
28999
+ ok: true,
29000
+ value: spreadValues
29001
+ };
29002
+ } finally {
29003
+ release();
28943
29004
  }
28944
- return {
28945
- ok: true,
28946
- value: spreadValues
28947
- };
28948
29005
  }
28949
29006
  async function evaluateObjectSpread(node, context) {
28950
29007
  const value = await evaluateNode(node.argument, context);
@@ -33406,4 +33463,4 @@ export {
33406
33463
  FileSnapshotBackend,
33407
33464
  run
33408
33465
  };
33409
- //# sourceMappingURL=chunk-DHD453E5.js.map
33466
+ //# sourceMappingURL=chunk-D4YY44EF.js.map