js/src/jit-test/tests/debug/Script-getLineOffsets-05.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // getLineOffsets identifies multiple ways to land on a line.
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.script, lineno, offs;
michael@0 9
michael@0 10 lineno = g.line0 + where;
michael@0 11 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 () { g.log += 'B'; }});
michael@0 15 }
michael@0 16
michael@0 17 lineno++;
michael@0 18 offs = s.getLineOffsets(lineno);
michael@0 19 for (var i = 0; i < offs.length; i++) {
michael@0 20 assertEq(s.getOffsetLine(offs[i]), lineno);
michael@0 21 s.setBreakpoint(offs[i], {hit: function () { g.log += 'C'; }});
michael@0 22 }
michael@0 23
michael@0 24 g.log += 'A';
michael@0 25 };
michael@0 26
michael@0 27 function test(s) {
michael@0 28 assertEq(s.charAt(s.length - 1), '\n');
michael@0 29 var count = (s.split(/\n/).length - 1); // number of lines in s
michael@0 30 g.log = '';
michael@0 31 where = 1 + count;
michael@0 32 g.eval("line0 = Error().lineNumber;\n" +
michael@0 33 "debugger;\n" + // line0 + 1
michael@0 34 s + // line0 + 2 ... line0 + where
michael@0 35 "log += 'D';\n");
michael@0 36 assertEq(g.log, 'AB!CD');
michael@0 37 }
michael@0 38
michael@0 39 // if-statement with yes and no paths on a single line
michael@0 40 g.i = 0;
michael@0 41 test("if (i === 0)\n" +
michael@0 42 " log += '!'; else log += 'X';\n");
michael@0 43 test("if (i === 2)\n" +
michael@0 44 " log += 'X'; else log += '!';\n");
michael@0 45
michael@0 46 // break to a line that has code inside and outside the loop
michael@0 47 g.i = 2;
michael@0 48 test("while (1) {\n" +
michael@0 49 " if (i === 2) break;\n" +
michael@0 50 " log += 'X'; } log += '!';\n");
michael@0 51
michael@0 52 // leaving a while loop by failing the test, when the last line has stuff both inside and outside the loop
michael@0 53 g.i = 0;
michael@0 54 test("while (i > 0) {\n" +
michael@0 55 " if (i === 70) log += 'X';\n" +
michael@0 56 " --i; } log += '!';\n");
michael@0 57
michael@0 58 // multiple case-labels on the same line
michael@0 59 g.i = 0;
michael@0 60 test("switch (i) {\n" +
michael@0 61 " case 0: case 1: log += '!'; break; }\n");
michael@0 62 test("switch ('' + i) {\n" +
michael@0 63 " case '0': case '1': log += '!'; break; }\n");
michael@0 64 test("switch (i) {\n" +
michael@0 65 " case 'ok' + i: case i - i: log += '!'; break; }\n");

mercurial