@poe-platform/safe-js 0.1.115 → 0.1.116

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-G2KH7I4M.js";
30
+ } from "./chunk-VDFW3EKS.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-HFCKNAQK.js.map
8248
+ //# sourceMappingURL=chunk-3R3FX4C5.js.map
@@ -24826,63 +24826,42 @@ function getNumberMember(property, budget) {
24826
24826
  return createSandboxClosure({
24827
24827
  sandbox: true,
24828
24828
  name: `Number#${property}`,
24829
- call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget)
24829
+ call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget, context)
24830
24830
  });
24831
24831
  }
24832
24832
  function isNumberMethodName(property) {
24833
24833
  return typeof property === "string" && numberMethodNames.has(property);
24834
24834
  }
24835
- function callNumberMethod(value, methodName, args, budget) {
24835
+ function callNumberMethod(value, methodName, args, budget, context) {
24836
24836
  if (typeof value !== "number") {
24837
24837
  throw new TypeError(`Number#${methodName} requires a number receiver.`);
24838
24838
  }
24839
- return budget.allocateString(callNativeNumberMethod(value, methodName, args));
24840
- }
24841
- function callNativeNumberMethod(value, methodName, args) {
24842
- switch (methodName) {
24843
- case "toString":
24844
- return value.toString(asValidatedRadix(args[0]));
24845
- case "toExponential":
24846
- return args[0] === void 0 ? value.toExponential() : value.toExponential(asValidatedFractionDigits(args[0], methodName));
24847
- case "toFixed":
24848
- return value.toFixed(asValidatedFractionDigits(args[0], methodName));
24849
- case "toPrecision":
24850
- return args[0] === void 0 ? value.toPrecision() : value.toPrecision(asValidatedPrecision(args[0]));
24839
+ const argument = args[0];
24840
+ if (argument !== null && typeof argument === "object") {
24841
+ return formatObjectArgument(value, methodName, argument, budget, context);
24851
24842
  }
24843
+ return formatNumber(value, methodName, argument === void 0 ? void 0 : Number(argument), budget);
24852
24844
  }
24853
- function asValidatedRadix(value) {
24854
- if (value === void 0) {
24855
- return void 0;
24856
- }
24857
- const radix = toIntegerOrInfinity2(value);
24858
- if (radix < 2 || radix > 36) {
24859
- throw new RangeError("Number#toString radix must be between 2 and 36.");
24860
- }
24861
- return radix;
24862
- }
24863
- function asValidatedFractionDigits(value, methodName) {
24864
- const digits = toIntegerOrInfinity2(value);
24865
- if (digits < 0 || digits > 100) {
24866
- throw new RangeError(`Number#${methodName} digits must be between 0 and 100.`);
24867
- }
24868
- return digits;
24869
- }
24870
- function asValidatedPrecision(value) {
24871
- const precision = toIntegerOrInfinity2(value);
24872
- if (precision < 1 || precision > 100) {
24873
- throw new RangeError("Number#toPrecision precision must be between 1 and 100.");
24845
+ async function formatObjectArgument(value, methodName, argument, budget, context) {
24846
+ const retainedArgument = {};
24847
+ budget.setRetainedValues(retainedArgument, () => [argument]);
24848
+ try {
24849
+ const number = await sandboxNumber(argument, budget, context);
24850
+ return formatNumber(value, methodName, number, budget);
24851
+ } finally {
24852
+ budget.setRetainedValues(retainedArgument, void 0);
24874
24853
  }
24875
- return precision;
24876
24854
  }
24877
- function toIntegerOrInfinity2(value) {
24878
- const number = Number(value);
24879
- if (Number.isNaN(number) || Object.is(number, 0) || Object.is(number, -0)) {
24880
- return 0;
24881
- }
24882
- if (!Number.isFinite(number)) {
24883
- return number;
24855
+ function formatNumber(value, methodName, argument, budget) {
24856
+ let result;
24857
+ try {
24858
+ result = value[methodName](argument);
24859
+ } catch (error) {
24860
+ if (!(error instanceof RangeError)) throw error;
24861
+ const detail = methodName === "toString" ? "radix must be between 2 and 36." : methodName === "toPrecision" ? "precision must be between 1 and 100." : "digits must be between 0 and 100.";
24862
+ throw new RangeError(`Number#${methodName} ${detail}`);
24884
24863
  }
24885
- return Math.trunc(number);
24864
+ return budget.allocateString(result);
24886
24865
  }
24887
24866
 
24888
24867
  // packages/safe-js/src/interp/methods/generator.ts
@@ -28707,7 +28686,7 @@ async function evaluateNumberMethodCall(node, target, methodName, context) {
28707
28686
  return {
28708
28687
  kind: "normal",
28709
28688
  hasValue: true,
28710
- value: callNumberMethod(target, methodName, args.value, context.budget)
28689
+ value: await callNumberMethod(target, methodName, args.value, context.budget, createCoercionContext(context))
28711
28690
  };
28712
28691
  } catch (error) {
28713
28692
  if (isFatalSandboxError(error)) {
@@ -33304,4 +33283,4 @@ export {
33304
33283
  FileSnapshotBackend,
33305
33284
  run
33306
33285
  };
33307
- //# sourceMappingURL=chunk-G2KH7I4M.js.map
33286
+ //# sourceMappingURL=chunk-VDFW3EKS.js.map