Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/exponentiation/exp-operator-evaluation-order.js

raw
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 ---*/
20
21 var capture = [];
22 var leftValue = { valueOf() { capture.push("leftValue"); return 3; }};
23 var rightValue = { valueOf() { capture.push("rightValue"); return 2; }};
24
25 (capture.push("left"), leftValue) ** (capture.push("right"), rightValue);
26
27 // Expected per operator evaluation order: "left", "right", "leftValue", "rightValue"
28
29 assert.sameValue(capture[0], "left", "Expected the 1st element captured to be 'left'");
30 assert.sameValue(capture[1], "right", "Expected the 2nd element captured to be 'right'");
31 assert.sameValue(capture[2], "leftValue", "Expected the 3rd element captured to be 'leftValue'");
32 assert.sameValue(capture[3], "rightValue", "Expected the 4th element captured to be 'rightValue'");