computed-property-name-topropertykey-before-value-evaluation.js (1113B)
1 // Copyright (C) 2024 André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-runtime-semantics-propertydefinitionevaluation 6 description: > 7 ToPropertyKey is performed before evaluating the value expression. 8 info: | 9 13.2.5.5 Runtime Semantics: PropertyDefinitionEvaluation 10 11 PropertyDefinition : PropertyName : AssignmentExpression 12 13 1. Let propKey be ? Evaluation of PropertyName. 14 ... 15 6. Else, 16 a. Let exprValueRef be ? Evaluation of AssignmentExpression. 17 b. Let propValue be ? GetValue(exprValueRef). 18 ... 19 9. Perform ! CreateDataPropertyOrThrow(object, propKey, propValue). 20 ... 21 22 13.2.5.4 Runtime Semantics: Evaluation 23 24 ComputedPropertyName : [ AssignmentExpression ] 25 26 1. Let exprValue be ? Evaluation of AssignmentExpression. 27 2. Let propName be ? GetValue(exprValue). 28 3. Return ? ToPropertyKey(propName). 29 ---*/ 30 31 var value = "bad"; 32 33 var key = { 34 toString() { 35 value = "ok"; 36 return "p"; 37 } 38 }; 39 40 var obj = { 41 [key]: value 42 }; 43 44 assert.sameValue(obj.p, "ok"); 45 46 reportCompare(0, 0);