js/src/jit-test/tests/debug/Frame-onStep-lines-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/debug/Frame-onStep-lines-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +// Test that a frame's onStep handler gets called at least once on each line of a function.
     1.5 +
     1.6 +var g = newGlobal();
     1.7 +var dbg = new Debugger(g);
     1.8 +
     1.9 +// When we hit a 'debugger' statement, set offsets to the frame's script's
    1.10 +// table of line offsets --- a sparse array indexed by line number. Begin
    1.11 +// single-stepping the current frame; for each source line we hit, delete
    1.12 +// the line's entry in offsets. Thus, at the end, offsets is an array with
    1.13 +// an element for each line we did not reach.
    1.14 +var doSingleStep = true;
    1.15 +var offsets;
    1.16 +dbg.onDebuggerStatement = function (frame) {
    1.17 +    var script = frame.script;
    1.18 +    offsets = script.getAllOffsets();
    1.19 +    print("debugger line: " + script.getOffsetLine(frame.offset));
    1.20 +    print("original lines: " + uneval(Object.keys(offsets)));
    1.21 +    if (doSingleStep) {
    1.22 +	frame.onStep = function onStepHandler() {
    1.23 +	    var line = script.getOffsetLine(this.offset);
    1.24 +	    delete offsets[line];
    1.25 +	};
    1.26 +    }
    1.27 +};
    1.28 +
    1.29 +g.eval(
    1.30 +       'function t(a, b, c) {                \n' +
    1.31 +       '    debugger;                        \n' +
    1.32 +       '    var x = a;                       \n' +
    1.33 +       '    x += b;                          \n' +
    1.34 +       '    if (x < 10)                      \n' +
    1.35 +       '        x -= c;                      \n' +
    1.36 +       '    return x;                        \n' +
    1.37 +       '}                                    \n'
    1.38 +       );
    1.39 +
    1.40 +// This should stop at every line but the first of the function.
    1.41 +g.eval('t(1,2,3)');
    1.42 +assertEq(Object.keys(offsets).length, 1);
    1.43 +
    1.44 +// This should stop at every line but the first of the function, and the
    1.45 +// body of the 'if'.
    1.46 +g.eval('t(10,20,30)');
    1.47 +assertEq(Object.keys(offsets).length, 2);
    1.48 +
    1.49 +// This shouldn't stop at all. It's the frame that's in single-step mode,
    1.50 +// not the script, so the prior execution of t in single-step mode should
    1.51 +// have no effect on this one.
    1.52 +doSingleStep = false;
    1.53 +g.eval('t(0, 0, 0)');
    1.54 +assertEq(Object.keys(offsets).length, 6);
    1.55 +doSingleStep = true;
    1.56 +
    1.57 +// Single-step in an eval frame. This should reach every line but the
    1.58 +// first.
    1.59 +g.eval(
    1.60 +       'debugger;                        \n' +
    1.61 +       'var a=1, b=2, c=3;               \n' +
    1.62 +       'var x = a;                       \n' +
    1.63 +       'x += b;                          \n' +
    1.64 +       'if (x < 10)                      \n' +
    1.65 +       '    x -= c;                      \n'
    1.66 +       );
    1.67 +print("final lines: " + uneval(Object.keys(offsets)));
    1.68 +assertEq(Object.keys(offsets).length, 1);
    1.69 +
    1.70 +// Single-step in a global code frame. This should reach every line but the
    1.71 +// first.
    1.72 +g.evaluate(
    1.73 +           'debugger;                        \n' +
    1.74 +           'var a=1, b=2, c=3;               \n' +
    1.75 +           'var x = a;                       \n' +
    1.76 +           'x += b;                          \n' +
    1.77 +           'if (x < 10)                      \n' +
    1.78 +           '    x -= c;                      \n'
    1.79 +           );
    1.80 +print("final lines: " + uneval(Object.keys(offsets)));
    1.81 +assertEq(Object.keys(offsets).length, 1);

mercurial