@poe-platform/safe-js 0.1.304 → 0.1.306

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-I3JCUPXR.js";
30
+ } from "./chunk-ZSYBRZU6.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-K2TSSLLI.js.map
8252
+ //# sourceMappingURL=chunk-BYRLOIR7.js.map
@@ -14195,25 +14195,37 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
14195
14195
  if (applyArgs === null || applyArgs === void 0) {
14196
14196
  return options.callClosure(target, [], stack, thisValue);
14197
14197
  }
14198
- if (!Array.isArray(applyArgs)) {
14199
- throw new TypeError("Function#apply requires an array or nullish arguments value.");
14198
+ if (typeof applyArgs !== "object") {
14199
+ throw new TypeError("Function#apply requires an object or nullish arguments value.");
14200
14200
  }
14201
- if (context?.getProperty === void 0)
14201
+ if (context?.getProperty === void 0 && Array.isArray(applyArgs))
14202
14202
  return options.callClosure(target, applyArgs, stack, thisValue);
14203
14203
  return (async () => {
14204
+ const budget = options.budget ?? new Budget();
14205
+ const invocationContext = {
14206
+ ...context,
14207
+ stack,
14208
+ thisValue: context?.thisValue,
14209
+ invokeClosure: context?.invokeClosure ?? ((callee, values2, receiver) => Promise.resolve(options.callClosure(callee, values2, stack, receiver)))
14210
+ };
14211
+ const read = (value, key) => {
14212
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
14213
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
14214
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, invocationContext);
14215
+ };
14204
14216
  const values = [];
14205
- const length = applyArgs.length;
14206
- options.budget?.allocateArrayLength(length);
14207
- const retained = {};
14208
- options.budget?.setRetainedValues(retained, () => values);
14217
+ const release = retainValues(budget, () => [applyArgs, ...values]);
14209
14218
  try {
14219
+ const number = await sandboxNumber(await read(applyArgs, "length"), budget, invocationContext);
14220
+ const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
14221
+ budget.allocateArrayLength(length);
14210
14222
  for (let index = 0; index < length; index++) {
14211
- options.budget?.visitNode();
14212
- values.push(await context.getProperty(applyArgs, index));
14223
+ budget.visitNode();
14224
+ values.push(await read(applyArgs, String(index)));
14213
14225
  }
14214
14226
  return await options.callClosure(target, values, stack, thisValue);
14215
14227
  } finally {
14216
- options.budget?.setRetainedValues(retained, void 0);
14228
+ release();
14217
14229
  }
14218
14230
  })();
14219
14231
  }
@@ -14462,74 +14474,6 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14462
14474
  }
14463
14475
  }
14464
14476
 
14465
- // packages/safe-js/src/interp/globals/error.ts
14466
- var errorConstructorNames = /* @__PURE__ */ new WeakMap();
14467
- var errorNames = [
14468
- "Error",
14469
- "TypeError",
14470
- "RangeError",
14471
- "ReferenceError",
14472
- "SyntaxError",
14473
- "URIError",
14474
- "EvalError",
14475
- "AggregateError"
14476
- ];
14477
- function createErrorGlobals(options) {
14478
- return Object.fromEntries(
14479
- errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
14480
- );
14481
- }
14482
- function isSandboxErrorConstructorInstance2(value, constructor) {
14483
- if (!isSandboxClosure(constructor)) {
14484
- throw new TypeError("Right-hand side of 'instanceof' is not a function.");
14485
- }
14486
- const name = errorConstructorNames.get(constructor);
14487
- if (name === void 0) {
14488
- return false;
14489
- }
14490
- return isSandboxErrorConstructorInstance(value, name);
14491
- }
14492
- function createErrorConstructor(name, budget) {
14493
- const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
14494
- const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
14495
- errorConstructorNames.set(closure, name);
14496
- return closure;
14497
- }
14498
- function createSubsetError(name, args, stackFrames, budget) {
14499
- const message = name === "AggregateError" ? args[1] : args[0];
14500
- const options = name === "AggregateError" ? args[2] : args[1];
14501
- const error = createSubsetErrorValue(name, message, stackFrames, budget);
14502
- if (name === "AggregateError") {
14503
- const errors = Array.isArray(args[0]) ? [...args[0]] : [];
14504
- budget.allocateArrayLength(errors.length);
14505
- error.errors = errors;
14506
- }
14507
- if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
14508
- error.cause = options.cause;
14509
- }
14510
- return error;
14511
- }
14512
- function isObjectLike(value) {
14513
- return typeof value === "object" && value !== null;
14514
- }
14515
-
14516
- // packages/safe-js/src/interp/methods/collection-iterator.ts
14517
- function getCollectionIteratorMember(target, property, budget) {
14518
- if (Object.hasOwn(target, property)) return target[property];
14519
- if (property !== "next") return void 0;
14520
- const { collectionKind } = collectionIteratorState(target);
14521
- return createSandboxClosure({
14522
- sandbox: true,
14523
- name: "next",
14524
- call: (_args, context) => {
14525
- const receiver = context?.thisValue;
14526
- if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
14527
- throw new TypeError("Iterator next requires a matching collection iterator receiver.");
14528
- return nextCollectionIterator(receiver, budget);
14529
- }
14530
- });
14531
- }
14532
-
14533
14477
  // packages/safe-js/src/interp/globals/float32array.ts
14534
14478
  var constructors = /* @__PURE__ */ new WeakSet();
14535
14479
  function createFloat32ArrayGlobal(budget) {
@@ -14655,6 +14599,119 @@ function relativeIndex(value, length, fallback) {
14655
14599
  return integer2 < 0 ? Math.max(length + integer2, 0) : Math.min(integer2, length);
14656
14600
  }
14657
14601
 
14602
+ // packages/safe-js/src/interp/globals/error.ts
14603
+ var errorConstructorNames = /* @__PURE__ */ new WeakMap();
14604
+ var errorNames = [
14605
+ "Error",
14606
+ "TypeError",
14607
+ "RangeError",
14608
+ "ReferenceError",
14609
+ "SyntaxError",
14610
+ "URIError",
14611
+ "EvalError",
14612
+ "AggregateError"
14613
+ ];
14614
+ function createErrorGlobals(options) {
14615
+ return Object.fromEntries(
14616
+ errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
14617
+ );
14618
+ }
14619
+ function isSandboxErrorConstructorInstance2(value, constructor) {
14620
+ if (!isSandboxClosure(constructor)) {
14621
+ throw new TypeError("Right-hand side of 'instanceof' is not a function.");
14622
+ }
14623
+ const name = errorConstructorNames.get(constructor);
14624
+ if (name === void 0) {
14625
+ return false;
14626
+ }
14627
+ return isSandboxErrorConstructorInstance(value, name);
14628
+ }
14629
+ function createErrorConstructor(name, budget) {
14630
+ const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
14631
+ const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
14632
+ errorConstructorNames.set(closure, name);
14633
+ return closure;
14634
+ }
14635
+ function createSubsetError(name, args, stackFrames, budget) {
14636
+ const message = name === "AggregateError" ? args[1] : args[0];
14637
+ const options = name === "AggregateError" ? args[2] : args[1];
14638
+ const error = createSubsetErrorValue(name, message, stackFrames, budget);
14639
+ if (name === "AggregateError") {
14640
+ const errors = Array.isArray(args[0]) ? [...args[0]] : [];
14641
+ budget.allocateArrayLength(errors.length);
14642
+ error.errors = errors;
14643
+ }
14644
+ if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
14645
+ error.cause = options.cause;
14646
+ }
14647
+ return error;
14648
+ }
14649
+ function isObjectLike(value) {
14650
+ return typeof value === "object" && value !== null;
14651
+ }
14652
+
14653
+ // packages/safe-js/src/interp/instanceof.ts
14654
+ async function evaluateInstanceof(value, constructor, budget, context) {
14655
+ if (constructor === null || typeof constructor !== "object")
14656
+ throw new TypeError("Right-hand side of 'instanceof' must be an object.");
14657
+ const method = await readInstanceProperty(constructor, Symbol.hasInstance, budget, context);
14658
+ if (method !== void 0 && method !== null) {
14659
+ if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
14660
+ return Boolean(await invokeBuiltinClosure(method, [value], budget, context, constructor));
14661
+ }
14662
+ if (!isSandboxClosure(constructor))
14663
+ throw new TypeError("Right-hand side of 'instanceof' is not a function.");
14664
+ return ordinaryHasInstance(value, constructor, budget, context);
14665
+ }
14666
+ async function ordinaryHasInstance(value, constructor, budget, context) {
14667
+ if (!isSandboxClosure(constructor)) return false;
14668
+ if (constructor.boundTarget !== void 0) {
14669
+ budget.visitNode();
14670
+ return evaluateInstanceof(value, constructor.boundTarget, budget, context);
14671
+ }
14672
+ if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
14673
+ if (isSandboxErrorConstructorInstance2(value, constructor)) return true;
14674
+ if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
14675
+ const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
14676
+ if (typeof prototype !== "object" || prototype === null)
14677
+ throw new TypeError("Function has a non-object prototype in instanceof check.");
14678
+ let depth = 0;
14679
+ for (let current = getSandboxPrototype(value, budget); current !== null; current = getSandboxPrototype(current, budget)) {
14680
+ budget.visitNode();
14681
+ assertSandboxDataDepth(depth++);
14682
+ if (current === prototype) return true;
14683
+ }
14684
+ return false;
14685
+ }
14686
+ async function readInstanceProperty(value, key, budget, context) {
14687
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
14688
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
14689
+ if (descriptor === void 0) return void 0;
14690
+ return readPropertyDescriptor(descriptor, value, {
14691
+ ...context,
14692
+ stack: context?.stack ?? [],
14693
+ thisValue: value,
14694
+ invokeClosure: context?.invokeClosure ?? ((closure, args, receiver) => invokeBuiltinClosure(closure, args, budget, context, receiver))
14695
+ });
14696
+ }
14697
+
14698
+ // packages/safe-js/src/interp/methods/collection-iterator.ts
14699
+ function getCollectionIteratorMember(target, property, budget) {
14700
+ if (Object.hasOwn(target, property)) return target[property];
14701
+ if (property !== "next") return void 0;
14702
+ const { collectionKind } = collectionIteratorState(target);
14703
+ return createSandboxClosure({
14704
+ sandbox: true,
14705
+ name: "next",
14706
+ call: (_args, context) => {
14707
+ const receiver = context?.thisValue;
14708
+ if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
14709
+ throw new TypeError("Iterator next requires a matching collection iterator receiver.");
14710
+ return nextCollectionIterator(receiver, budget);
14711
+ }
14712
+ });
14713
+ }
14714
+
14658
14715
  // packages/safe-js/src/interp/scope.ts
14659
14716
  var uninitialized = /* @__PURE__ */ Symbol("uninitialized");
14660
14717
  var Scope = class _Scope {
@@ -17519,42 +17576,11 @@ function applyBinaryOperator(node, left, right, context) {
17519
17576
  case ">>>":
17520
17577
  return toNumber(left) >>> toNumber(right);
17521
17578
  case "instanceof":
17522
- return evaluateInstanceof(left, right, context);
17579
+ return evaluateInstanceof(left, right, context.budget, createCoercionContext(context));
17523
17580
  case "in":
17524
17581
  return hasSandboxProperty(right, left, context);
17525
17582
  }
17526
17583
  }
17527
- async function evaluateInstanceof(left, right, context) {
17528
- while (true) {
17529
- if (right === null || typeof right !== "object" && typeof right !== "function")
17530
- throw new TypeError("Right-hand side of 'instanceof' must be an object.");
17531
- const method = await getPropertyValue(right, Symbol.hasInstance, context);
17532
- if (method !== void 0 && method !== null) {
17533
- if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
17534
- return Boolean(await invokeSandboxClosure(method, [left], context, context.callStack, void 0, right));
17535
- }
17536
- if (!isSandboxClosure(right))
17537
- throw new TypeError("Right-hand side of 'instanceof' is not a function.");
17538
- if (right.boundTarget === void 0) break;
17539
- context.budget.visitNode();
17540
- right = right.boundTarget;
17541
- }
17542
- if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
17543
- if (isSandboxErrorConstructorInstance2(left, right)) return true;
17544
- if (isGuestClosure(right)) {
17545
- if (typeof left !== "object" || left === null) return false;
17546
- const prototype = await getPropertyValue(right, "prototype", context);
17547
- if (typeof prototype !== "object" || prototype === null)
17548
- throw new TypeError("Function has a non-object prototype in instanceof check.");
17549
- let depth = 0;
17550
- for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
17551
- context.budget.visitNode();
17552
- assertSandboxDataDepth(depth++);
17553
- if (current === prototype) return true;
17554
- }
17555
- }
17556
- return false;
17557
- }
17558
17584
  function createCoercionContext(context) {
17559
17585
  return {
17560
17586
  stack: context.callStack,
@@ -24057,7 +24083,7 @@ function createUriGlobals(budget) {
24057
24083
  }
24058
24084
 
24059
24085
  // packages/safe-js/src/interp/globals/function.ts
24060
- function createFunctionPrototype(budget) {
24086
+ function createFunctionPrototype(budget, installHasInstance = true) {
24061
24087
  const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
24062
24088
  const properties = materializeFunctionProperties(prototype);
24063
24089
  Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
@@ -24077,8 +24103,17 @@ function createFunctionPrototype(budget) {
24077
24103
  })
24078
24104
  });
24079
24105
  }
24106
+ const hasInstance = installHasInstance ? createSandboxClosure({
24107
+ guest: true,
24108
+ sandbox: true,
24109
+ name: "[Symbol.hasInstance]",
24110
+ length: 1,
24111
+ call: ([value], context) => ordinaryHasInstance(value, context?.thisValue, budget, context)
24112
+ }) : void 0;
24113
+ if (hasInstance !== void 0) Object.defineProperty(properties, Symbol.hasInstance, { value: hasInstance });
24080
24114
  setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
24081
24115
  installFunctionPrototype(budget, prototype);
24116
+ if (hasInstance !== void 0) registerIntrinsicFunction(budget, hasInstance);
24082
24117
  }
24083
24118
 
24084
24119
  // packages/safe-js/src/interp/globals/generator.ts
@@ -24371,7 +24406,7 @@ function createBuiltinBindings(options) {
24371
24406
  ...createPromiseGlobals(options),
24372
24407
  ...createRegexGlobals(options)
24373
24408
  };
24374
- createFunctionPrototype(options.budget);
24409
+ createFunctionPrototype(options.budget, options.functionHasInstance);
24375
24410
  createGeneratorPrototypes(options.budget);
24376
24411
  registerBuiltinIdentities(options.budget, bindings);
24377
24412
  return bindings;
@@ -41239,4 +41274,4 @@ export {
41239
41274
  FileSnapshotBackend,
41240
41275
  run
41241
41276
  };
41242
- //# sourceMappingURL=chunk-I3JCUPXR.js.map
41277
+ //# sourceMappingURL=chunk-ZSYBRZU6.js.map