poe-code 14.0.40 → 14.0.42

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.
package/dist/index.js CHANGED
@@ -128047,6 +128047,139 @@ var init_host_call = __esm({
128047
128047
  }
128048
128048
  });
128049
128049
 
128050
+ // packages/safe-js/src/interp/string-coercion.ts
128051
+ function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
128052
+ if (value === null || typeof value !== "object") {
128053
+ if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
128054
+ return budget.allocateString(String(value));
128055
+ }
128056
+ return stringifyObject(value, budget, context, joining);
128057
+ }
128058
+ async function stringifyObject(value, budget, context, joining) {
128059
+ const leaveCall = budget.enterCall();
128060
+ try {
128061
+ budget.visitNode();
128062
+ for (const name of ["toString", "valueOf"]) {
128063
+ const descriptor = Object.getOwnPropertyDescriptor(value, name);
128064
+ let result;
128065
+ if (descriptor === void 0) {
128066
+ if (name === "valueOf") continue;
128067
+ result = await defaultToString(value, budget, context, joining);
128068
+ } else {
128069
+ const hook = ownDataValue(value, name);
128070
+ if (!isSandboxClosure(hook)) continue;
128071
+ if (context?.invokeClosure === void 0) {
128072
+ throw new TypeError("String hooks require a sandbox call context.");
128073
+ }
128074
+ result = await context.invokeClosure(hook, [], value);
128075
+ }
128076
+ if (result === null || typeof result !== "object") {
128077
+ return sandboxString(result, budget, context, joining);
128078
+ }
128079
+ }
128080
+ throw new TypeError("Cannot convert object to primitive value");
128081
+ } finally {
128082
+ leaveCall();
128083
+ }
128084
+ }
128085
+ async function defaultToString(value, budget, context, joining) {
128086
+ if (isSandboxDate(value)) return budget.allocateString(dateString(value));
128087
+ if (Array.isArray(value) || isFloat32Array(value)) {
128088
+ if (Object.hasOwn(value, "join")) {
128089
+ const join21 = ownDataValue(value, "join");
128090
+ if (!isSandboxClosure(join21))
128091
+ return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
128092
+ if (context?.invokeClosure === void 0) {
128093
+ throw new TypeError("String hooks require a sandbox call context.");
128094
+ }
128095
+ return context.invokeClosure(join21, [], value);
128096
+ }
128097
+ if (joining.has(value)) return "";
128098
+ joining.add(value);
128099
+ try {
128100
+ const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
128101
+ let text5 = "";
128102
+ for (let index = 0; index < length; index++) {
128103
+ budget.visitNode();
128104
+ const element = ownDataValue(value, String(index));
128105
+ const part = element === null || element === void 0 ? "" : await sandboxString(element, budget, context, joining);
128106
+ text5 = budget.allocateString(text5 + (index === 0 ? "" : ",") + part);
128107
+ }
128108
+ return text5;
128109
+ } finally {
128110
+ joining.delete(value);
128111
+ }
128112
+ }
128113
+ if (sandboxErrorTypes.has(value)) {
128114
+ const nameValue = ownDataValue(value, "name");
128115
+ const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
128116
+ const messageValue2 = ownDataValue(value, "message");
128117
+ const message2 = messageValue2 === void 0 ? "" : await sandboxString(messageValue2, budget, context, joining);
128118
+ return name === "" ? message2 : message2 === "" ? name : `${name}: ${message2}`;
128119
+ }
128120
+ return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
128121
+ }
128122
+ function ownDataValue(value, name) {
128123
+ const descriptor = Object.getOwnPropertyDescriptor(value, name);
128124
+ if (descriptor !== void 0 && !Object.hasOwn(descriptor, "value")) {
128125
+ throw new TypeError("String conversion requires sandbox data properties.");
128126
+ }
128127
+ return descriptor?.value;
128128
+ }
128129
+ var init_string_coercion = __esm({
128130
+ "packages/safe-js/src/interp/string-coercion.ts"() {
128131
+ "use strict";
128132
+ init_shape();
128133
+ init_date();
128134
+ init_float32();
128135
+ init_values();
128136
+ }
128137
+ });
128138
+
128139
+ // packages/safe-js/src/interp/property-key.ts
128140
+ async function toPropertyKey(value, budget, context) {
128141
+ if (typeof value === "string") return value;
128142
+ const invocation = context.invokeClosure === void 0 ? {
128143
+ ...context,
128144
+ invokeClosure: async (closure, args, thisValue) => {
128145
+ const leaveCall = budget.enterCall();
128146
+ try {
128147
+ const result = closure.call(args, { ...invocation, thisValue });
128148
+ if (isSandboxPromise(result)) {
128149
+ await result.synchronousPrefix;
128150
+ return result;
128151
+ }
128152
+ return await result;
128153
+ } finally {
128154
+ leaveCall();
128155
+ }
128156
+ }
128157
+ } : context;
128158
+ if (typeof value === "object" && value !== null && !Array.isArray(value) && !isSandboxClosure(value) && !isSandboxMap(value) && !isSandboxSet(value) && !isSandboxPromise(value) && !isSandboxRegex(value) && !isSandboxDate(value) && !isFloat32Array(value) && !isSandboxGenerator(value) && !isGuestHostObject(value)) {
128159
+ for (const name of ["toString", "valueOf"]) {
128160
+ const method = getSandboxDataProperty(value, name, budget);
128161
+ if (!isSandboxClosure(method)) continue;
128162
+ const primitive = await invocation.invokeClosure(method, [], value);
128163
+ if (primitive === null || typeof primitive !== "object") {
128164
+ return budget.allocateString(String(primitive));
128165
+ }
128166
+ }
128167
+ throw new TypeError("Cannot convert object to primitive value.");
128168
+ }
128169
+ return sandboxString(value, budget, invocation);
128170
+ }
128171
+ var init_property_key = __esm({
128172
+ "packages/safe-js/src/interp/property-key.ts"() {
128173
+ "use strict";
128174
+ init_date();
128175
+ init_float32();
128176
+ init_host_capabilities();
128177
+ init_object_model();
128178
+ init_string_coercion();
128179
+ init_values();
128180
+ }
128181
+ });
128182
+
128050
128183
  // packages/safe-js/src/interp/exceptions.ts
128051
128184
  async function evaluateThrowStatement(node, context, evaluateNode3) {
128052
128185
  const argument = await evaluateNode3(node.argument, context);
@@ -128436,12 +128569,13 @@ async function resolvePatternPropertyKey(property, context, evaluateNode3) {
128436
128569
  result: computedKey
128437
128570
  };
128438
128571
  }
128439
- if (typeof computedKey.value !== "string" && typeof computedKey.value !== "number") {
128440
- throw new TypeError("Computed catch binding keys must evaluate to a string or number.");
128441
- }
128442
128572
  return {
128443
128573
  ok: true,
128444
- value: computedKey.value
128574
+ value: await (context.toPropertyKey?.(computedKey.value) ?? toPropertyKey(
128575
+ computedKey.value,
128576
+ context.budget,
128577
+ { stack: context.callStack, thisValue: void 0 }
128578
+ ))
128445
128579
  };
128446
128580
  }
128447
128581
  function getStaticPropertyKey(property) {
@@ -128477,6 +128611,7 @@ var init_exceptions = __esm({
128477
128611
  init_host_call();
128478
128612
  init_promise_tracker();
128479
128613
  init_values();
128614
+ init_property_key();
128480
128615
  capturedExceptionBrand = /* @__PURE__ */ Symbol("CapturedException");
128481
128616
  }
128482
128617
  });
@@ -130610,6 +130745,27 @@ function getSandboxPrototype(value, budget) {
130610
130745
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
130611
130746
  return budget !== void 0 && isPrototypeRecord(value) ? intrinsicPrototypes.get(budget) ?? null : null;
130612
130747
  }
130748
+ function getSandboxDataProperty(value, key3, budget) {
130749
+ let current = value;
130750
+ let depth = 0;
130751
+ while (typeof current === "object" && current !== null) {
130752
+ if (isGuestHostObject(current)) return getHostObjectMember(current, String(key3));
130753
+ if (isGuestClosure(current)) return getGuestFunctionProperty(current, String(key3));
130754
+ if (isSandboxClosure(current)) {
130755
+ const properties = current.properties;
130756
+ return properties !== void 0 && Object.hasOwn(properties, String(key3)) ? properties[String(key3)] : void 0;
130757
+ }
130758
+ if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxGenerator(current))
130759
+ return void 0;
130760
+ if (Object.hasOwn(current, String(key3))) return current[String(key3)];
130761
+ current = getSandboxPrototype(current, budget);
130762
+ if (current !== null) {
130763
+ budget?.visitNode();
130764
+ assertSandboxDataDepth(++depth);
130765
+ }
130766
+ }
130767
+ return void 0;
130768
+ }
130613
130769
  function setSandboxPrototype(value, prototype, budget) {
130614
130770
  if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
130615
130771
  throw new TypeError("Object.prototype has an immutable null prototype.");
@@ -143153,17 +143309,17 @@ async function bindMemberExpression(pattern, value, scope, context) {
143153
143309
  if (object.kind !== "normal") {
143154
143310
  return { ok: false, result: object };
143155
143311
  }
143312
+ const property = pattern.computed ? await context.evaluate(pattern.property) : { kind: "normal", value: getStaticPropertyName(pattern.property) };
143313
+ if (property.kind !== "normal") {
143314
+ return { ok: false, result: property };
143315
+ }
143156
143316
  if (object.value === null || object.value === void 0) {
143157
143317
  throw new TypeError("Cannot assign properties of null or undefined.");
143158
143318
  }
143159
143319
  if (!isIndexableValue(object.value)) {
143160
143320
  throw new TypeError("Assignment expressions require a sandbox object property.");
143161
143321
  }
143162
- const property = pattern.computed ? await evaluateProperty(pattern.property, context) : { ok: true, value: getStaticPropertyName(pattern.property) };
143163
- if (!property.ok) {
143164
- return property;
143165
- }
143166
- context.setProperty(object.value, property.value, value);
143322
+ context.setProperty(object.value, await context.toPropertyKey(property.value), value);
143167
143323
  return { ok: true };
143168
143324
  }
143169
143325
  async function evaluatePatternKey(property, context) {
@@ -143174,10 +143330,7 @@ async function evaluateProperty(property, context) {
143174
143330
  if (result.kind !== "normal") {
143175
143331
  return { ok: false, result };
143176
143332
  }
143177
- if (typeof result.value !== "string" && typeof result.value !== "number") {
143178
- throw new TypeError("Computed property access requires a string or number key.");
143179
- }
143180
- return { ok: true, value: result.value };
143333
+ return { ok: true, value: await context.toPropertyKey(result.value) };
143181
143334
  }
143182
143335
  function getStaticPropertyName(property) {
143183
143336
  if (property.type === "Identifier") {
@@ -143261,95 +143414,6 @@ var init_var_hoist = __esm({
143261
143414
  }
143262
143415
  });
143263
143416
 
143264
- // packages/safe-js/src/interp/string-coercion.ts
143265
- function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
143266
- if (value === null || typeof value !== "object") {
143267
- if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
143268
- return budget.allocateString(String(value));
143269
- }
143270
- return stringifyObject(value, budget, context, joining);
143271
- }
143272
- async function stringifyObject(value, budget, context, joining) {
143273
- const leaveCall = budget.enterCall();
143274
- try {
143275
- budget.visitNode();
143276
- for (const name of ["toString", "valueOf"]) {
143277
- const descriptor = Object.getOwnPropertyDescriptor(value, name);
143278
- let result;
143279
- if (descriptor === void 0) {
143280
- if (name === "valueOf") continue;
143281
- result = await defaultToString(value, budget, context, joining);
143282
- } else {
143283
- const hook = ownDataValue(value, name);
143284
- if (!isSandboxClosure(hook)) continue;
143285
- if (context?.invokeClosure === void 0) {
143286
- throw new TypeError("String hooks require a sandbox call context.");
143287
- }
143288
- result = await context.invokeClosure(hook, [], value);
143289
- }
143290
- if (result === null || typeof result !== "object") {
143291
- return sandboxString(result, budget, context, joining);
143292
- }
143293
- }
143294
- throw new TypeError("Cannot convert object to primitive value");
143295
- } finally {
143296
- leaveCall();
143297
- }
143298
- }
143299
- async function defaultToString(value, budget, context, joining) {
143300
- if (isSandboxDate(value)) return budget.allocateString(dateString(value));
143301
- if (Array.isArray(value) || isFloat32Array(value)) {
143302
- if (Object.hasOwn(value, "join")) {
143303
- const join21 = ownDataValue(value, "join");
143304
- if (!isSandboxClosure(join21))
143305
- return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
143306
- if (context?.invokeClosure === void 0) {
143307
- throw new TypeError("String hooks require a sandbox call context.");
143308
- }
143309
- return context.invokeClosure(join21, [], value);
143310
- }
143311
- if (joining.has(value)) return "";
143312
- joining.add(value);
143313
- try {
143314
- const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
143315
- let text5 = "";
143316
- for (let index = 0; index < length; index++) {
143317
- budget.visitNode();
143318
- const element = ownDataValue(value, String(index));
143319
- const part = element === null || element === void 0 ? "" : await sandboxString(element, budget, context, joining);
143320
- text5 = budget.allocateString(text5 + (index === 0 ? "" : ",") + part);
143321
- }
143322
- return text5;
143323
- } finally {
143324
- joining.delete(value);
143325
- }
143326
- }
143327
- if (sandboxErrorTypes.has(value)) {
143328
- const nameValue = ownDataValue(value, "name");
143329
- const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
143330
- const messageValue2 = ownDataValue(value, "message");
143331
- const message2 = messageValue2 === void 0 ? "" : await sandboxString(messageValue2, budget, context, joining);
143332
- return name === "" ? message2 : message2 === "" ? name : `${name}: ${message2}`;
143333
- }
143334
- return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
143335
- }
143336
- function ownDataValue(value, name) {
143337
- const descriptor = Object.getOwnPropertyDescriptor(value, name);
143338
- if (descriptor !== void 0 && !Object.hasOwn(descriptor, "value")) {
143339
- throw new TypeError("String conversion requires sandbox data properties.");
143340
- }
143341
- return descriptor?.value;
143342
- }
143343
- var init_string_coercion = __esm({
143344
- "packages/safe-js/src/interp/string-coercion.ts"() {
143345
- "use strict";
143346
- init_shape();
143347
- init_date();
143348
- init_float32();
143349
- init_values();
143350
- }
143351
- });
143352
-
143353
143417
  // packages/safe-js/src/interp/methods/array.ts
143354
143418
  function getArrayMember(value, property, options) {
143355
143419
  const index = getArrayIndex(property);
@@ -146007,6 +146071,7 @@ async function interpret(node, options = {}) {
146007
146071
  budget,
146008
146072
  callStack: [],
146009
146073
  onYield: options.onYield,
146074
+ onSuspend: options.onSuspend,
146010
146075
  captureReplayState: options.captureReplayState,
146011
146076
  rootNode: node,
146012
146077
  scope,
@@ -146383,7 +146448,7 @@ async function evaluateBinaryExpression(node, context) {
146383
146448
  if (typeof right.value !== "object" || right.value === null) {
146384
146449
  throw new TypeError("Right-hand side of 'in' must be an object.");
146385
146450
  }
146386
- leftValue = await toPropertyKey(leftValue, context);
146451
+ leftValue = await toPropertyKey(leftValue, context.budget, createCoercionContext(context));
146387
146452
  }
146388
146453
  const value = applyBinaryOperator(node, leftValue, right.value, context);
146389
146454
  return {
@@ -146473,7 +146538,15 @@ async function evaluateMemberAssignmentExpression(node, context) {
146473
146538
  if (member.kind === "nullish") {
146474
146539
  throw new TypeError("Cannot assign properties of null or undefined.");
146475
146540
  }
146476
- const current = node.operator === "=" ? void 0 : getPropertyValue(member.object, member.property, context);
146541
+ let property;
146542
+ let current = void 0;
146543
+ if (node.operator !== "=") {
146544
+ if (member.object === null || member.object === void 0) {
146545
+ throw new TypeError("Cannot assign properties of null or undefined.");
146546
+ }
146547
+ property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
146548
+ current = getPropertyValue(member.object, property, context);
146549
+ }
146477
146550
  if (node.operator === "&&=" && !isTruthy(current)) {
146478
146551
  return {
146479
146552
  kind: "normal",
@@ -146500,7 +146573,11 @@ async function evaluateMemberAssignmentExpression(node, context) {
146500
146573
  return right;
146501
146574
  }
146502
146575
  const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
146503
- setSandboxProperty(member.object, member.property, value, context.budget);
146576
+ if (member.object === null || member.object === void 0) {
146577
+ throw new TypeError("Cannot assign properties of null or undefined.");
146578
+ }
146579
+ property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
146580
+ setSandboxProperty(member.object, property, value, context.budget);
146504
146581
  return {
146505
146582
  kind: "normal",
146506
146583
  hasValue: true,
@@ -147439,7 +147516,10 @@ async function evaluateThrowStatement2(node, context) {
147439
147516
  return evaluateThrowStatement(node, context, evaluateNode2);
147440
147517
  }
147441
147518
  async function evaluateTryStatement2(node, context) {
147442
- return evaluateTryStatement(node, context, evaluateNode2);
147519
+ return evaluateTryStatement(node, {
147520
+ ...context,
147521
+ toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(context))
147522
+ }, evaluateNode2);
147443
147523
  }
147444
147524
  async function evaluateUnaryExpression(node, context) {
147445
147525
  if (node.operator === "delete") {
@@ -147484,8 +147564,8 @@ async function evaluateDeleteExpression(node, context) {
147484
147564
  if (member.kind === "completion") {
147485
147565
  return member.result;
147486
147566
  }
147487
- if (member.kind === "nullish") {
147488
- if (node.argument.optional) {
147567
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
147568
+ if (member.kind === "nullish" && node.argument.optional) {
147489
147569
  return {
147490
147570
  kind: "normal",
147491
147571
  hasValue: true,
@@ -147497,7 +147577,8 @@ async function evaluateDeleteExpression(node, context) {
147497
147577
  if (!isIndexableSandboxValue(member.object)) {
147498
147578
  throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
147499
147579
  }
147500
- const deleted = deleteSandboxProperty(member.object, member.property);
147580
+ const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147581
+ const deleted = deleteSandboxProperty(member.object, property);
147501
147582
  return {
147502
147583
  kind: "normal",
147503
147584
  hasValue: true,
@@ -147545,14 +147626,15 @@ async function evaluateMemberUpdateExpression(node, context) {
147545
147626
  if (member.kind === "completion") {
147546
147627
  return member.result;
147547
147628
  }
147548
- if (member.kind === "nullish") {
147629
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
147549
147630
  throw new TypeError("Cannot update properties of null or undefined.");
147550
147631
  }
147632
+ const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147551
147633
  const current = toNumber(
147552
- await toNumericPrimitive(getPropertyValue(member.object, member.property, context), context)
147634
+ await toNumericPrimitive(getPropertyValue(member.object, property, context), context)
147553
147635
  );
147554
147636
  const next = node.operator === "++" ? current + 1 : current - 1;
147555
- setSandboxProperty(member.object, member.property, next, context.budget);
147637
+ setSandboxProperty(member.object, property, next, context.budget);
147556
147638
  return {
147557
147639
  kind: "normal",
147558
147640
  hasValue: true,
@@ -147563,14 +147645,14 @@ async function evaluateMemberExpression(node, context) {
147563
147645
  const member = await evaluateMemberAccess(node, context);
147564
147646
  if (member.kind === "error") return member;
147565
147647
  if (member.kind === "completion") return member.result;
147566
- if (member.kind === "nullish") {
147567
- if (node.optional) return { kind: "normal", hasValue: true, value: void 0 };
147648
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
147649
+ if (member.kind === "nullish" && node.optional) return { kind: "normal", hasValue: true, value: void 0 };
147568
147650
  throw new TypeError("Cannot read properties of null or undefined.");
147569
147651
  }
147570
147652
  return {
147571
147653
  kind: "normal",
147572
147654
  hasValue: true,
147573
- value: getPropertyValue(member.object, member.property, context)
147655
+ value: getPropertyValue(member.object, await toPropertyKey(member.property, context.budget, createCoercionContext(context)), context)
147574
147656
  };
147575
147657
  }
147576
147658
  function getPropertyValue(target, property, context) {
@@ -147595,6 +147677,7 @@ function createPatternContext(context, scope = context.scope, evaluate = evaluat
147595
147677
  const evaluationContext = { ...context, scope };
147596
147678
  return {
147597
147679
  evaluate: (node) => evaluate(node, evaluationContext),
147680
+ toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(evaluationContext)),
147598
147681
  getProperty: (value, key3) => getPropertyValue(value, key3, evaluationContext),
147599
147682
  setProperty: (target, key3, value) => setSandboxProperty(target, key3, value, context.budget)
147600
147683
  };
@@ -147689,21 +147772,8 @@ async function evaluateMemberAccess(node, context) {
147689
147772
  kind: "nullish"
147690
147773
  };
147691
147774
  }
147692
- const property = node.computed ? await evaluateMemberProperty(node.property, context) : { ok: true, value: getStaticPropertyName2(node.property) };
147693
- if (!property.ok) {
147694
- return property.result.kind === "error" ? {
147695
- kind: "error",
147696
- error: property.result.error
147697
- } : {
147698
- kind: "completion",
147699
- result: property.result
147700
- };
147701
- }
147702
- if (object.value === null || object.value === void 0) {
147703
- return {
147704
- kind: "nullish"
147705
- };
147706
- }
147775
+ const property = node.computed ? await evaluateNode2(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
147776
+ if (property.kind !== "normal") return { kind: "completion", result: property };
147707
147777
  return {
147708
147778
  kind: "resolved",
147709
147779
  object: object.value,
@@ -147718,13 +147788,10 @@ async function evaluateMemberProperty(node, context) {
147718
147788
  result: property
147719
147789
  };
147720
147790
  }
147721
- if (typeof property.value === "string" || typeof property.value === "number") {
147722
- return {
147723
- ok: true,
147724
- value: property.value
147725
- };
147726
- }
147727
- throw new TypeError("Computed property access requires a string or number key.");
147791
+ return {
147792
+ ok: true,
147793
+ value: await toPropertyKey(property.value, context.budget, createCoercionContext(context))
147794
+ };
147728
147795
  }
147729
147796
  async function evaluateObjectPropertyKey(node, context) {
147730
147797
  if (!node.computed) {
@@ -147748,15 +147815,15 @@ async function evaluateMemberCallExpression(node, context) {
147748
147815
  if (node.callee.type !== "MemberExpression") {
147749
147816
  throw new TypeError("Expected member call expression.");
147750
147817
  }
147751
- const member = await evaluateMemberAccess(node.callee, context);
147752
- if (member.kind === "error") {
147753
- return member;
147818
+ const reference = await evaluateMemberAccess(node.callee, context);
147819
+ if (reference.kind === "error") {
147820
+ return reference;
147754
147821
  }
147755
- if (member.kind === "completion") {
147756
- return member.result;
147822
+ if (reference.kind === "completion") {
147823
+ return reference.result;
147757
147824
  }
147758
- if (member.kind === "nullish") {
147759
- if (node.optional || node.callee.optional) {
147825
+ if (reference.kind === "nullish" || reference.object === null || reference.object === void 0) {
147826
+ if (reference.kind === "nullish") {
147760
147827
  return {
147761
147828
  kind: "normal",
147762
147829
  hasValue: true,
@@ -147765,6 +147832,10 @@ async function evaluateMemberCallExpression(node, context) {
147765
147832
  }
147766
147833
  throw new TypeError("Cannot read properties of null or undefined.");
147767
147834
  }
147835
+ const member = {
147836
+ ...reference,
147837
+ property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
147838
+ };
147768
147839
  if (typeof member.object === "string" && isStringMethodName(member.property)) {
147769
147840
  return evaluateStringMethodCall(node, member.object, member.property, context);
147770
147841
  }
@@ -148096,23 +148167,13 @@ function applyBinaryOperator(node, left, right, context) {
148096
148167
  return hasSandboxProperty(right, left, context);
148097
148168
  }
148098
148169
  }
148099
- async function toPropertyKey(value, context) {
148100
- if (isPlainSandboxObject(value) && !isSandboxDate(value) && !isFloat32Array(value) && !isSandboxGenerator(value) && !isGuestHostObject(value)) {
148101
- for (const name of ["toString", "valueOf"]) {
148102
- const method = getMemberValue(value, name, context);
148103
- if (!isSandboxClosure(method)) continue;
148104
- const primitive = await invokeSandboxClosure(method, [], context, context.callStack, void 0, value);
148105
- if (primitive === null || typeof primitive !== "object") {
148106
- return context.budget.allocateString(String(primitive));
148107
- }
148108
- }
148109
- throw new TypeError("Cannot convert object to primitive value.");
148110
- }
148111
- return sandboxString(value, context.budget, {
148170
+ function createCoercionContext(context) {
148171
+ return {
148112
148172
  stack: context.callStack,
148113
148173
  thisValue: void 0,
148174
+ compilation: context.compilation,
148114
148175
  invokeClosure: (closure, args, thisValue) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue)
148115
- });
148176
+ };
148116
148177
  }
148117
148178
  function hasSandboxProperty(value, key3, context) {
148118
148179
  let current = value;
@@ -148661,7 +148722,7 @@ var init_interpreter = __esm({
148661
148722
  "use strict";
148662
148723
  init_promise_replay();
148663
148724
  init_host_capabilities();
148664
- init_string_coercion();
148725
+ init_property_key();
148665
148726
  init_promise_tracker();
148666
148727
  init_jobs4();
148667
148728
  init_cancel2();
@@ -148818,44 +148879,51 @@ function createInterpretedClosure(node, context, evaluateNode3) {
148818
148879
  };
148819
148880
  if (!node.async)
148820
148881
  return executeClosure(node, args, callContext?.thisValue, invocationContext, evaluateNode3);
148821
- let completePrefix;
148822
- const synchronousPrefix = new Promise((resolve16) => {
148823
- completePrefix = resolve16;
148824
- });
148825
- const promise = new Promise((resolve16, reject) => {
148826
- runAsyncPrefix(async () => {
148827
- try {
148828
- const value = await executeClosure(
148829
- node,
148830
- args,
148831
- callContext?.thisValue,
148832
- { ...invocationContext, onSuspend: completePrefix },
148833
- evaluateNode3
148834
- );
148835
- resolve16(
148836
- isSandboxPromise(value) || getThenable(value) !== void 0 ? awaitSandboxValue(
148837
- createSandboxPromise(resolveSandboxValue(value, { budget: context.budget }), {
148838
- trackReplay: false
148839
- }),
148840
- context.signal,
148841
- context.budget
148842
- ) : allocateProducedSandboxValue(value, context.budget)
148843
- );
148844
- } catch (error3) {
148845
- reject(error3);
148846
- } finally {
148847
- completePrefix();
148848
- }
148849
- }).catch((error3) => {
148850
- reject(error3);
148851
- completePrefix();
148852
- });
148853
- });
148854
- return createSandboxPromise(promise, { synchronousPrefix });
148882
+ return executeAsyncFunction(
148883
+ (onSuspend) => executeClosure(
148884
+ node,
148885
+ args,
148886
+ callContext?.thisValue,
148887
+ { ...invocationContext, onSuspend },
148888
+ evaluateNode3
148889
+ ),
148890
+ context.budget,
148891
+ context.signal
148892
+ );
148855
148893
  }
148856
148894
  });
148857
148895
  return closure;
148858
148896
  }
148897
+ function executeAsyncFunction(execute2, budget, signal) {
148898
+ let completePrefix;
148899
+ const synchronousPrefix = new Promise((resolve16) => {
148900
+ completePrefix = resolve16;
148901
+ });
148902
+ const promise = new Promise((resolve16, reject) => {
148903
+ runAsyncPrefix(async () => {
148904
+ try {
148905
+ const value = await execute2(completePrefix);
148906
+ resolve16(
148907
+ isSandboxPromise(value) || getThenable(value) !== void 0 ? awaitSandboxValue(
148908
+ createSandboxPromise(resolveSandboxValue(value, { budget }), {
148909
+ trackReplay: false
148910
+ }),
148911
+ signal,
148912
+ budget
148913
+ ) : allocateProducedSandboxValue(value, budget)
148914
+ );
148915
+ } catch (error3) {
148916
+ reject(error3);
148917
+ } finally {
148918
+ completePrefix();
148919
+ }
148920
+ }).catch((error3) => {
148921
+ reject(error3);
148922
+ completePrefix();
148923
+ });
148924
+ });
148925
+ return createSandboxPromise(promise, { synchronousPrefix });
148926
+ }
148859
148927
  function createGeneratorClosure(node, context, evaluateNode3) {
148860
148928
  return createSandboxClosure({
148861
148929
  guest: true,