tor-browser

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

switch-dflt-global-block-scoping.js (1524B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/annex-b-fns/global-block-scoping.case
      3 // - src/annex-b-fns/global/switch-dflt.template
      4 /*---
      5 description: A block-scoped binding is created (Funtion declaration in the `default` clause of a `switch` statement in the global scope)
      6 esid: sec-web-compat-globaldeclarationinstantiation
      7 flags: [generated, noStrict]
      8 info: |
      9    13.2.14 Runtime Semantics: BlockDeclarationInstantiation
     10 
     11    [...]
     12    4. For each element d in declarations do
     13       a. For each element dn of the BoundNames of d do
     14          i. If IsConstantDeclaration of d is true, then
     15             [...]
     16          ii. Else,
     17              2. Perform ! envRec.CreateMutableBinding(dn, false).
     18 
     19       b. If d is a GeneratorDeclaration production or a FunctionDeclaration
     20          production, then
     21          i. Let fn be the sole element of the BoundNames of d.
     22          ii. Let fo be the result of performing InstantiateFunctionObject for
     23              d with argument env.
     24          iii. Perform envRec.InitializeBinding(fn, fo).
     25 ---*/
     26 var initialBV, currentBV;
     27 
     28 switch (1) {
     29  default:
     30    function f() { initialBV = f; f = 123; currentBV = f; return 'decl'; }
     31 }
     32 
     33 f();
     34 
     35 assert.sameValue(
     36  initialBV(),
     37  'decl',
     38  'Block-scoped binding value is function object at execution time'
     39 );
     40 assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable');
     41 assert.sameValue(
     42  f(),
     43  'decl',
     44  'Block-scoped binding is independent of outer var-scoped binding'
     45 );
     46 
     47 reportCompare(0, 0);