| 1 |
// Copyright (C) 2019 Leo Balter. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: > |
| 6 |
ShortCircuitExpression in the Conditional Expression (? :) |
| 7 |
esid: sec-conditional-operator |
| 8 |
info: | |
| 9 |
ShortCircuitExpression : |
| 10 |
LogicalORExpression |
| 11 |
CoalesceExpression |
| 12 |
|
| 13 |
CoalesceExpression : |
| 14 |
CoalesceExpressionHead ?? BitwiseORExpression |
| 15 |
|
| 16 |
CoalesceExpressionHead : |
| 17 |
CoalesceExpression |
| 18 |
BitwiseORExpression |
| 19 |
|
| 20 |
ConditionalExpression : |
| 21 |
ShortCircuitExpression |
| 22 |
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression |
| 23 |
features: [coalesce-expression] |
| 24 |
---*/ |
| 25 |
|
| 26 |
var x; |
| 27 |
|
| 28 |
x = undefined ?? true ? 0 : 42; |
| 29 |
assert.sameValue(x, 0, 'undefined ?? true ? 0 : 42'); |
| 30 |
|
| 31 |
x = undefined; |
| 32 |
x = null ?? true ? 0 : 42; |
| 33 |
assert.sameValue(x, 0, 'null ?? true ? 0 : 42'); |
| 34 |
|
| 35 |
x = undefined; |
| 36 |
x = undefined ?? false ? 0 : 42; |
| 37 |
assert.sameValue(x, 42, 'undefined ?? false ? 0 : 42'); |
| 38 |
|
| 39 |
x = undefined; |
| 40 |
x = null ?? false ? 0 : 42; |
| 41 |
assert.sameValue(x, 42, 'null ?? false ? 0 : 42'); |
| 42 |
|
| 43 |
x = undefined; |
| 44 |
x = false ?? true ? 0 : 42; |
| 45 |
assert.sameValue(x, 42, 'false ?? true ? 0 : 42'); |
| 46 |
|
| 47 |
x = undefined; |
| 48 |
x = 0 ?? true ? 0 : 42; |
| 49 |
assert.sameValue(x, 42, '0 ?? true ? 0 : 42'); |
| 50 |
|
| 51 |
x = undefined; |
| 52 |
x = 1 ?? false ? 0 : 42; |
| 53 |
assert.sameValue(x, 0, '1 ?? false ? 0 : 42'); |
| 54 |
|
| 55 |
x = undefined; |
| 56 |
x = true ?? false ? 0 : 42; |
| 57 |
assert.sameValue(x, 0, 'true ?? false ? 0 : 42'); |
| 58 |
|
| 59 |
x = undefined; |
| 60 |
x = true ?? true ? 0 : 42; |
| 61 |
assert.sameValue(x, 0, 'true ?? true ? 0 : 42'); |
| 62 |
|
| 63 |
x = undefined; |
| 64 |
x = '' ?? true ? 0 : 42; |
| 65 |
assert.sameValue(x, 42, '"" ?? true ? 0 : 42'); |
| 66 |
|
| 67 |
x = undefined; |
| 68 |
x = Symbol() ?? false ? 0 : 42; |
| 69 |
assert.sameValue(x, 0, 'Symbol() ?? false ? 0 : 42'); |
| 70 |
|
| 71 |
x = undefined; |
| 72 |
x = {} ?? false ? 0 : 42; |
| 73 |
assert.sameValue(x, 0, 'object ?? false ? 0 : 42'); |
| 74 |
|
| 75 |
reportCompare(0, 0); |