@poe-platform/safe-js 0.1.305 → 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-JIC2DHRN.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-OENI52IW.js.map
8252
+ //# sourceMappingURL=chunk-BYRLOIR7.js.map
@@ -14474,74 +14474,6 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14474
14474
  }
14475
14475
  }
14476
14476
 
14477
- // packages/safe-js/src/interp/globals/error.ts
14478
- var errorConstructorNames = /* @__PURE__ */ new WeakMap();
14479
- var errorNames = [
14480
- "Error",
14481
- "TypeError",
14482
- "RangeError",
14483
- "ReferenceError",
14484
- "SyntaxError",
14485
- "URIError",
14486
- "EvalError",
14487
- "AggregateError"
14488
- ];
14489
- function createErrorGlobals(options) {
14490
- return Object.fromEntries(
14491
- errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
14492
- );
14493
- }
14494
- function isSandboxErrorConstructorInstance2(value, constructor) {
14495
- if (!isSandboxClosure(constructor)) {
14496
- throw new TypeError("Right-hand side of 'instanceof' is not a function.");
14497
- }
14498
- const name = errorConstructorNames.get(constructor);
14499
- if (name === void 0) {
14500
- return false;
14501
- }
14502
- return isSandboxErrorConstructorInstance(value, name);
14503
- }
14504
- function createErrorConstructor(name, budget) {
14505
- const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
14506
- const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
14507
- errorConstructorNames.set(closure, name);
14508
- return closure;
14509
- }
14510
- function createSubsetError(name, args, stackFrames, budget) {
14511
- const message = name === "AggregateError" ? args[1] : args[0];
14512
- const options = name === "AggregateError" ? args[2] : args[1];
14513
- const error = createSubsetErrorValue(name, message, stackFrames, budget);
14514
- if (name === "AggregateError") {
14515
- const errors = Array.isArray(args[0]) ? [...args[0]] : [];
14516
- budget.allocateArrayLength(errors.length);
14517
- error.errors = errors;
14518
- }
14519
- if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
14520
- error.cause = options.cause;
14521
- }
14522
- return error;
14523
- }
14524
- function isObjectLike(value) {
14525
- return typeof value === "object" && value !== null;
14526
- }
14527
-
14528
- // packages/safe-js/src/interp/methods/collection-iterator.ts
14529
- function getCollectionIteratorMember(target, property, budget) {
14530
- if (Object.hasOwn(target, property)) return target[property];
14531
- if (property !== "next") return void 0;
14532
- const { collectionKind } = collectionIteratorState(target);
14533
- return createSandboxClosure({
14534
- sandbox: true,
14535
- name: "next",
14536
- call: (_args, context) => {
14537
- const receiver = context?.thisValue;
14538
- if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
14539
- throw new TypeError("Iterator next requires a matching collection iterator receiver.");
14540
- return nextCollectionIterator(receiver, budget);
14541
- }
14542
- });
14543
- }
14544
-
14545
14477
  // packages/safe-js/src/interp/globals/float32array.ts
14546
14478
  var constructors = /* @__PURE__ */ new WeakSet();
14547
14479
  function createFloat32ArrayGlobal(budget) {
@@ -14667,6 +14599,119 @@ function relativeIndex(value, length, fallback) {
14667
14599
  return integer2 < 0 ? Math.max(length + integer2, 0) : Math.min(integer2, length);
14668
14600
  }
14669
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
+
14670
14715
  // packages/safe-js/src/interp/scope.ts
14671
14716
  var uninitialized = /* @__PURE__ */ Symbol("uninitialized");
14672
14717
  var Scope = class _Scope {
@@ -17531,42 +17576,11 @@ function applyBinaryOperator(node, left, right, context) {
17531
17576
  case ">>>":
17532
17577
  return toNumber(left) >>> toNumber(right);
17533
17578
  case "instanceof":
17534
- return evaluateInstanceof(left, right, context);
17579
+ return evaluateInstanceof(left, right, context.budget, createCoercionContext(context));
17535
17580
  case "in":
17536
17581
  return hasSandboxProperty(right, left, context);
17537
17582
  }
17538
17583
  }
17539
- async function evaluateInstanceof(left, right, context) {
17540
- while (true) {
17541
- if (right === null || typeof right !== "object" && typeof right !== "function")
17542
- throw new TypeError("Right-hand side of 'instanceof' must be an object.");
17543
- const method = await getPropertyValue(right, Symbol.hasInstance, context);
17544
- if (method !== void 0 && method !== null) {
17545
- if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
17546
- return Boolean(await invokeSandboxClosure(method, [left], context, context.callStack, void 0, right));
17547
- }
17548
- if (!isSandboxClosure(right))
17549
- throw new TypeError("Right-hand side of 'instanceof' is not a function.");
17550
- if (right.boundTarget === void 0) break;
17551
- context.budget.visitNode();
17552
- right = right.boundTarget;
17553
- }
17554
- if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
17555
- if (isSandboxErrorConstructorInstance2(left, right)) return true;
17556
- if (isGuestClosure(right)) {
17557
- if (typeof left !== "object" || left === null) return false;
17558
- const prototype = await getPropertyValue(right, "prototype", context);
17559
- if (typeof prototype !== "object" || prototype === null)
17560
- throw new TypeError("Function has a non-object prototype in instanceof check.");
17561
- let depth = 0;
17562
- for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
17563
- context.budget.visitNode();
17564
- assertSandboxDataDepth(depth++);
17565
- if (current === prototype) return true;
17566
- }
17567
- }
17568
- return false;
17569
- }
17570
17584
  function createCoercionContext(context) {
17571
17585
  return {
17572
17586
  stack: context.callStack,
@@ -24069,7 +24083,7 @@ function createUriGlobals(budget) {
24069
24083
  }
24070
24084
 
24071
24085
  // packages/safe-js/src/interp/globals/function.ts
24072
- function createFunctionPrototype(budget) {
24086
+ function createFunctionPrototype(budget, installHasInstance = true) {
24073
24087
  const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
24074
24088
  const properties = materializeFunctionProperties(prototype);
24075
24089
  Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
@@ -24089,8 +24103,17 @@ function createFunctionPrototype(budget) {
24089
24103
  })
24090
24104
  });
24091
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 });
24092
24114
  setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
24093
24115
  installFunctionPrototype(budget, prototype);
24116
+ if (hasInstance !== void 0) registerIntrinsicFunction(budget, hasInstance);
24094
24117
  }
24095
24118
 
24096
24119
  // packages/safe-js/src/interp/globals/generator.ts
@@ -24383,7 +24406,7 @@ function createBuiltinBindings(options) {
24383
24406
  ...createPromiseGlobals(options),
24384
24407
  ...createRegexGlobals(options)
24385
24408
  };
24386
- createFunctionPrototype(options.budget);
24409
+ createFunctionPrototype(options.budget, options.functionHasInstance);
24387
24410
  createGeneratorPrototypes(options.budget);
24388
24411
  registerBuiltinIdentities(options.budget, bindings);
24389
24412
  return bindings;
@@ -41251,4 +41274,4 @@ export {
41251
41274
  FileSnapshotBackend,
41252
41275
  run
41253
41276
  };
41254
- //# sourceMappingURL=chunk-JIC2DHRN.js.map
41277
+ //# sourceMappingURL=chunk-ZSYBRZU6.js.map