tor-browser

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

Environment-identity-01.js (1017B)


      1 // The value of frame.environment is the same Environment object at different
      2 // times within a single visit to a scope.
      3 
      4 var g = newGlobal({newCompartment: true});
      5 var dbg = Debugger(g);
      6 g.eval("function h() { debugger; }");
      7 var hits, env;
      8 dbg.onDebuggerStatement = function (hframe) {
      9    var frame = hframe.older;
     10    var e = frame.environment;
     11 
     12    // frame.environment is at least cached from one moment to the next.
     13    assertEq(e, frame.environment);
     14 
     15    // frame.environment is cached from statement to statement within a call frame.
     16    if (env === undefined)
     17        env = e;
     18    else
     19        assertEq(e, env);
     20 
     21    hits++;
     22 };
     23 
     24 hits = 0;
     25 env = undefined;
     26 g.eval("function f() { (function () { var i = 0; h(); var j = 2; h(); })(); }");
     27 g.f();
     28 assertEq(hits, 2);
     29 
     30 hits = 0;
     31 env = undefined;
     32 g.eval("function f2() { { let i = 0; h(); let j = 2; h(); } }");
     33 g.f2();
     34 assertEq(hits, 2);
     35 
     36 hits = 0;
     37 env = undefined;
     38 g.eval("function f3() { { let i; for (i = 0; i < 2; i++) h(); } }");
     39 g.f3();
     40 assertEq(hits, 2);