tor-browser

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

envChain_function-calls.js (1337B)


      1 var g = newGlobal({ newCompartment: true });
      2 g.eval(`
      3 let counter = 10;
      4 
      5 function func1() {
      6  var local1 = counter;
      7 
      8  var func2 = function f2() {
      9    var local2 = counter;
     10 
     11    var func3 = function f3() {
     12      var local3 = counter;
     13 
     14      var func4 = function f4() {
     15        var local4 = counter;
     16 
     17        // Close these local variables over to make them available in
     18        // the environment objects.
     19        var x = [local1, local2, local3];
     20 
     21        counter++;
     22 
     23        debugger;
     24      };
     25 
     26      func4();
     27    };
     28 
     29    func3();
     30  };
     31 
     32  func2();
     33 };
     34 `);
     35 
     36 var dbg = new Debugger(g);
     37 
     38 var result = null;
     39 
     40 dbg.onDebuggerStatement = function handleDebuggerStatement(f) {
     41  result = {
     42    local1: f.eval("local1").return,
     43    local2: f.eval("local2").return,
     44    local3: f.eval("local3").return,
     45    local4: f.eval("local4").return,
     46  };
     47 };
     48 
     49 g.eval('func1()');
     50 
     51 // All references, with/without the function call bounrary, should see
     52 // the same value.
     53 assertEq(result.local1, 10);
     54 assertEq(result.local2, 10);
     55 assertEq(result.local3, 10);
     56 assertEq(result.local4, 10);
     57 
     58 g.eval('func1()');
     59 
     60 // All references, with/without the function call bounrary, should see
     61 // the same updated value in the 2nd call's environment chain.
     62 assertEq(result.local1, 11);
     63 assertEq(result.local2, 11);
     64 assertEq(result.local3, 11);
     65 assertEq(result.local4, 11);