cptn-dflt-b-final.js (2916B)
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 [...] 35 3. Let foundInB be the result of performing Strict Equality 36 Comparison input === clauseSelector.[[value]]. 37 ii. If foundInB is true, then 38 [...] 39 8. If foundInB is true, return NormalCompletion(V). 40 9. Let R be the result of evaluating DefaultClause. 41 10. If R.[[value]] is not empty, let V = R.[[value]]. 42 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). 43 12. Repeat for each CaseClause C in B (NOTE this is another complete 44 iteration of the second CaseClauses) 45 a. Let R be the result of evaluating CaseClause C. 46 b. If R.[[value]] is not empty, let V = R.[[value]]. 47 c. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). 48 13. Return NormalCompletion(V). 49 ---*/ 50 51 assert.sameValue( 52 eval('1; switch ("a") { default: case "b": }'), 53 undefined, 54 'empty StatementList (lone case)' 55 ); 56 assert.sameValue( 57 eval('2; switch ("a") { default: case "b": 3; }'), 58 3, 59 'non-empy StatementList (lone case)' 60 ); 61 assert.sameValue( 62 eval('4; switch ("a") { default: case "b": case "c": }'), 63 undefined, 64 'empty StatementList (following an empty case)' 65 ); 66 assert.sameValue( 67 eval('5; switch ("a") { default: case "b": case "c": 6; }'), 68 6, 69 'non-empty StatementList (following an empty case)' 70 ); 71 assert.sameValue( 72 eval('7; switch ("a") { default: case "b": 8; case "c": }'), 73 8, 74 'empty StatementList (following a non-empty case)' 75 ); 76 assert.sameValue( 77 eval('9; switch ("a") { default: case "b": 10; case "c": 11; }'), 78 11, 79 'non-empty StatementList (following a non-empty case)' 80 ); 81 82 reportCompare(0, 0);