tor-browser

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

weird-scopechains.js (908B)


      1 function checkNameLookup() {
      2    return "global";
      3 }
      4 
      5 function assertWithMessage(got, expected, message) {
      6    assertEq(message + ": " + got, message + ": " + expected);
      7 }
      8 
      9 var obj = {
     10    checkNameLookup: function() {
     11 return "local";
     12    },
     13 
     14    checkThisBinding: function() {
     15 return this.checkNameLookup();
     16    },
     17 };
     18 
     19 evaluate("(" + function() {
     20    assertWithMessage(checkNameLookup(), "local", "nameLookup");
     21    assertWithMessage(checkThisBinding(), "local", "thisBinding");
     22 
     23    // Important: lambda needs to close over "reason", so it won't just get the
     24    // scope of testFunc as its scope.  Instead it'll get the Call object
     25    // "reason" lives in.
     26    var reason = " in lambda in Call";
     27    (function() {
     28 assertWithMessage(checkNameLookup(), "local", "nameLookup" + reason);
     29 assertWithMessage(checkThisBinding(), "local", "thisBinding" + reason);
     30    })();
     31 } + ")()", {envChainObject: obj});