tor-browser

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

func-switch-case-eval-func-init.js (1314B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/annex-b-fns/eval-func-init.case
      3 // - src/annex-b-fns/eval-func/direct-switch-case.template
      4 /*---
      5 description: Variable binding is initialized to `undefined` in outer scope (Function declaration in the `case` clause of a `switch` statement in eval code)
      6 esid: sec-web-compat-evaldeclarationinstantiation
      7 flags: [generated, noStrict]
      8 info: |
      9    B.3.3.3 Changes to EvalDeclarationInstantiation
     10 
     11    [...]
     12    a. If declaredFunctionOrVarNames does not contain F, then
     13       i. If varEnvRec is a global Environment Record, then
     14          [...]
     15       ii. Else,
     16           i. Let bindingExists be varEnvRec.HasBinding(F).
     17           ii. If bindingExists is false, then
     18               i. Perform ! varEnvRec.CreateMutableBinding(F, true).
     19               ii. Perform ! varEnvRec.InitializeBinding(F, undefined).
     20    [...]
     21 ---*/
     22 var init, changed;
     23 
     24 (function() {
     25  eval(
     26    'init = f;\
     27    f = 123;\
     28    changed = f;switch (1) {' +
     29    '  case 1:' +
     30    '    function f() {  }' +
     31    '}\
     32    '
     33  );
     34 }());
     35 
     36 assert.sameValue(init, undefined, 'binding is initialized to `undefined`');
     37 assert.sameValue(changed, 123, 'binding is mutable');
     38 assert.throws(ReferenceError, function() {
     39  f;
     40 }, 'global binding is not created');
     41 
     42 reportCompare(0, 0);