exp-operator-evaluation-order.js (1565B)
1 // Copyright (C) 2016 Rick Waldron, André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 author: Rick Waldron, André Bargull 6 esid: sec-exp-operator-runtime-semantics-evaluation 7 description: Exponentiation Operator expression order of evaluation 8 info: | 9 ExponentiationExpression: 10 UpdateExpression ** ExponentiationExpression 11 12 1. Let left be the result of evaluating UpdateExpression. 13 2. Let leftValue be ? GetValue(left). 14 3. Let right be the result of evaluating ExponentiationExpression. 15 4. Let rightValue be ? GetValue(right). 16 5. Let base be ? ToNumber(leftValue). 17 6. Let exponent be ? ToNumber(rightValue). 18 7. Return the result of Applying the ** operator with base and exponent as specified in 12.7.3.4. 19 features: [exponentiation] 20 ---*/ 21 22 var capture = []; 23 var leftValue = { valueOf() { capture.push("leftValue"); return 3; }}; 24 var rightValue = { valueOf() { capture.push("rightValue"); return 2; }}; 25 26 (capture.push("left"), leftValue) ** (capture.push("right"), rightValue); 27 28 // Expected per operator evaluation order: "left", "right", "leftValue", "rightValue" 29 30 assert.sameValue(capture[0], "left", "Expected the 1st element captured to be 'left'"); 31 assert.sameValue(capture[1], "right", "Expected the 2nd element captured to be 'right'"); 32 assert.sameValue(capture[2], "leftValue", "Expected the 3rd element captured to be 'leftValue'"); 33 assert.sameValue(capture[3], "rightValue", "Expected the 4th element captured to be 'rightValue'"); 34 35 reportCompare(0, 0);