@poe-platform/safe-js 0.1.164 → 0.1.166

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-VHZYRV5Q.js";
30
+ } from "./chunk-LVK2NO45.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-JPANSO6U.js.map
8252
+ //# sourceMappingURL=chunk-L2WEG3IX.js.map
@@ -9486,7 +9486,7 @@ function syncIterator(iterator) {
9486
9486
  }
9487
9487
 
9488
9488
  // packages/safe-js/src/interp/patterns.ts
9489
- async function bindPattern(pattern, value, target, scope, context) {
9489
+ async function bindPattern(pattern, value, target, scope, context, reference) {
9490
9490
  switch (pattern.type) {
9491
9491
  case "Identifier":
9492
9492
  bindIdentifier(pattern, value, target, scope);
@@ -9495,15 +9495,15 @@ async function bindPattern(pattern, value, target, scope, context) {
9495
9495
  if ("kind" in target) {
9496
9496
  throw new TypeError("Destructuring declarations cannot bind to member expressions.");
9497
9497
  }
9498
- return bindMemberExpression(pattern, value, scope, context);
9498
+ return bindMemberExpression(pattern, value, context, reference);
9499
9499
  case "AssignmentPattern":
9500
- return bindAssignmentPattern(pattern, value, target, scope, context);
9500
+ return bindAssignmentPattern(pattern, value, target, scope, context, reference);
9501
9501
  case "ArrayPattern":
9502
9502
  return bindArrayPattern(pattern, value, target, scope, context);
9503
9503
  case "ObjectPattern":
9504
9504
  return bindObjectPattern(pattern, value, target, scope, context);
9505
9505
  case "RestElement":
9506
- return bindPattern(pattern.argument, value, target, scope, context);
9506
+ return bindPattern(pattern.argument, value, target, scope, context, reference);
9507
9507
  }
9508
9508
  }
9509
9509
  function bindIdentifier(pattern, value, target, scope) {
@@ -9522,9 +9522,9 @@ function bindIdentifier(pattern, value, target, scope) {
9522
9522
  }
9523
9523
  scope.declare(pattern.name, target.kind, value);
9524
9524
  }
9525
- async function bindAssignmentPattern(pattern, value, target, scope, context) {
9525
+ async function bindAssignmentPattern(pattern, value, target, scope, context, reference) {
9526
9526
  if (value !== void 0) {
9527
- return bindPattern(pattern.left, value, target, scope, context);
9527
+ return bindPattern(pattern.left, value, target, scope, context, reference);
9528
9528
  }
9529
9529
  const defaultValue = await context.evaluate(
9530
9530
  pattern.right,
@@ -9533,7 +9533,26 @@ async function bindAssignmentPattern(pattern, value, target, scope, context) {
9533
9533
  if (defaultValue.kind !== "normal") {
9534
9534
  return { ok: false, result: defaultValue };
9535
9535
  }
9536
- return bindPattern(pattern.left, defaultValue.value, target, scope, context);
9536
+ return bindPattern(pattern.left, defaultValue.value, target, scope, context, reference);
9537
+ }
9538
+ async function bindPatternValue(pattern, readValue, target, scope, context) {
9539
+ let member = pattern;
9540
+ while (member.type === "AssignmentPattern" || member.type === "RestElement")
9541
+ member = member.type === "AssignmentPattern" ? member.left : member.argument;
9542
+ let reference;
9543
+ if ("assign" in target && member.type === "MemberExpression") {
9544
+ const prepared = await prepareMemberReference(member, context);
9545
+ if (!prepared.ok) return prepared;
9546
+ reference = prepared.reference;
9547
+ }
9548
+ let value;
9549
+ const release = context.budget === void 0 ? () => void 0 : retainValues(context.budget, () => [reference?.object, reference?.key, value]);
9550
+ try {
9551
+ value = (await readValue()).value;
9552
+ return await bindPattern(pattern, value, target, scope, context, reference);
9553
+ } finally {
9554
+ release();
9555
+ }
9537
9556
  }
9538
9557
  async function bindArrayPattern(pattern, value, target, scope, context) {
9539
9558
  const budget = context.budget ?? new Budget();
@@ -9570,20 +9589,22 @@ async function bindArrayPattern(pattern, value, target, scope, context) {
9570
9589
  await next(false);
9571
9590
  continue;
9572
9591
  }
9573
- let elementValue;
9574
- if (element.type === "RestElement") {
9575
- const rest = [];
9576
- retained = rest;
9577
- for (let entry = await next(); !done; entry = await next()) {
9578
- budget.allocateArrayLength(rest.length + 1);
9579
- rest.push(entry.value);
9580
- }
9581
- elementValue = rest;
9582
- } else {
9583
- elementValue = (await next()).value;
9584
- }
9585
- retained = elementValue;
9586
- const binding = await bindPattern(element, elementValue, target, scope, context);
9592
+ const binding = await bindPatternValue(
9593
+ element,
9594
+ async () => {
9595
+ if (element.type !== "RestElement") return next();
9596
+ const rest = [];
9597
+ retained = rest;
9598
+ for (let entry = await next(); !done; entry = await next()) {
9599
+ budget.allocateArrayLength(rest.length + 1);
9600
+ rest.push(entry.value);
9601
+ }
9602
+ return { value: rest };
9603
+ },
9604
+ target,
9605
+ scope,
9606
+ context
9607
+ );
9587
9608
  if (!binding.ok) {
9588
9609
  if (!done) {
9589
9610
  done = true;
@@ -9605,15 +9626,15 @@ async function bindArrayPattern(pattern, value, target, scope, context) {
9605
9626
  }
9606
9627
  }
9607
9628
  async function bindObjectPattern(pattern, value, target, scope, context) {
9608
- if (typeof value !== "object" || value === null) {
9609
- throw new TypeError("Object destructuring declarations require a non-null object value.");
9629
+ if (value === void 0 || value === null) {
9630
+ throw new TypeError("Object destructuring requires a non-nullish value.");
9610
9631
  }
9611
9632
  const excludedKeys = /* @__PURE__ */ new Set();
9612
9633
  for (const property of pattern.properties) {
9613
9634
  if (property.type === "RestElement") {
9614
- const binding2 = await bindPattern(
9635
+ const binding2 = await bindPatternValue(
9615
9636
  property,
9616
- await copyObjectRestValue(value, excludedKeys, context),
9637
+ async () => ({ value: await copyObjectRestValue(value, excludedKeys, context) }),
9617
9638
  target,
9618
9639
  scope,
9619
9640
  context
@@ -9628,9 +9649,9 @@ async function bindObjectPattern(pattern, value, target, scope, context) {
9628
9649
  return key;
9629
9650
  }
9630
9651
  excludedKeys.add(typeof key.value === "symbol" ? key.value : String(key.value));
9631
- const binding = await bindPattern(
9652
+ const binding = await bindPatternValue(
9632
9653
  property.value,
9633
- await context.getProperty(value, key.value),
9654
+ async () => ({ value: await context.getProperty(value, key.value) }),
9634
9655
  target,
9635
9656
  scope,
9636
9657
  context
@@ -9641,7 +9662,22 @@ async function bindObjectPattern(pattern, value, target, scope, context) {
9641
9662
  }
9642
9663
  return { ok: true };
9643
9664
  }
9644
- async function bindMemberExpression(pattern, value, scope, context) {
9665
+ async function bindMemberExpression(pattern, value, context, reference) {
9666
+ if (reference === void 0) {
9667
+ const prepared = await prepareMemberReference(pattern, context);
9668
+ if (!prepared.ok) return prepared;
9669
+ reference = prepared.reference;
9670
+ }
9671
+ if (reference.object === null || reference.object === void 0) {
9672
+ throw new TypeError("Cannot assign properties of null or undefined.");
9673
+ }
9674
+ if (!isIndexableValue(reference.object)) {
9675
+ throw new TypeError("Assignment expressions require a sandbox object property.");
9676
+ }
9677
+ await context.setProperty(reference.object, reference.key, value);
9678
+ return { ok: true };
9679
+ }
9680
+ async function prepareMemberReference(pattern, context) {
9645
9681
  const object = await context.evaluate(pattern.object);
9646
9682
  if (object.kind !== "normal") {
9647
9683
  return { ok: false, result: object };
@@ -9650,14 +9686,10 @@ async function bindMemberExpression(pattern, value, scope, context) {
9650
9686
  if (property.kind !== "normal") {
9651
9687
  return { ok: false, result: property };
9652
9688
  }
9653
- if (object.value === null || object.value === void 0) {
9654
- throw new TypeError("Cannot assign properties of null or undefined.");
9655
- }
9656
- if (!isIndexableValue(object.value)) {
9657
- throw new TypeError("Assignment expressions require a sandbox object property.");
9658
- }
9659
- await context.setProperty(object.value, await context.toPropertyKey(property.value), value);
9660
- return { ok: true };
9689
+ return {
9690
+ ok: true,
9691
+ reference: { object: object.value, key: await context.toPropertyKey(property.value) }
9692
+ };
9661
9693
  }
9662
9694
  async function evaluatePatternKey(property, context) {
9663
9695
  return property.computed ? evaluateProperty(property.key, context) : { ok: true, value: getStaticPropertyName(property.key) };
@@ -15992,42 +16024,47 @@ function applyBinaryOperator(node, left, right, context) {
15992
16024
  case ">>>":
15993
16025
  return toNumber(left) >>> toNumber(right);
15994
16026
  case "instanceof":
15995
- while (isSandboxClosure(right) && right.boundTarget !== void 0) right = right.boundTarget;
15996
- if (isSandboxPromiseConstructor(right)) return isSandboxPromise(left);
15997
- if (isSandboxMapConstructor(right) && isSandboxMap(left)) {
15998
- return true;
15999
- }
16000
- if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
16001
- if (isDateConstructor(right))
16002
- return isSandboxDate(left) && getDatePrototype(left, context.budget, context.compilation?.owner) !== null;
16003
- if (isSandboxSetConstructor(right) && isSandboxSet(left)) {
16004
- return true;
16005
- }
16006
- if (isSandboxErrorConstructorInstance2(left, right)) {
16007
- return true;
16008
- }
16009
- if (isGuestClosure(right)) {
16010
- if (typeof left !== "object" || left === null) return false;
16011
- const check = (prototype2) => {
16012
- if (typeof prototype2 !== "object" || prototype2 === null) {
16013
- throw new TypeError("Function has a non-object prototype in instanceof check.");
16014
- }
16015
- let depth = 0;
16016
- for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
16017
- context.budget.visitNode();
16018
- assertSandboxDataDepth(depth++);
16019
- if (current === prototype2) return true;
16020
- }
16021
- return false;
16022
- };
16023
- const prototype = getPropertyValue(right, "prototype", context);
16024
- return prototype instanceof Promise ? prototype.then(check) : check(prototype);
16025
- }
16026
- return false;
16027
+ return evaluateInstanceof(left, right, context);
16027
16028
  case "in":
16028
16029
  return hasSandboxProperty(right, left, context);
16029
16030
  }
16030
16031
  }
16032
+ async function evaluateInstanceof(left, right, context) {
16033
+ while (true) {
16034
+ if (right === null || typeof right !== "object" && typeof right !== "function")
16035
+ throw new TypeError("Right-hand side of 'instanceof' must be an object.");
16036
+ const method = await getPropertyValue(right, Symbol.hasInstance, context);
16037
+ if (method !== void 0 && method !== null) {
16038
+ if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
16039
+ return Boolean(await invokeSandboxClosure(method, [left], context, context.callStack, void 0, right));
16040
+ }
16041
+ if (!isSandboxClosure(right))
16042
+ throw new TypeError("Right-hand side of 'instanceof' is not a function.");
16043
+ if (right.boundTarget === void 0) break;
16044
+ context.budget.visitNode();
16045
+ right = right.boundTarget;
16046
+ }
16047
+ if (isSandboxPromiseConstructor(right)) return isSandboxPromise(left);
16048
+ if (isSandboxMapConstructor(right) && isSandboxMap(left)) return true;
16049
+ if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
16050
+ if (isDateConstructor(right))
16051
+ return isSandboxDate(left) && getDatePrototype(left, context.budget, context.compilation?.owner) !== null;
16052
+ if (isSandboxSetConstructor(right) && isSandboxSet(left)) return true;
16053
+ if (isSandboxErrorConstructorInstance2(left, right)) return true;
16054
+ if (isGuestClosure(right)) {
16055
+ if (typeof left !== "object" || left === null) return false;
16056
+ const prototype = await getPropertyValue(right, "prototype", context);
16057
+ if (typeof prototype !== "object" || prototype === null)
16058
+ throw new TypeError("Function has a non-object prototype in instanceof check.");
16059
+ let depth = 0;
16060
+ for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
16061
+ context.budget.visitNode();
16062
+ assertSandboxDataDepth(depth++);
16063
+ if (current === prototype) return true;
16064
+ }
16065
+ }
16066
+ return false;
16067
+ }
16031
16068
  function createCoercionContext(context) {
16032
16069
  return {
16033
16070
  stack: context.callStack,
@@ -35896,4 +35933,4 @@ export {
35896
35933
  FileSnapshotBackend,
35897
35934
  run
35898
35935
  };
35899
- //# sourceMappingURL=chunk-VHZYRV5Q.js.map
35936
+ //# sourceMappingURL=chunk-LVK2NO45.js.map