Debian Codegraph @

js/src/tests/test262/language/statements/switch/cptn-a-fall-thru-abrupt-empty.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 es6id: 13.12.11
5 description: >
6 Completion value when execution continues through multiple cases and ends
7 with an empty abrupt completion
8 info: |
9 SwitchStatement : switch ( Expression ) CaseBlock
10
11 [...]
12 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with
13 argument switchValue.
14 9. Set the running execution context’s LexicalEnvironment to oldEnv.
15 10. Return R.
16
17 13.12.9 Runtime Semantics: CaseBlockEvaluation
18
19 CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
20
21 1. Let V = undefined.
22 2. Let A be the list of CaseClause items in the first CaseClauses, in
23 source text order. If the first CaseClauses is not present A is « ».
24 3. Let found be false.
25 4. Repeat for each CaseClause C in A
26 a. If found is false, then
27 [...]
28 b. If found is true, then
29 i. Let R be the result of evaluating C.
30 ii. If R.[[value]] is not empty, let V = R.[[value]].
31 iii. If R is an abrupt completion, return Completion(UpdateEmpty(R,
32 V)).
33 ---*/
34
35 assert.sameValue(
36 eval('1; switch ("a") { case "a": 2; case "b": 3; break; default: }'),
37 3,
38 'Non-empty value replaces previous non-empty value'
39 );
40 assert.sameValue(
41 eval('4; switch ("a") { case "a": case "b": 5; break; default: }'),
42 5,
43 'Non-empty value replaces empty value'
44 );
45 assert.sameValue(
46 eval('6; switch ("a") { case "a": 7; case "b": break; default: }'),
47 7,
48 'Empty value does not replace previous non-empty value'
49 );
50
51 assert.sameValue(
52 eval('8; do { switch ("a") { case "a": 9; case "b": 10; continue; default: } } while (false)'),
53 10,
54 'Non-empty value replaces previous non-empty value'
55 );
56 assert.sameValue(
57 eval('11; do { switch ("a") { case "a": case "b": 12; continue; default: } } while (false)'),
58 12,
59 'Non-empty value replaces empty value'
60 );
61 assert.sameValue(
62 eval('13; do { switch ("a") { case "a": 14; case "b": continue; default: } } while (false)'),
63 14,
64 'Empty value does not replace previous non-empty value'
65 );
66
67 reportCompare(0, 0);