Debian Codegraph @

js/src/tests/test262/language/expressions/coalesce/abrupt-is-a-short-circuit.js

raw
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 Abrupt completions are also a Short circuit and prevent evaluation of the right-side expressions
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 function poison() {
39 throw new Test262Error('poison handled');
40 }
41
42 function morePoison() {
43 throw 'poison!!!!';
44 }
45
46 x = undefined;
47 assert.throws(Test262Error, function() {
48 undefined ?? poison() ?? morePoison();
49 }, 'undefined ?? poison() ?? morePoison();');
50
51 x = undefined;
52 assert.throws(Test262Error, function() {
53 null ?? poison() ?? morePoison();
54 }, 'null ?? poison() ?? morePoison();');
55
56 assert.throws(Test262Error, function() {
57 poison() ?? morePoison();
58 }, 'poison() ?? morePoison();');
59
60 reportCompare(0, 0);