Debian Codegraph @

js/src/tests/test262/language/statements/switch/cptn-no-dflt-match-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 only 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 CaseClauses, in source text
21 order.
22 3. Let found be false.
23 4. Repeat for each CaseClause C in A,
24 a. If found is false, then
25 i. Let clauseSelector be the result of CaseSelectorEvaluation of C.
26 ii. If clauseSelector is an abrupt completion, then
27 1. If clauseSelector.[[value]] is empty, return
28 Completion{[[type]]: clauseSelector.[[type]], [[value]]:
29 undefined, [[target]]: clauseSelector.[[target]]}.
30 2. Else, return Completion(clauseSelector).
31 iii. Let found be the result of performing Strict Equality Comparison
32 input === clauseSelector.[[value]].
33 b. If found is true, then
34 i. Let R be the result of evaluating C.
35 ii. If R.[[value]] is not empty, let V = R.[[value]].
36 iii. If R is an abrupt completion, return Completion(UpdateEmpty(R,
37 V)).
38 5. Return NormalCompletion(V).
39 ---*/
40
41 assert.sameValue(
42 eval('1; switch ("a") { case "a": }'),
43 undefined,
44 'empty StatementList (lone case)'
45 );
46 assert.sameValue(
47 eval('2; switch ("a") { case "a": 3; }'),
48 3,
49 'non-empy StatementList (lone case)'
50 );
51 assert.sameValue(
52 eval('4; switch ("b") { case "a": case "b": }'),
53 undefined,
54 'empty StatementList (following an empty case)'
55 );
56 assert.sameValue(
57 eval('5; switch ("b") { case "a": case "b": 6; }'),
58 6,
59 'non-empty StatementList (following an empty case)'
60 );
61 assert.sameValue(
62 eval('7; switch ("b") { case "a": 8; case "b": }'),
63 undefined,
64 'empty StatementList (following a non-empty case)'
65 );
66 assert.sameValue(
67 eval('9; switch ("b") { case "a": 10; case "b": 11; }'),
68 11,
69 'non-empty StatementList (following a non-empty case)'
70 );
71
72 reportCompare(0, 0);