| 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 |
[...] |
| 27 |
5. Let foundInB be false. |
| 28 |
6. Let B be the List containing the CaseClause items in the second |
| 29 |
CaseClauses, in source text order. If the second CaseClauses is not |
| 30 |
present B is « ». |
| 31 |
7. If found is false, then |
| 32 |
a. Repeat for each CaseClause C in B |
| 33 |
i. If foundInB is false, then |
| 34 |
1. Let clauseSelector be the result of CaseSelectorEvaluation of |
| 35 |
C. |
| 36 |
[...] |
| 37 |
3. Let foundInB be the result of performing Strict Equality |
| 38 |
Comparison input === clauseSelector.[[value]]. |
| 39 |
ii. If foundInB is true, then |
| 40 |
[...] |
| 41 |
8. If foundInB is true, return NormalCompletion(V). |
| 42 |
9. Let R be the result of evaluating DefaultClause. |
| 43 |
10. If R.[[value]] is not empty, let V = R.[[value]]. |
| 44 |
11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). |
| 45 |
12. Repeat for each CaseClause C in B (NOTE this is another complete |
| 46 |
iteration of the second CaseClauses) |
| 47 |
a. Let R be the result of evaluating CaseClause C. |
| 48 |
b. If R.[[value]] is not empty, let V = R.[[value]]. |
| 49 |
c. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). |
| 50 |
---*/ |
| 51 |
|
| 52 |
assert.sameValue( |
| 53 |
eval('1; switch ("a") { default: case "b": 2; case "c": 3; break; }'), |
| 54 |
3, |
| 55 |
'Non-empty value replaces previous non-empty value' |
| 56 |
); |
| 57 |
assert.sameValue( |
| 58 |
eval('4; switch ("a") { default: case "b": case "c": 5; break; }'), |
| 59 |
5, |
| 60 |
'Non-empty value replaces empty value' |
| 61 |
); |
| 62 |
assert.sameValue( |
| 63 |
eval('6; switch ("a") { default: case "b": 7; case "c": break; }'), |
| 64 |
7, |
| 65 |
'Empty value does not replace previous non-empty value' |
| 66 |
); |
| 67 |
|
| 68 |
assert.sameValue( |
| 69 |
eval('8; do { switch ("a") { default: case "b": 9; case "c": 10; continue; } } while (false)'), |
| 70 |
10, |
| 71 |
'Non-empty value replaces previous non-empty value' |
| 72 |
); |
| 73 |
assert.sameValue( |
| 74 |
eval('11; do { switch ("a") { default: case "b": case "c": 12; continue; } } while (false)'), |
| 75 |
12, |
| 76 |
'Non-empty value replaces empty value' |
| 77 |
); |
| 78 |
assert.sameValue( |
| 79 |
eval('13; do { switch ("a") { default: case "b": 14; case "c": continue; } } while (false)'), |
| 80 |
14, |
| 81 |
'Empty value does not replace previous non-empty value' |
| 82 |
); |
| 83 |
|
| 84 |
reportCompare(0, 0); |