tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

scope-lex-close-dflt.js (1459B)


      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 esid: sec-switch-statement-runtime-semantics-evaluation
      5 description: Removal of lexical environment (from `default` clause)
      6 info: |
      7    1. Let exprRef be the result of evaluating Expression.
      8    2. Let switchValue be ? GetValue(exprRef).
      9    3. Let oldEnv be the running execution context's LexicalEnvironment.
     10    4. Let blockEnv be NewDeclarativeEnvironment(oldEnv).
     11    5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv).
     12    6. Set the running execution context's LexicalEnvironment to blockEnv.
     13    7. Let R be the result of performing CaseBlockEvaluation of CaseBlock with
     14      argument switchValue.
     15    [...]
     16 features: [let]
     17 ---*/
     18 
     19 let x = 'outside';
     20 var probeDefault, probeDefaultBeforeCase, probeCase;
     21 
     22 switch (null) {
     23  default:
     24    let x = 'inside';
     25    probeDefault = function() { return x; };
     26 }
     27 
     28 assert.sameValue(probeDefault(), 'inside', 'from lone `default` clause`');
     29 assert.sameValue(x, 'outside');
     30 
     31 switch (null) {
     32  default:
     33    let x = 'inside';
     34    probeDefaultBeforeCase = function() { return x; };
     35  case 0:
     36    probeCase = function() { return x; };
     37 }
     38 
     39 assert.sameValue(
     40  probeDefaultBeforeCase(),
     41  'inside',
     42  'from `default` clause preceding `case` clause'
     43 );
     44 assert.sameValue(
     45  probeCase(), 'inside', 'from `case` clause following `default` clause'
     46 );
     47 
     48 reportCompare(0, 0);