cptn-dflt-fall-thru-abrupt-empty.js (2391B)
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 in the default case 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 [...] 33 8. If foundInB is true, return NormalCompletion(V). 34 9. Let R be the result of evaluating DefaultClause. 35 10. If R.[[value]] is not empty, let V = R.[[value]]. 36 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). 37 ---*/ 38 39 assert.sameValue( 40 eval('1; switch ("a") { case "a": 2; default: 3; break; }'), 41 3, 42 'Non-empty value replaces previous non-empty value' 43 ); 44 assert.sameValue( 45 eval('4; switch ("a") { case "a": default: 5; break; }'), 46 5, 47 'Non-empty value replaces empty value' 48 ); 49 assert.sameValue( 50 eval('6; switch ("a") { case "a": 7; default: break; }'), 51 7, 52 'Empty value does not replace previous non-empty value' 53 ); 54 55 assert.sameValue( 56 eval('8; do { switch ("a") { case "a": 9; default: 10; continue; } } while (false)'), 57 10, 58 'Non-empty value replaces previous non-empty value' 59 ); 60 assert.sameValue( 61 eval('11; do { switch ("a") { case "a": default: 12; continue; } } while (false)'), 62 12, 63 'Non-empty value replaces empty value' 64 ); 65 assert.sameValue( 66 eval('13; do { switch ("a") { case "a": 14; default: continue; } } while (false)'), 67 14, 68 'Empty value does not replace previous non-empty value' 69 ); 70 71 reportCompare(0, 0);