@poe-platform/safe-js 0.1.252 → 0.1.254

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-QN4BNY6V.js";
30
+ } from "./chunk-VFXTEJXR.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-EEO344SX.js.map
8252
+ //# sourceMappingURL=chunk-4MBS7HVN.js.map
@@ -22164,6 +22164,7 @@ function f16round(value) {
22164
22164
  }
22165
22165
  function createMathGlobals(options = {}) {
22166
22166
  const random = options.random ?? Math.random;
22167
+ const budget = options.budget ?? new Budget();
22167
22168
  const mathObject = {
22168
22169
  E: Math.E,
22169
22170
  LN2: Math.LN2,
@@ -22173,12 +22174,15 @@ function createMathGlobals(options = {}) {
22173
22174
  PI: Math.PI,
22174
22175
  SQRT1_2: Math.SQRT1_2,
22175
22176
  SQRT2: Math.SQRT2,
22176
- random: createSandboxClosure({ sandbox: true, call: () => random(), name: "random" })
22177
+ random: createSandboxClosure({ sandbox: true, guest: true, call: () => random(), name: "random", length: 0 })
22177
22178
  };
22178
22179
  for (const [name, method] of Object.entries(mathMethods)) {
22180
+ const variadic = method === Math.max || method === Math.min || method === Math.hypot;
22179
22181
  mathObject[name] = createSandboxClosure({
22180
22182
  sandbox: true,
22181
- call: (args) => Reflect.apply(method, Math, args),
22183
+ guest: true,
22184
+ length: method.length,
22185
+ call: (args, context) => callNumericMethod(method, args, variadic, budget, context),
22182
22186
  name
22183
22187
  });
22184
22188
  }
@@ -22191,12 +22195,44 @@ function createMathGlobals(options = {}) {
22191
22195
  });
22192
22196
  }
22193
22197
  Object.defineProperty(mathObject, Symbol.toStringTag, { value: "Math", configurable: true });
22198
+ registerBuiltinIdentities(budget, { Math: mathObject });
22199
+ for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(mathObject))) {
22200
+ if (isSandboxClosure(descriptor.value)) registerIntrinsicFunction(budget, descriptor.value);
22201
+ }
22202
+ registerIntrinsicObject(budget, mathObject);
22194
22203
  return {
22195
22204
  Infinity: Infinity,
22196
22205
  Math: mathObject,
22197
22206
  NaN: Number.NaN
22198
22207
  };
22199
22208
  }
22209
+ function callNumericMethod(method, args, variadic, budget, context) {
22210
+ const count = variadic ? args.length : Math.min(args.length, method.length);
22211
+ const numbers = [];
22212
+ const release = retainValues(budget, () => [...args, numbers]);
22213
+ try {
22214
+ const result = advance();
22215
+ if (result instanceof Promise) return result.finally(release);
22216
+ release();
22217
+ return result;
22218
+ } catch (error) {
22219
+ release();
22220
+ throw error;
22221
+ }
22222
+ function advance() {
22223
+ while (numbers.length < count) {
22224
+ budget.visitNode();
22225
+ const input = args[numbers.length];
22226
+ const number = context === void 0 ? +input : sandboxNumber(input, budget, context);
22227
+ if (number instanceof Promise) return number.then((value) => {
22228
+ numbers.push(value);
22229
+ return advance();
22230
+ });
22231
+ numbers.push(number);
22232
+ }
22233
+ return Reflect.apply(method, Math, numbers);
22234
+ }
22235
+ }
22200
22236
  function createSeededRandom(seed) {
22201
22237
  let state = normalizeSeed(seed);
22202
22238
  return {
@@ -22860,7 +22896,7 @@ function createBuiltinBindings(options) {
22860
22896
  Symbol: createSymbolGlobal(options.budget),
22861
22897
  BigInt: createBigIntGlobal(options.budget),
22862
22898
  ...createErrorGlobals(options),
22863
- ...createMathGlobals({ random: options.random }),
22899
+ ...createMathGlobals({ random: options.random, budget: options.budget }),
22864
22900
  ...createObjectArrayGlobals(options),
22865
22901
  ...createMiscGlobals(options),
22866
22902
  ...createUriGlobals(options.budget),
@@ -22868,7 +22904,6 @@ function createBuiltinBindings(options) {
22868
22904
  ...createRegexGlobals(options)
22869
22905
  };
22870
22906
  registerBuiltinIdentities(options.budget, bindings);
22871
- registerIntrinsicObject(options.budget, bindings.Math);
22872
22907
  return bindings;
22873
22908
  }
22874
22909
 
@@ -39585,4 +39620,4 @@ export {
39585
39620
  FileSnapshotBackend,
39586
39621
  run
39587
39622
  };
39588
- //# sourceMappingURL=chunk-QN4BNY6V.js.map
39623
+ //# sourceMappingURL=chunk-VFXTEJXR.js.map