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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Test that a frame's onStep handler gets called at least once on each line of a function.
     3 var g = newGlobal();
     4 var dbg = new Debugger(g);
     6 // When we hit a 'debugger' statement, set offsets to the frame's script's
     7 // table of line offsets --- a sparse array indexed by line number. Begin
     8 // single-stepping the current frame; for each source line we hit, delete
     9 // the line's entry in offsets. Thus, at the end, offsets is an array with
    10 // an element for each line we did not reach.
    11 var doSingleStep = true;
    12 var offsets;
    13 dbg.onDebuggerStatement = function (frame) {
    14     var script = frame.script;
    15     offsets = script.getAllOffsets();
    16     print("debugger line: " + script.getOffsetLine(frame.offset));
    17     print("original lines: " + uneval(Object.keys(offsets)));
    18     if (doSingleStep) {
    19 	frame.onStep = function onStepHandler() {
    20 	    var line = script.getOffsetLine(this.offset);
    21 	    delete offsets[line];
    22 	};
    23     }
    24 };
    26 g.eval(
    27        'function t(a, b, c) {                \n' +
    28        '    debugger;                        \n' +
    29        '    var x = a;                       \n' +
    30        '    x += b;                          \n' +
    31        '    if (x < 10)                      \n' +
    32        '        x -= c;                      \n' +
    33        '    return x;                        \n' +
    34        '}                                    \n'
    35        );
    37 // This should stop at every line but the first of the function.
    38 g.eval('t(1,2,3)');
    39 assertEq(Object.keys(offsets).length, 1);
    41 // This should stop at every line but the first of the function, and the
    42 // body of the 'if'.
    43 g.eval('t(10,20,30)');
    44 assertEq(Object.keys(offsets).length, 2);
    46 // This shouldn't stop at all. It's the frame that's in single-step mode,
    47 // not the script, so the prior execution of t in single-step mode should
    48 // have no effect on this one.
    49 doSingleStep = false;
    50 g.eval('t(0, 0, 0)');
    51 assertEq(Object.keys(offsets).length, 6);
    52 doSingleStep = true;
    54 // Single-step in an eval frame. This should reach every line but the
    55 // first.
    56 g.eval(
    57        'debugger;                        \n' +
    58        'var a=1, b=2, c=3;               \n' +
    59        'var x = a;                       \n' +
    60        'x += b;                          \n' +
    61        'if (x < 10)                      \n' +
    62        '    x -= c;                      \n'
    63        );
    64 print("final lines: " + uneval(Object.keys(offsets)));
    65 assertEq(Object.keys(offsets).length, 1);
    67 // Single-step in a global code frame. This should reach every line but the
    68 // first.
    69 g.evaluate(
    70            'debugger;                        \n' +
    71            'var a=1, b=2, c=3;               \n' +
    72            'var x = a;                       \n' +
    73            'x += b;                          \n' +
    74            'if (x < 10)                      \n' +
    75            '    x -= c;                      \n'
    76            );
    77 print("final lines: " + uneval(Object.keys(offsets)));
    78 assertEq(Object.keys(offsets).length, 1);

mercurial