tor-browser

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

Frame-this-12.js (1342B)


      1 // Check evalInFrame("this") always returns the same object for a given frame.
      2 // Primitive this-values should not be boxed multiple times.
      3 
      4 var g = newGlobal({newCompartment: true});
      5 var dbg = new Debugger(g);
      6 var framesEntered = 0;
      7 var framesPopped = 0;
      8 var numSteps = 0;
      9 dbg.onEnterFrame = function (frame) {
     10    if (frame.type === 'eval')
     11        return;
     12    framesEntered++;
     13 
     14    var frameThis = frame.eval('this').return;
     15 
     16    frame.onPop = function() {
     17        framesPopped++;
     18        assertEq(frame.eval('this').return, frameThis);
     19    };
     20 
     21    frame.onStep = function() {
     22        numSteps++;
     23        assertEq(frame.eval('this').return, frameThis);
     24    }
     25 
     26    g.gotThis = frameThis.unsafeDereference();
     27    assertEq(frame.this, frameThis);
     28 };
     29 
     30 g.eval("function nonstrictfun() { return this; }");
     31 g.eval("nonstrictfun.call(Math); assertEq(gotThis, Math);");
     32 g.eval("nonstrictfun.call(true); assertEq(gotThis.valueOf(), true);");
     33 g.eval("nonstrictfun.call(); assertEq(gotThis, this);");
     34 
     35 g.eval("function nonstrictfunNoThis() { return 1; }");
     36 g.eval("nonstrictfunNoThis.call(Math); assertEq(gotThis, Math);");
     37 g.eval("nonstrictfunNoThis.call(true); assertEq(gotThis.valueOf(), true);");
     38 g.eval("nonstrictfunNoThis.call(); assertEq(gotThis, this);");
     39 
     40 assertEq(framesEntered, 6);
     41 assertEq(framesPopped, 6);
     42 assertEq(numSteps > 15, true);