| 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 | |
| 18 | 13.12.9 Runtime Semantics: CaseBlockEvaluation |
| 19 | |
| 20 | CaseBlock : { CaseClauses } |
| 21 | |
| 22 | 1. Let V = undefined. |
| 23 | 2. Let A be the List of CaseClause items in CaseClauses, in source text |
| 24 | order. |
| 25 | 3. Let found be false. |
| 26 | 4. Repeat for each CaseClause C in A, |
| 27 | a. If found is false, then |
| 28 | i. Let clauseSelector be the result of CaseSelectorEvaluation of C. |
| 29 | ii. If clauseSelector is an abrupt completion, then |
| 30 | 1. If clauseSelector.[[value]] is empty, return |
| 31 | Completion{[[type]]: clauseSelector.[[type]], [[value]]: |
| 32 | undefined, [[target]]: clauseSelector.[[target]]}. |
| 33 | 2. Else, return Completion(clauseSelector). |
| 34 | iii. Let found be the result of performing Strict Equality Comparison |
| 35 | input === clauseSelector.[[value]]. |
| 36 | b. If found is true, then |
| 37 | i. Let R be the result of evaluating C. |
| 38 | ii. If R.[[value]] is not empty, let V = R.[[value]]. |
| 39 | iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, |
| 40 | V)). |
| 41 | ---*/ |
| 42 | |
| 43 | assert.sameValue(eval('1; switch ("a") { case "a": break; }'), undefined); |
| 44 | assert.sameValue(eval('2; switch ("a") { case "a": { 3; break; } }'), 3); |
| 45 | |
| 46 | assert.sameValue( |
| 47 | eval('4; do { switch ("a") { case "a": continue; } } while (false)'), |
| 48 | undefined |
| 49 | ); |
| 50 | assert.sameValue( |
| 51 | eval('5; do { switch ("a") { case "a": { 6; continue; } } } while (false)'), |
| 52 | 6 |
| 53 | ); |
| 54 | |
| 55 | reportCompare(0, 0); |