Debian Codegraph @

js/src/tests/test262/language/statements/switch/cptn-b-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 final case matches
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 i. If foundInB is false, then
32 1. Let clauseSelector be the result of CaseSelectorEvaluation of
33 C.
34 2. If clauseSelector is an abrupt completion, then
35 a. If clauseSelector.[[value]] is empty, return
36 Completion{[[type]]: clauseSelector.[[type]], [[value]]:
37 undefined, [[target]]: clauseSelector.[[target]]}.
38 b. Else, return Completion(clauseSelector).
39 3. Let foundInB be the result of performing Strict Equality
40 Comparison input === clauseSelector.[[value]].
41 ii. If foundInB is true, then
42 1. Let R be the result of evaluating CaseClause C.
43 2. If R.[[value]] is not empty, let V = R.[[value]].
44 3. If R is an abrupt completion, return
45 Completion(UpdateEmpty(R, V)).
46 8. If foundInB is true, return NormalCompletion(V).
47 ---*/
48
49 assert.sameValue(
50 eval('1; switch ("a") { default: case "a": }'),
51 undefined,
52 'empty StatementList (lone case)'
53 );
54 assert.sameValue(
55 eval('2; switch ("a") { default: case "a": 3; }'),
56 3,
57 'non-empy StatementList (lone case)'
58 );
59 assert.sameValue(
60 eval('4; switch ("b") { default: case "a": case "b": }'),
61 undefined,
62 'empty StatementList (following an empty case)'
63 );
64 assert.sameValue(
65 eval('5; switch ("b") { default: case "a": case "b": 6; }'),
66 6,
67 'non-empty StatementList (following an empty case)'
68 );
69 assert.sameValue(
70 eval('7; switch ("b") { default: case "a": 8; case "b": }'),
71 undefined,
72 'empty StatementList (following a non-empty case)'
73 );
74 assert.sameValue(
75 eval('9; switch ("b") { default: case "a": 10; case "b": 11; }'),
76 11,
77 'non-empty StatementList (following a non-empty case)'
78 );
79
80 reportCompare(0, 0);