@poe-platform/safe-js 0.1.88 → 0.1.89

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-5J6BX3HD.js";
30
+ } from "./chunk-M4M56OCI.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8245,4 +8245,4 @@ export {
8245
8245
  parseMcpConfig,
8246
8246
  makeMcpModule
8247
8247
  };
8248
- //# sourceMappingURL=chunk-AD7V4BRD.js.map
8248
+ //# sourceMappingURL=chunk-KWV4LCEU.js.map
@@ -6997,6 +6997,27 @@ function getSandboxPrototype(value, budget) {
6997
6997
  if (prototypes.has(value)) return prototypes.get(value) ?? null;
6998
6998
  return budget !== void 0 && isPrototypeRecord(value) ? intrinsicPrototypes.get(budget) ?? null : null;
6999
6999
  }
7000
+ function getSandboxDataProperty(value, key, budget) {
7001
+ let current = value;
7002
+ let depth = 0;
7003
+ while (typeof current === "object" && current !== null) {
7004
+ if (isGuestHostObject(current)) return getHostObjectMember(current, String(key));
7005
+ if (isGuestClosure(current)) return getGuestFunctionProperty(current, String(key));
7006
+ if (isSandboxClosure(current)) {
7007
+ const properties = current.properties;
7008
+ return properties !== void 0 && Object.hasOwn(properties, String(key)) ? properties[String(key)] : void 0;
7009
+ }
7010
+ if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxGenerator(current))
7011
+ return void 0;
7012
+ if (Object.hasOwn(current, String(key))) return current[String(key)];
7013
+ current = getSandboxPrototype(current, budget);
7014
+ if (current !== null) {
7015
+ budget?.visitNode();
7016
+ assertSandboxDataDepth(++depth);
7017
+ }
7018
+ }
7019
+ return void 0;
7020
+ }
7000
7021
  function setSandboxPrototype(value, prototype, budget) {
7001
7022
  if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
7002
7023
  throw new TypeError("Object.prototype has an immutable null prototype.");
@@ -8157,6 +8178,119 @@ function isCounter(value) {
8157
8178
  // packages/safe-js/src/interp/cancel.ts
8158
8179
  import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
8159
8180
 
8181
+ // packages/safe-js/src/interp/string-coercion.ts
8182
+ function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
8183
+ if (value === null || typeof value !== "object") {
8184
+ if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
8185
+ return budget.allocateString(String(value));
8186
+ }
8187
+ return stringifyObject(value, budget, context, joining);
8188
+ }
8189
+ async function stringifyObject(value, budget, context, joining) {
8190
+ const leaveCall = budget.enterCall();
8191
+ try {
8192
+ budget.visitNode();
8193
+ for (const name of ["toString", "valueOf"]) {
8194
+ const descriptor = Object.getOwnPropertyDescriptor(value, name);
8195
+ let result;
8196
+ if (descriptor === void 0) {
8197
+ if (name === "valueOf") continue;
8198
+ result = await defaultToString(value, budget, context, joining);
8199
+ } else {
8200
+ const hook = ownDataValue(value, name);
8201
+ if (!isSandboxClosure(hook)) continue;
8202
+ if (context?.invokeClosure === void 0) {
8203
+ throw new TypeError("String hooks require a sandbox call context.");
8204
+ }
8205
+ result = await context.invokeClosure(hook, [], value);
8206
+ }
8207
+ if (result === null || typeof result !== "object") {
8208
+ return sandboxString(result, budget, context, joining);
8209
+ }
8210
+ }
8211
+ throw new TypeError("Cannot convert object to primitive value");
8212
+ } finally {
8213
+ leaveCall();
8214
+ }
8215
+ }
8216
+ async function defaultToString(value, budget, context, joining) {
8217
+ if (isSandboxDate(value)) return budget.allocateString(dateString(value));
8218
+ if (Array.isArray(value) || isFloat32Array(value)) {
8219
+ if (Object.hasOwn(value, "join")) {
8220
+ const join = ownDataValue(value, "join");
8221
+ if (!isSandboxClosure(join))
8222
+ return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
8223
+ if (context?.invokeClosure === void 0) {
8224
+ throw new TypeError("String hooks require a sandbox call context.");
8225
+ }
8226
+ return context.invokeClosure(join, [], value);
8227
+ }
8228
+ if (joining.has(value)) return "";
8229
+ joining.add(value);
8230
+ try {
8231
+ const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
8232
+ let text = "";
8233
+ for (let index = 0; index < length; index++) {
8234
+ budget.visitNode();
8235
+ const element = ownDataValue(value, String(index));
8236
+ const part = element === null || element === void 0 ? "" : await sandboxString(element, budget, context, joining);
8237
+ text = budget.allocateString(text + (index === 0 ? "" : ",") + part);
8238
+ }
8239
+ return text;
8240
+ } finally {
8241
+ joining.delete(value);
8242
+ }
8243
+ }
8244
+ if (sandboxErrorTypes.has(value)) {
8245
+ const nameValue = ownDataValue(value, "name");
8246
+ const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
8247
+ const messageValue = ownDataValue(value, "message");
8248
+ const message = messageValue === void 0 ? "" : await sandboxString(messageValue, budget, context, joining);
8249
+ return name === "" ? message : message === "" ? name : `${name}: ${message}`;
8250
+ }
8251
+ return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
8252
+ }
8253
+ function ownDataValue(value, name) {
8254
+ const descriptor = Object.getOwnPropertyDescriptor(value, name);
8255
+ if (descriptor !== void 0 && !Object.hasOwn(descriptor, "value")) {
8256
+ throw new TypeError("String conversion requires sandbox data properties.");
8257
+ }
8258
+ return descriptor?.value;
8259
+ }
8260
+
8261
+ // packages/safe-js/src/interp/property-key.ts
8262
+ async function toPropertyKey(value, budget, context) {
8263
+ if (typeof value === "string") return value;
8264
+ const invocation = context.invokeClosure === void 0 ? {
8265
+ ...context,
8266
+ invokeClosure: async (closure, args, thisValue) => {
8267
+ const leaveCall = budget.enterCall();
8268
+ try {
8269
+ const result = closure.call(args, { ...invocation, thisValue });
8270
+ if (isSandboxPromise(result)) {
8271
+ await result.synchronousPrefix;
8272
+ return result;
8273
+ }
8274
+ return await result;
8275
+ } finally {
8276
+ leaveCall();
8277
+ }
8278
+ }
8279
+ } : context;
8280
+ 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)) {
8281
+ for (const name of ["toString", "valueOf"]) {
8282
+ const method = getSandboxDataProperty(value, name, budget);
8283
+ if (!isSandboxClosure(method)) continue;
8284
+ const primitive = await invocation.invokeClosure(method, [], value);
8285
+ if (primitive === null || typeof primitive !== "object") {
8286
+ return budget.allocateString(String(primitive));
8287
+ }
8288
+ }
8289
+ throw new TypeError("Cannot convert object to primitive value.");
8290
+ }
8291
+ return sandboxString(value, budget, invocation);
8292
+ }
8293
+
8160
8294
  // packages/safe-js/src/interp/exceptions.ts
8161
8295
  var capturedExceptionBrand = /* @__PURE__ */ Symbol("CapturedException");
8162
8296
  async function evaluateThrowStatement(node, context, evaluateNode2) {
@@ -8547,12 +8681,13 @@ async function resolvePatternPropertyKey(property, context, evaluateNode2) {
8547
8681
  result: computedKey
8548
8682
  };
8549
8683
  }
8550
- if (typeof computedKey.value !== "string" && typeof computedKey.value !== "number") {
8551
- throw new TypeError("Computed catch binding keys must evaluate to a string or number.");
8552
- }
8553
8684
  return {
8554
8685
  ok: true,
8555
- value: computedKey.value
8686
+ value: await (context.toPropertyKey?.(computedKey.value) ?? toPropertyKey(
8687
+ computedKey.value,
8688
+ context.budget,
8689
+ { stack: context.callStack, thisValue: void 0 }
8690
+ ))
8556
8691
  };
8557
8692
  }
8558
8693
  function getStaticPropertyKey(property) {
@@ -23089,17 +23224,17 @@ async function bindMemberExpression(pattern, value, scope, context) {
23089
23224
  if (object.kind !== "normal") {
23090
23225
  return { ok: false, result: object };
23091
23226
  }
23227
+ const property = pattern.computed ? await context.evaluate(pattern.property) : { kind: "normal", value: getStaticPropertyName(pattern.property) };
23228
+ if (property.kind !== "normal") {
23229
+ return { ok: false, result: property };
23230
+ }
23092
23231
  if (object.value === null || object.value === void 0) {
23093
23232
  throw new TypeError("Cannot assign properties of null or undefined.");
23094
23233
  }
23095
23234
  if (!isIndexableValue(object.value)) {
23096
23235
  throw new TypeError("Assignment expressions require a sandbox object property.");
23097
23236
  }
23098
- const property = pattern.computed ? await evaluateProperty(pattern.property, context) : { ok: true, value: getStaticPropertyName(pattern.property) };
23099
- if (!property.ok) {
23100
- return property;
23101
- }
23102
- context.setProperty(object.value, property.value, value);
23237
+ context.setProperty(object.value, await context.toPropertyKey(property.value), value);
23103
23238
  return { ok: true };
23104
23239
  }
23105
23240
  async function evaluatePatternKey(property, context) {
@@ -23110,10 +23245,7 @@ async function evaluateProperty(property, context) {
23110
23245
  if (result.kind !== "normal") {
23111
23246
  return { ok: false, result };
23112
23247
  }
23113
- if (typeof result.value !== "string" && typeof result.value !== "number") {
23114
- throw new TypeError("Computed property access requires a string or number key.");
23115
- }
23116
- return { ok: true, value: result.value };
23248
+ return { ok: true, value: await context.toPropertyKey(result.value) };
23117
23249
  }
23118
23250
  function getStaticPropertyName(property) {
23119
23251
  if (property.type === "Identifier") {
@@ -23185,86 +23317,6 @@ function hoistVarDeclarations(node, scope) {
23185
23317
  }
23186
23318
  }
23187
23319
 
23188
- // packages/safe-js/src/interp/string-coercion.ts
23189
- function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
23190
- if (value === null || typeof value !== "object") {
23191
- if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
23192
- return budget.allocateString(String(value));
23193
- }
23194
- return stringifyObject(value, budget, context, joining);
23195
- }
23196
- async function stringifyObject(value, budget, context, joining) {
23197
- const leaveCall = budget.enterCall();
23198
- try {
23199
- budget.visitNode();
23200
- for (const name of ["toString", "valueOf"]) {
23201
- const descriptor = Object.getOwnPropertyDescriptor(value, name);
23202
- let result;
23203
- if (descriptor === void 0) {
23204
- if (name === "valueOf") continue;
23205
- result = await defaultToString(value, budget, context, joining);
23206
- } else {
23207
- const hook = ownDataValue(value, name);
23208
- if (!isSandboxClosure(hook)) continue;
23209
- if (context?.invokeClosure === void 0) {
23210
- throw new TypeError("String hooks require a sandbox call context.");
23211
- }
23212
- result = await context.invokeClosure(hook, [], value);
23213
- }
23214
- if (result === null || typeof result !== "object") {
23215
- return sandboxString(result, budget, context, joining);
23216
- }
23217
- }
23218
- throw new TypeError("Cannot convert object to primitive value");
23219
- } finally {
23220
- leaveCall();
23221
- }
23222
- }
23223
- async function defaultToString(value, budget, context, joining) {
23224
- if (isSandboxDate(value)) return budget.allocateString(dateString(value));
23225
- if (Array.isArray(value) || isFloat32Array(value)) {
23226
- if (Object.hasOwn(value, "join")) {
23227
- const join = ownDataValue(value, "join");
23228
- if (!isSandboxClosure(join))
23229
- return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
23230
- if (context?.invokeClosure === void 0) {
23231
- throw new TypeError("String hooks require a sandbox call context.");
23232
- }
23233
- return context.invokeClosure(join, [], value);
23234
- }
23235
- if (joining.has(value)) return "";
23236
- joining.add(value);
23237
- try {
23238
- const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
23239
- let text = "";
23240
- for (let index = 0; index < length; index++) {
23241
- budget.visitNode();
23242
- const element = ownDataValue(value, String(index));
23243
- const part = element === null || element === void 0 ? "" : await sandboxString(element, budget, context, joining);
23244
- text = budget.allocateString(text + (index === 0 ? "" : ",") + part);
23245
- }
23246
- return text;
23247
- } finally {
23248
- joining.delete(value);
23249
- }
23250
- }
23251
- if (sandboxErrorTypes.has(value)) {
23252
- const nameValue = ownDataValue(value, "name");
23253
- const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
23254
- const messageValue = ownDataValue(value, "message");
23255
- const message = messageValue === void 0 ? "" : await sandboxString(messageValue, budget, context, joining);
23256
- return name === "" ? message : message === "" ? name : `${name}: ${message}`;
23257
- }
23258
- return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
23259
- }
23260
- function ownDataValue(value, name) {
23261
- const descriptor = Object.getOwnPropertyDescriptor(value, name);
23262
- if (descriptor !== void 0 && !Object.hasOwn(descriptor, "value")) {
23263
- throw new TypeError("String conversion requires sandbox data properties.");
23264
- }
23265
- return descriptor?.value;
23266
- }
23267
-
23268
23320
  // packages/safe-js/src/interp/methods/array.ts
23269
23321
  var activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
23270
23322
  var arrayMethodNames = /* @__PURE__ */ new Set([
@@ -26217,7 +26269,7 @@ async function evaluateBinaryExpression(node, context) {
26217
26269
  if (typeof right.value !== "object" || right.value === null) {
26218
26270
  throw new TypeError("Right-hand side of 'in' must be an object.");
26219
26271
  }
26220
- leftValue = await toPropertyKey(leftValue, context);
26272
+ leftValue = await toPropertyKey(leftValue, context.budget, createCoercionContext(context));
26221
26273
  }
26222
26274
  const value = applyBinaryOperator(node, leftValue, right.value, context);
26223
26275
  return {
@@ -26307,7 +26359,15 @@ async function evaluateMemberAssignmentExpression(node, context) {
26307
26359
  if (member.kind === "nullish") {
26308
26360
  throw new TypeError("Cannot assign properties of null or undefined.");
26309
26361
  }
26310
- const current = node.operator === "=" ? void 0 : getPropertyValue(member.object, member.property, context);
26362
+ let property;
26363
+ let current = void 0;
26364
+ if (node.operator !== "=") {
26365
+ if (member.object === null || member.object === void 0) {
26366
+ throw new TypeError("Cannot assign properties of null or undefined.");
26367
+ }
26368
+ property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
26369
+ current = getPropertyValue(member.object, property, context);
26370
+ }
26311
26371
  if (node.operator === "&&=" && !isTruthy(current)) {
26312
26372
  return {
26313
26373
  kind: "normal",
@@ -26334,7 +26394,11 @@ async function evaluateMemberAssignmentExpression(node, context) {
26334
26394
  return right;
26335
26395
  }
26336
26396
  const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
26337
- setSandboxProperty(member.object, member.property, value, context.budget);
26397
+ if (member.object === null || member.object === void 0) {
26398
+ throw new TypeError("Cannot assign properties of null or undefined.");
26399
+ }
26400
+ property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
26401
+ setSandboxProperty(member.object, property, value, context.budget);
26338
26402
  return {
26339
26403
  kind: "normal",
26340
26404
  hasValue: true,
@@ -27273,7 +27337,10 @@ async function evaluateThrowStatement2(node, context) {
27273
27337
  return evaluateThrowStatement(node, context, evaluateNode);
27274
27338
  }
27275
27339
  async function evaluateTryStatement2(node, context) {
27276
- return evaluateTryStatement(node, context, evaluateNode);
27340
+ return evaluateTryStatement(node, {
27341
+ ...context,
27342
+ toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(context))
27343
+ }, evaluateNode);
27277
27344
  }
27278
27345
  async function evaluateUnaryExpression(node, context) {
27279
27346
  if (node.operator === "delete") {
@@ -27318,8 +27385,8 @@ async function evaluateDeleteExpression(node, context) {
27318
27385
  if (member.kind === "completion") {
27319
27386
  return member.result;
27320
27387
  }
27321
- if (member.kind === "nullish") {
27322
- if (node.argument.optional) {
27388
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
27389
+ if (member.kind === "nullish" && node.argument.optional) {
27323
27390
  return {
27324
27391
  kind: "normal",
27325
27392
  hasValue: true,
@@ -27331,7 +27398,8 @@ async function evaluateDeleteExpression(node, context) {
27331
27398
  if (!isIndexableSandboxValue(member.object)) {
27332
27399
  throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
27333
27400
  }
27334
- const deleted = deleteSandboxProperty(member.object, member.property);
27401
+ const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
27402
+ const deleted = deleteSandboxProperty(member.object, property);
27335
27403
  return {
27336
27404
  kind: "normal",
27337
27405
  hasValue: true,
@@ -27379,14 +27447,15 @@ async function evaluateMemberUpdateExpression(node, context) {
27379
27447
  if (member.kind === "completion") {
27380
27448
  return member.result;
27381
27449
  }
27382
- if (member.kind === "nullish") {
27450
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
27383
27451
  throw new TypeError("Cannot update properties of null or undefined.");
27384
27452
  }
27453
+ const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
27385
27454
  const current = toNumber(
27386
- await toNumericPrimitive(getPropertyValue(member.object, member.property, context), context)
27455
+ await toNumericPrimitive(getPropertyValue(member.object, property, context), context)
27387
27456
  );
27388
27457
  const next = node.operator === "++" ? current + 1 : current - 1;
27389
- setSandboxProperty(member.object, member.property, next, context.budget);
27458
+ setSandboxProperty(member.object, property, next, context.budget);
27390
27459
  return {
27391
27460
  kind: "normal",
27392
27461
  hasValue: true,
@@ -27397,14 +27466,14 @@ async function evaluateMemberExpression(node, context) {
27397
27466
  const member = await evaluateMemberAccess(node, context);
27398
27467
  if (member.kind === "error") return member;
27399
27468
  if (member.kind === "completion") return member.result;
27400
- if (member.kind === "nullish") {
27401
- if (node.optional) return { kind: "normal", hasValue: true, value: void 0 };
27469
+ if (member.kind === "nullish" || member.object === null || member.object === void 0) {
27470
+ if (member.kind === "nullish" && node.optional) return { kind: "normal", hasValue: true, value: void 0 };
27402
27471
  throw new TypeError("Cannot read properties of null or undefined.");
27403
27472
  }
27404
27473
  return {
27405
27474
  kind: "normal",
27406
27475
  hasValue: true,
27407
- value: getPropertyValue(member.object, member.property, context)
27476
+ value: getPropertyValue(member.object, await toPropertyKey(member.property, context.budget, createCoercionContext(context)), context)
27408
27477
  };
27409
27478
  }
27410
27479
  function getPropertyValue(target, property, context) {
@@ -27429,6 +27498,7 @@ function createPatternContext(context, scope = context.scope, evaluate = evaluat
27429
27498
  const evaluationContext = { ...context, scope };
27430
27499
  return {
27431
27500
  evaluate: (node) => evaluate(node, evaluationContext),
27501
+ toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(evaluationContext)),
27432
27502
  getProperty: (value, key) => getPropertyValue(value, key, evaluationContext),
27433
27503
  setProperty: (target, key, value) => setSandboxProperty(target, key, value, context.budget)
27434
27504
  };
@@ -27523,21 +27593,8 @@ async function evaluateMemberAccess(node, context) {
27523
27593
  kind: "nullish"
27524
27594
  };
27525
27595
  }
27526
- const property = node.computed ? await evaluateMemberProperty(node.property, context) : { ok: true, value: getStaticPropertyName2(node.property) };
27527
- if (!property.ok) {
27528
- return property.result.kind === "error" ? {
27529
- kind: "error",
27530
- error: property.result.error
27531
- } : {
27532
- kind: "completion",
27533
- result: property.result
27534
- };
27535
- }
27536
- if (object.value === null || object.value === void 0) {
27537
- return {
27538
- kind: "nullish"
27539
- };
27540
- }
27596
+ const property = node.computed ? await evaluateNode(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
27597
+ if (property.kind !== "normal") return { kind: "completion", result: property };
27541
27598
  return {
27542
27599
  kind: "resolved",
27543
27600
  object: object.value,
@@ -27552,13 +27609,10 @@ async function evaluateMemberProperty(node, context) {
27552
27609
  result: property
27553
27610
  };
27554
27611
  }
27555
- if (typeof property.value === "string" || typeof property.value === "number") {
27556
- return {
27557
- ok: true,
27558
- value: property.value
27559
- };
27560
- }
27561
- throw new TypeError("Computed property access requires a string or number key.");
27612
+ return {
27613
+ ok: true,
27614
+ value: await toPropertyKey(property.value, context.budget, createCoercionContext(context))
27615
+ };
27562
27616
  }
27563
27617
  async function evaluateObjectPropertyKey(node, context) {
27564
27618
  if (!node.computed) {
@@ -27582,15 +27636,15 @@ async function evaluateMemberCallExpression(node, context) {
27582
27636
  if (node.callee.type !== "MemberExpression") {
27583
27637
  throw new TypeError("Expected member call expression.");
27584
27638
  }
27585
- const member = await evaluateMemberAccess(node.callee, context);
27586
- if (member.kind === "error") {
27587
- return member;
27639
+ const reference = await evaluateMemberAccess(node.callee, context);
27640
+ if (reference.kind === "error") {
27641
+ return reference;
27588
27642
  }
27589
- if (member.kind === "completion") {
27590
- return member.result;
27643
+ if (reference.kind === "completion") {
27644
+ return reference.result;
27591
27645
  }
27592
- if (member.kind === "nullish") {
27593
- if (node.optional || node.callee.optional) {
27646
+ if (reference.kind === "nullish" || reference.object === null || reference.object === void 0) {
27647
+ if (reference.kind === "nullish") {
27594
27648
  return {
27595
27649
  kind: "normal",
27596
27650
  hasValue: true,
@@ -27599,6 +27653,10 @@ async function evaluateMemberCallExpression(node, context) {
27599
27653
  }
27600
27654
  throw new TypeError("Cannot read properties of null or undefined.");
27601
27655
  }
27656
+ const member = {
27657
+ ...reference,
27658
+ property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
27659
+ };
27602
27660
  if (typeof member.object === "string" && isStringMethodName(member.property)) {
27603
27661
  return evaluateStringMethodCall(node, member.object, member.property, context);
27604
27662
  }
@@ -27930,23 +27988,13 @@ function applyBinaryOperator(node, left, right, context) {
27930
27988
  return hasSandboxProperty(right, left, context);
27931
27989
  }
27932
27990
  }
27933
- async function toPropertyKey(value, context) {
27934
- if (isPlainSandboxObject(value) && !isSandboxDate(value) && !isFloat32Array(value) && !isSandboxGenerator(value) && !isGuestHostObject(value)) {
27935
- for (const name of ["toString", "valueOf"]) {
27936
- const method = getMemberValue(value, name, context);
27937
- if (!isSandboxClosure(method)) continue;
27938
- const primitive = await invokeSandboxClosure(method, [], context, context.callStack, void 0, value);
27939
- if (primitive === null || typeof primitive !== "object") {
27940
- return context.budget.allocateString(String(primitive));
27941
- }
27942
- }
27943
- throw new TypeError("Cannot convert object to primitive value.");
27944
- }
27945
- return sandboxString(value, context.budget, {
27991
+ function createCoercionContext(context) {
27992
+ return {
27946
27993
  stack: context.callStack,
27947
27994
  thisValue: void 0,
27995
+ compilation: context.compilation,
27948
27996
  invokeClosure: (closure, args, thisValue) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue)
27949
- });
27997
+ };
27950
27998
  }
27951
27999
  function hasSandboxProperty(value, key, context) {
27952
28000
  let current = value;
@@ -32818,4 +32866,4 @@ export {
32818
32866
  FileSnapshotBackend,
32819
32867
  run
32820
32868
  };
32821
- //# sourceMappingURL=chunk-5J6BX3HD.js.map
32869
+ //# sourceMappingURL=chunk-M4M56OCI.js.map