tor-browser

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

stepping.js (1106B)


      1 // Test that stepping through a function stops at the expected lines.
      2 // `script` is a string, some JS code that evaluates to a function.
      3 // `expected` is the array of line numbers where stepping is expected to stop
      4 // when we call the function.
      5 function testStepping(script, expected) {
      6    let g = newGlobal({newCompartment: true});
      7    let f = g.eval(script);
      8 
      9    let log = [];
     10    function maybePause(frame) {
     11        let previousLine = log[log.length - 1]; // note: may be undefined
     12        let line = frame.script.getOffsetLocation(frame.offset).lineNumber;
     13        if (line !== previousLine)
     14            log.push(line);
     15    }
     16 
     17    let dbg = new Debugger(g);
     18    dbg.onEnterFrame = frame => {
     19        // Log this pause (before the first instruction of the function).
     20        maybePause(frame);
     21 
     22        // Log future pauses in the same stack frame.
     23        frame.onStep = function() { maybePause(this); };
     24 
     25        // Now disable this hook so that we step over function calls, not into them.
     26        dbg.onEnterFrame = undefined;
     27    };
     28 
     29    f();
     30 
     31    assertEq(log.join(","), expected.join(","));
     32 }