summaryrefslogtreecommitdiff
path: root/js/src/tests/test262/language/expressions/conditional/coalesce-expr-ternary.js
blob: 543f22127a02b08839ce01a3e7f5efcb4ba7639e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
    ShortCircuitExpression in the Conditional Expression (? :)
esid: sec-conditional-operator
info: |
    ShortCircuitExpression :
        LogicalORExpression
        CoalesceExpression

    CoalesceExpression :
        CoalesceExpressionHead ?? BitwiseORExpression

    CoalesceExpressionHead :
        CoalesceExpression
        BitwiseORExpression

    ConditionalExpression :
        ShortCircuitExpression
        ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
features: [coalesce-expression]
---*/

var x;

x = undefined ?? true ? 0 : 42;
assert.sameValue(x, 0, 'undefined ?? true ? 0 : 42');

x = undefined;
x = null ?? true ? 0 : 42;
assert.sameValue(x, 0, 'null ?? true ? 0 : 42');

x = undefined;
x = undefined ?? false ? 0 : 42;
assert.sameValue(x, 42, 'undefined ?? false ? 0 : 42');

x = undefined;
x = null ?? false ? 0 : 42;
assert.sameValue(x, 42, 'null ?? false ? 0 : 42');

x = undefined;
x = false ?? true ? 0 : 42;
assert.sameValue(x, 42, 'false ?? true ? 0 : 42');

x = undefined;
x = 0 ?? true ? 0 : 42;
assert.sameValue(x, 42, '0 ?? true ? 0 : 42');

x = undefined;
x = 1 ?? false ? 0 : 42;
assert.sameValue(x, 0, '1 ?? false ? 0 : 42');

x = undefined;
x = true ?? false ? 0 : 42;
assert.sameValue(x, 0, 'true ?? false ? 0 : 42');

x = undefined;
x = true ?? true ? 0 : 42;
assert.sameValue(x, 0, 'true ?? true ? 0 : 42');

x = undefined;
x = '' ?? true ? 0 : 42;
assert.sameValue(x, 42, '"" ?? true ? 0 : 42');

x = undefined;
x = Symbol() ?? false ? 0 : 42;
assert.sameValue(x, 0, 'Symbol() ?? false ? 0 : 42');

x = undefined;
x = {} ?? false ? 0 : 42;
assert.sameValue(x, 0, 'object ?? false ? 0 : 42');

reportCompare(0, 0);