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.

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

mercurial