poe-code 14.0.41 → 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);
@@ -146384,7 +146448,7 @@ async function evaluateBinaryExpression(node, context) {
146384
146448
  if (typeof right.value !== "object" || right.value === null) {
146385
146449
  throw new TypeError("Right-hand side of 'in' must be an object.");
146386
146450
  }
146387
- leftValue = await toPropertyKey(leftValue, context);
146451
+ leftValue = await toPropertyKey(leftValue, context.budget, createCoercionContext(context));
146388
146452
  }
146389
146453
  const value = applyBinaryOperator(node, leftValue, right.value, context);
146390
146454
  return {
@@ -146474,7 +146538,15 @@ async function evaluateMemberAssignmentExpression(node, context) {
146474
146538
  if (member.kind === "nullish") {
146475
146539
  throw new TypeError("Cannot assign properties of null or undefined.");
146476
146540
  }
146477
- 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
+ }
146478
146550
  if (node.operator === "&&=" && !isTruthy(current)) {
146479
146551
  return {
146480
146552
  kind: "normal",
@@ -146501,7 +146573,11 @@ async function evaluateMemberAssignmentExpression(node, context) {
146501
146573
  return right;
146502
146574
  }
146503
146575
  const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
146504
- 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);
146505
146581
  return {
146506
146582
  kind: "normal",
146507
146583
  hasValue: true,
@@ -147440,7 +147516,10 @@ async function evaluateThrowStatement2(node, context) {
147440
147516
  return evaluateThrowStatement(node, context, evaluateNode2);
147441
147517
  }
147442
147518
  async function evaluateTryStatement2(node, context) {
147443
- return evaluateTryStatement(node, context, evaluateNode2);
147519
+ return evaluateTryStatement(node, {
147520
+ ...context,
147521
+ toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(context))
147522
+ }, evaluateNode2);
147444
147523
  }
147445
147524
  async function evaluateUnaryExpression(node, context) {
147446
147525
  if (node.operator === "delete") {
@@ -147485,8 +147564,8 @@ async function evaluateDeleteExpression(node, context) {
147485
147564
  if (member.kind === "completion") {
147486
147565
  return member.result;
147487
147566
  }
147488
- if (member.kind === "nullish") {
147489
- if (node.argument.optional) {
147567
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
147568
+ if (member.kind === "nullish" && node.argument.optional) {
147490
147569
  return {
147491
147570
  kind: "normal",
147492
147571
  hasValue: true,
@@ -147498,7 +147577,8 @@ async function evaluateDeleteExpression(node, context) {
147498
147577
  if (!isIndexableSandboxValue(member.object)) {
147499
147578
  throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
147500
147579
  }
147501
- 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);
147502
147582
  return {
147503
147583
  kind: "normal",
147504
147584
  hasValue: true,
@@ -147546,14 +147626,15 @@ async function evaluateMemberUpdateExpression(node, context) {
147546
147626
  if (member.kind === "completion") {
147547
147627
  return member.result;
147548
147628
  }
147549
- if (member.kind === "nullish") {
147629
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
147550
147630
  throw new TypeError("Cannot update properties of null or undefined.");
147551
147631
  }
147632
+ const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
147552
147633
  const current = toNumber(
147553
- await toNumericPrimitive(getPropertyValue(member.object, member.property, context), context)
147634
+ await toNumericPrimitive(getPropertyValue(member.object, property, context), context)
147554
147635
  );
147555
147636
  const next = node.operator === "++" ? current + 1 : current - 1;
147556
- setSandboxProperty(member.object, member.property, next, context.budget);
147637
+ setSandboxProperty(member.object, property, next, context.budget);
147557
147638
  return {
147558
147639
  kind: "normal",
147559
147640
  hasValue: true,
@@ -147564,14 +147645,14 @@ async function evaluateMemberExpression(node, context) {
147564
147645
  const member = await evaluateMemberAccess(node, context);
147565
147646
  if (member.kind === "error") return member;
147566
147647
  if (member.kind === "completion") return member.result;
147567
- if (member.kind === "nullish") {
147568
- 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 };
147569
147650
  throw new TypeError("Cannot read properties of null or undefined.");
147570
147651
  }
147571
147652
  return {
147572
147653
  kind: "normal",
147573
147654
  hasValue: true,
147574
- value: getPropertyValue(member.object, member.property, context)
147655
+ value: getPropertyValue(member.object, await toPropertyKey(member.property, context.budget, createCoercionContext(context)), context)
147575
147656
  };
147576
147657
  }
147577
147658
  function getPropertyValue(target, property, context) {
@@ -147596,6 +147677,7 @@ function createPatternContext(context, scope = context.scope, evaluate = evaluat
147596
147677
  const evaluationContext = { ...context, scope };
147597
147678
  return {
147598
147679
  evaluate: (node) => evaluate(node, evaluationContext),
147680
+ toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(evaluationContext)),
147599
147681
  getProperty: (value, key3) => getPropertyValue(value, key3, evaluationContext),
147600
147682
  setProperty: (target, key3, value) => setSandboxProperty(target, key3, value, context.budget)
147601
147683
  };
@@ -147690,21 +147772,8 @@ async function evaluateMemberAccess(node, context) {
147690
147772
  kind: "nullish"
147691
147773
  };
147692
147774
  }
147693
- const property = node.computed ? await evaluateMemberProperty(node.property, context) : { ok: true, value: getStaticPropertyName2(node.property) };
147694
- if (!property.ok) {
147695
- return property.result.kind === "error" ? {
147696
- kind: "error",
147697
- error: property.result.error
147698
- } : {
147699
- kind: "completion",
147700
- result: property.result
147701
- };
147702
- }
147703
- if (object.value === null || object.value === void 0) {
147704
- return {
147705
- kind: "nullish"
147706
- };
147707
- }
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 };
147708
147777
  return {
147709
147778
  kind: "resolved",
147710
147779
  object: object.value,
@@ -147719,13 +147788,10 @@ async function evaluateMemberProperty(node, context) {
147719
147788
  result: property
147720
147789
  };
147721
147790
  }
147722
- if (typeof property.value === "string" || typeof property.value === "number") {
147723
- return {
147724
- ok: true,
147725
- value: property.value
147726
- };
147727
- }
147728
- 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
+ };
147729
147795
  }
147730
147796
  async function evaluateObjectPropertyKey(node, context) {
147731
147797
  if (!node.computed) {
@@ -147749,15 +147815,15 @@ async function evaluateMemberCallExpression(node, context) {
147749
147815
  if (node.callee.type !== "MemberExpression") {
147750
147816
  throw new TypeError("Expected member call expression.");
147751
147817
  }
147752
- const member = await evaluateMemberAccess(node.callee, context);
147753
- if (member.kind === "error") {
147754
- return member;
147818
+ const reference = await evaluateMemberAccess(node.callee, context);
147819
+ if (reference.kind === "error") {
147820
+ return reference;
147755
147821
  }
147756
- if (member.kind === "completion") {
147757
- return member.result;
147822
+ if (reference.kind === "completion") {
147823
+ return reference.result;
147758
147824
  }
147759
- if (member.kind === "nullish") {
147760
- if (node.optional || node.callee.optional) {
147825
+ if (reference.kind === "nullish" || reference.object === null || reference.object === void 0) {
147826
+ if (reference.kind === "nullish") {
147761
147827
  return {
147762
147828
  kind: "normal",
147763
147829
  hasValue: true,
@@ -147766,6 +147832,10 @@ async function evaluateMemberCallExpression(node, context) {
147766
147832
  }
147767
147833
  throw new TypeError("Cannot read properties of null or undefined.");
147768
147834
  }
147835
+ const member = {
147836
+ ...reference,
147837
+ property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
147838
+ };
147769
147839
  if (typeof member.object === "string" && isStringMethodName(member.property)) {
147770
147840
  return evaluateStringMethodCall(node, member.object, member.property, context);
147771
147841
  }
@@ -148097,23 +148167,13 @@ function applyBinaryOperator(node, left, right, context) {
148097
148167
  return hasSandboxProperty(right, left, context);
148098
148168
  }
148099
148169
  }
148100
- async function toPropertyKey(value, context) {
148101
- if (isPlainSandboxObject(value) && !isSandboxDate(value) && !isFloat32Array(value) && !isSandboxGenerator(value) && !isGuestHostObject(value)) {
148102
- for (const name of ["toString", "valueOf"]) {
148103
- const method = getMemberValue(value, name, context);
148104
- if (!isSandboxClosure(method)) continue;
148105
- const primitive = await invokeSandboxClosure(method, [], context, context.callStack, void 0, value);
148106
- if (primitive === null || typeof primitive !== "object") {
148107
- return context.budget.allocateString(String(primitive));
148108
- }
148109
- }
148110
- throw new TypeError("Cannot convert object to primitive value.");
148111
- }
148112
- return sandboxString(value, context.budget, {
148170
+ function createCoercionContext(context) {
148171
+ return {
148113
148172
  stack: context.callStack,
148114
148173
  thisValue: void 0,
148174
+ compilation: context.compilation,
148115
148175
  invokeClosure: (closure, args, thisValue) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue)
148116
- });
148176
+ };
148117
148177
  }
148118
148178
  function hasSandboxProperty(value, key3, context) {
148119
148179
  let current = value;
@@ -148662,7 +148722,7 @@ var init_interpreter = __esm({
148662
148722
  "use strict";
148663
148723
  init_promise_replay();
148664
148724
  init_host_capabilities();
148665
- init_string_coercion();
148725
+ init_property_key();
148666
148726
  init_promise_tracker();
148667
148727
  init_jobs4();
148668
148728
  init_cancel2();