Debian Codegraph @

js/src/tests/test262/language/statements/switch/cptn-dflt-final.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: Completion value when the default case matches and is final
6 info: |
7 SwitchStatement : switch ( Expression ) CaseBlock
8
9 [...]
10 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with
11 argument switchValue.
12 9. Set the running execution context’s LexicalEnvironment to oldEnv.
13 10. Return R.
14
15 13.12.9 Runtime Semantics: CaseBlockEvaluation
16
17 CaseBlock : { CaseClauses }
18
19 1. Let V = undefined.
20 2. Let A be the list of CaseClause items in the first CaseClauses, in
21 source text order. If the first CaseClauses is not present A is « ».
22 3. Let found be false.
23 4. Repeat for each CaseClause C in A
24 [...]
25 5. Let foundInB be false.
26 6. Let B be the List containing the CaseClause items in the second
27 CaseClauses, in source text order. If the second CaseClauses is not
28 present B is « ».
29 7. If found is false, then
30 a. Repeat for each CaseClause C in B
31 [...]
32 8. If foundInB is true, return NormalCompletion(V).
33 9. Let R be the result of evaluating DefaultClause.
34 10. If R.[[value]] is not empty, let V = R.[[value]].
35 [...]
36 13. Return NormalCompletion(V).
37 ---*/
38
39 assert.sameValue(
40 eval('1; switch ("a") { default: }'),
41 undefined,
42 'empty StatementList (lone case)'
43 );
44 assert.sameValue(
45 eval('2; switch ("a") { default: 3; }'),
46 3,
47 'non-empy StatementList (lone case)'
48 );
49 assert.sameValue(
50 eval('4; switch ("b") { case "a": default: }'),
51 undefined,
52 'empty StatementList (following an empty case)'
53 );
54 assert.sameValue(
55 eval('5; switch ("b") { case "a": default: 6; }'),
56 6,
57 'non-empty StatementList (following an empty case)'
58 );
59 assert.sameValue(
60 eval('7; switch ("b") { case "a": 8; default: }'),
61 undefined,
62 'empty StatementList (following a non-empty case)'
63 );
64 assert.sameValue(
65 eval('9; switch ("b") { case "a": 10; default: 11; }'),
66 11,
67 'non-empty StatementList (following a non-empty case)'
68 );
69
70 reportCompare(0, 0);