js/src/jit-test/tests/debug/Script-getLineOffsets-03.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 // getLineOffsets treats one-line compound statements as having only one entry-point.
michael@0 2 // (A breakpoint on a line that only executes once will only hit once.)
michael@0 3
michael@0 4 var g = newGlobal();
michael@0 5 g.line0 = null;
michael@0 6 var dbg = Debugger(g);
michael@0 7 var log;
michael@0 8 dbg.onDebuggerStatement = function (frame) {
michael@0 9 var s = frame.script;
michael@0 10 var lineno = g.line0 + 2;
michael@0 11 var offs = s.getLineOffsets(lineno);
michael@0 12 for (var i = 0; i < offs.length; i++) {
michael@0 13 assertEq(s.getOffsetLine(offs[i]), lineno);
michael@0 14 s.setBreakpoint(offs[i], {hit: function () { log += 'B'; }});
michael@0 15 }
michael@0 16 log += 'A';
michael@0 17 };
michael@0 18
michael@0 19 function test(s) {
michael@0 20 log = '';
michael@0 21 g.eval("line0 = Error().lineNumber;\n" +
michael@0 22 "debugger;\n" + // line0 + 1
michael@0 23 s); // line0 + 2
michael@0 24 assertEq(log, 'AB');
michael@0 25 }
michael@0 26
michael@0 27 g.i = 0;
michael@0 28 g.j = 0;
michael@0 29 test("{i++; i--; i++; i--; }");
michael@0 30 test("if (i === 0) i++; else i--;");
michael@0 31 test("while (i < 5) i++;");
michael@0 32 test("do --i; while (i > 0);");
michael@0 33 test("for (i = 0; i < 5; i++) j++;");
michael@0 34 test("for (var x in [0, 1, 2]) j++;");
michael@0 35 test("switch (i) { case 0: j = 0; case 1: j = 1; case 2: j = 2; default: j = i; }");
michael@0 36 test("switch (i) { case 'A': j = 0; case 'B': j = 1; case 'C': j = 2; default: j = i; }");

mercurial