tor-browser

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

if-decl-else-decl-b-func-block-scoping.js (2060B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/annex-b-fns/func-block-scoping.case
      3 // - src/annex-b-fns/func/if-decl-else-decl-b.template
      4 /*---
      5 description: A block-scoped binding is created (IfStatement with a declaration in both statement positions in function scope)
      6 esid: sec-functiondeclarations-in-ifstatement-statement-clauses
      7 flags: [generated, noStrict]
      8 info: |
      9    The following rules for IfStatement augment those in 13.6:
     10 
     11    IfStatement[Yield, Return]:
     12        if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
     13        if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
     14        if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
     15        if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
     16 
     17 
     18    13.2.14 Runtime Semantics: BlockDeclarationInstantiation
     19 
     20    [...]
     21    4. For each element d in declarations do
     22       a. For each element dn of the BoundNames of d do
     23          i. If IsConstantDeclaration of d is true, then
     24             [...]
     25          ii. Else,
     26              2. Perform ! envRec.CreateMutableBinding(dn, false).
     27 
     28       b. If d is a GeneratorDeclaration production or a FunctionDeclaration
     29          production, then
     30          i. Let fn be the sole element of the BoundNames of d.
     31          ii. Let fo be the result of performing InstantiateFunctionObject for
     32              d with argument env.
     33          iii. Perform envRec.InitializeBinding(fn, fo). 
     34 ---*/
     35 var initialBV, currentBV, varBinding;
     36 
     37 (function() {
     38  
     39 
     40  if (false) function _f() {} else function f() { initialBV = f; f = 123; currentBV = f; return 'decl'; }
     41 
     42  varBinding = f;
     43  f();
     44 }());
     45 
     46 
     47 assert.sameValue(
     48  initialBV(),
     49  'decl',
     50  'Block-scoped binding value is function object at execution time'
     51 );
     52 assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable');
     53 assert.sameValue(
     54  varBinding(),
     55  'decl',
     56  'Block-scoped binding is independent of outer var-scoped binding'
     57 );
     58 
     59 reportCompare(0, 0);