js/src/jit-test/tests/debug/Script-getLineOffsets-04.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 works with instructions reachable only by breaking out of a loop or switch.
michael@0 2
michael@0 3 var g = newGlobal();
michael@0 4 g.line0 = null;
michael@0 5 var dbg = Debugger(g);
michael@0 6 var where;
michael@0 7 dbg.onDebuggerStatement = function (frame) {
michael@0 8 var s = frame.eval("f").return.script;
michael@0 9 var lineno = g.line0 + where;
michael@0 10 var offs = s.getLineOffsets(lineno);
michael@0 11 for (var i = 0; i < offs.length; i++) {
michael@0 12 assertEq(s.getOffsetLine(offs[i]), lineno);
michael@0 13 s.setBreakpoint(offs[i], {hit: function () { g.log += 'B'; }});
michael@0 14 }
michael@0 15 g.log += 'A';
michael@0 16 };
michael@0 17
michael@0 18 function test(s) {
michael@0 19 var count = (s.split(/\n/).length - 1); // number of newlines in s
michael@0 20 g.log = '';
michael@0 21 where = 3 + count + 1;
michael@0 22 g.eval("line0 = Error().lineNumber;\n" +
michael@0 23 "debugger;\n" + // line0 + 1
michael@0 24 "function f(i) {\n" + // line0 + 2
michael@0 25 s + // line0 + 3 ... line0 + where - 2
michael@0 26 " log += '?';\n" + // line0 + where - 1
michael@0 27 " log += '!';\n" + // line0 + where
michael@0 28 "}\n");
michael@0 29 g.f(0);
michael@0 30 assertEq(g.log, 'A?B!');
michael@0 31 }
michael@0 32
michael@0 33 test("i = 128;\n" +
michael@0 34 "for (;;) {\n" +
michael@0 35 " var x = i - 10;;\n" +
michael@0 36 " if (x < 0)\n" +
michael@0 37 " break;\n" +
michael@0 38 " i >>= 2;\n" +
michael@0 39 "}\n");
michael@0 40
michael@0 41 test("while (true)\n" +
michael@0 42 " if (++i === 2) break;\n");
michael@0 43
michael@0 44 test("do {\n" +
michael@0 45 " if (++i === 2) break;\n" +
michael@0 46 "} while (true);\n");
michael@0 47
michael@0 48 test("switch (i) {\n" +
michael@0 49 " case 2: return 7;\n" +
michael@0 50 " case 1: return 8;\n" +
michael@0 51 " case 0: break;\n" +
michael@0 52 " default: return -i;\n" +
michael@0 53 "}\n");

mercurial