cptn-a-abrupt-empty.js (2146B)
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 the matching case is exited via an empty abrupt 7 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 a. If found is false, then 27 i. Let clauseSelector be the result of CaseSelectorEvaluation of C. 28 ii. If clauseSelector is an abrupt completion, then 29 1. If clauseSelector.[[value]] is empty, return 30 Completion{[[type]]: clauseSelector.[[type]], [[value]]: 31 undefined, [[target]]: clauseSelector.[[target]]}. 32 2. Else, return Completion(clauseSelector). 33 iii. Let found be the result of performing Strict Equality Comparison 34 input === clauseSelector.[[value]]. 35 b. If found is true, then 36 i. Let R be the result of evaluating C. 37 ii. If R.[[value]] is not empty, let V = R.[[value]]. 38 iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, 39 V)). 40 ---*/ 41 42 assert.sameValue( 43 eval('1; switch ("a") { case "a": break; default: }'), undefined 44 ); 45 assert.sameValue( 46 eval('2; switch ("a") { case "a": { 3; break; } default: }'), 3 47 ); 48 49 assert.sameValue( 50 eval('4; do { switch ("a") { case "a": continue; default: } } while (false)'), 51 undefined 52 ); 53 assert.sameValue( 54 eval('5; do { switch ("a") { case "a": { 6; continue; } default: } } while (false)'), 55 6 56 ); 57 58 reportCompare(0, 0);