| 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 |
Short circuit if the CoalesceExpressionHead is not undefined or null (the empty string) |
| 7 |
esid: sec-conditional-operator |
| 8 |
info: | |
| 9 |
ConditionalExpression : |
| 10 |
ShortCircuitExpression |
| 11 |
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression |
| 12 |
|
| 13 |
ShortCircuitExpression : |
| 14 |
LogicalORExpression |
| 15 |
CoalesceExpression |
| 16 |
|
| 17 |
CoalesceExpression : |
| 18 |
CoalesceExpressionHead ?? BitwiseORExpression |
| 19 |
|
| 20 |
CoalesceExpressionHead : |
| 21 |
CoalesceExpression |
| 22 |
BitwiseORExpression |
| 23 |
|
| 24 |
Runtime Semantics: Evaluation |
| 25 |
|
| 26 |
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression |
| 27 |
|
| 28 |
1. Let lref be the result of evaluating CoalesceExpressionHead. |
| 29 |
2. Let lval be ? GetValue(lref). |
| 30 |
3. If lval is undefined or null, |
| 31 |
a. Let rref be the result of evaluating BitwiseORExpression. |
| 32 |
b. Return ? GetValue(rref). |
| 33 |
4. Otherwise, return lval. |
| 34 |
features: [coalesce-expression] |
| 35 |
---*/ |
| 36 |
|
| 37 |
var x; |
| 38 |
var str = ''; |
| 39 |
|
| 40 |
x = undefined; |
| 41 |
x = str ?? 1; |
| 42 |
assert.sameValue(x, str, 'str ?? 1'); |
| 43 |
|
| 44 |
x = undefined; |
| 45 |
x = str ?? null; |
| 46 |
assert.sameValue(x, str, 'str ?? null'); |
| 47 |
|
| 48 |
x = undefined; |
| 49 |
x = str ?? undefined; |
| 50 |
assert.sameValue(x, str, 'str ?? undefined'); |
| 51 |
|
| 52 |
x = undefined; |
| 53 |
x = str ?? null ?? undefined; |
| 54 |
assert.sameValue(x, str, 'str ?? null ?? undefined'); |
| 55 |
|
| 56 |
x = undefined; |
| 57 |
x = str ?? undefined ?? null; |
| 58 |
assert.sameValue(x, str, 'str ?? undefined ?? null'); |
| 59 |
|
| 60 |
x = undefined; |
| 61 |
x = str ?? null ?? null; |
| 62 |
assert.sameValue(x, str, 'str ?? null ?? null'); |
| 63 |
|
| 64 |
x = undefined; |
| 65 |
x = str ?? undefined ?? undefined; |
| 66 |
assert.sameValue(x, str, 'str ?? null ?? null'); |
| 67 |
|
| 68 |
x = undefined; |
| 69 |
x = null ?? str ?? null; |
| 70 |
assert.sameValue(x, str, 'null ?? str ?? null'); |
| 71 |
|
| 72 |
x = undefined; |
| 73 |
x = null ?? str ?? undefined; |
| 74 |
assert.sameValue(x, str, 'null ?? str ?? undefined'); |
| 75 |
|
| 76 |
x = undefined; |
| 77 |
x = undefined ?? str ?? null; |
| 78 |
assert.sameValue(x, str, 'undefined ?? str ?? null'); |
| 79 |
|
| 80 |
x = undefined; |
| 81 |
x = undefined ?? str ?? undefined; |
| 82 |
assert.sameValue(x, str, 'undefined ?? str ?? undefined'); |
| 83 |
|
| 84 |
reportCompare(0, 0); |