cptn-b-fall-thru-abrupt-empty.js (3102B)
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 2. If clauseSelector is an abrupt completion, then 37 a. If clauseSelector.[[value]] is empty, return 38 Completion{[[type]]: clauseSelector.[[type]], [[value]]: 39 undefined, [[target]]: clauseSelector.[[target]]}. 40 b. Else, return Completion(clauseSelector). 41 3. Let foundInB be the result of performing Strict Equality 42 Comparison input === clauseSelector.[[value]]. 43 ii. If foundInB is true, then 44 1. Let R be the result of evaluating CaseClause C. 45 2. If R.[[value]] is not empty, let V = R.[[value]]. 46 3. If R is an abrupt completion, return 47 Completion(UpdateEmpty(R, V)). 48 ---*/ 49 50 assert.sameValue( 51 eval('1; switch ("a") { default: case "a": 2; case "b": 3; break; }'), 52 3, 53 'Non-empty value replaces previous non-empty value' 54 ); 55 assert.sameValue( 56 eval('4; switch ("a") { default: case "a": case "b": 5; break; }'), 57 5, 58 'Non-empty value replaces empty value' 59 ); 60 assert.sameValue( 61 eval('6; switch ("a") { default: case "a": 7; case "b": break; }'), 62 7, 63 'Empty value does not replace previous non-empty value' 64 ); 65 66 assert.sameValue( 67 eval('8; do { switch ("a") { default: case "a": 9; case "b": 10; continue; } } while (false)'), 68 10, 69 'Non-empty value replaces previous non-empty value' 70 ); 71 assert.sameValue( 72 eval('11; do { switch ("a") { default: case "a": case "b": 12; continue; } } while (false)'), 73 12, 74 'Non-empty value replaces empty value' 75 ); 76 assert.sameValue( 77 eval('13; do { switch ("a") { default: case "a": 14; case "b": continue; } } while (false)'), 78 14, 79 'Empty value does not replace previous non-empty value' 80 ); 81 82 reportCompare(0, 0);