js/src/jit-test/tests/debug/Script-getLineOffsets-06.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 extended instructions, such as JSOP_GOTOX.
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;
michael@0 9 var offs;
michael@0 10 var 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 (frame) { g.log += 'B'; }});
michael@0 15 }
michael@0 16 g.log += 'A';
michael@0 17 };
michael@0 18
michael@0 19 function test(s) {
michael@0 20 assertEq(s.charAt(s.length - 1) !== '\n', true);
michael@0 21 var count = s.split(/\n/).length; // number of lines in s
michael@0 22 g.i = 0;
michael@0 23 g.log = '';
michael@0 24 where = 1 + count;
michael@0 25 g.eval("line0 = Error().lineNumber;\n" +
michael@0 26 "debugger;\n" + // line0 + 1
michael@0 27 s + // line0 + 2 ... line0 + where
michael@0 28 " log += 'C';\n");
michael@0 29 assertEq(g.log, 'ABC');
michael@0 30 }
michael@0 31
michael@0 32 function repeat(s) {
michael@0 33 return Array((1 << 14) + 1).join(s); // 16K copies of s
michael@0 34 }
michael@0 35 var long_expr = "i" + repeat(" + i");
michael@0 36 var long_throw_stmt = "throw " + long_expr + ";\n";
michael@0 37
michael@0 38 // long break (JSOP_GOTOX)
michael@0 39 test("for (;;) {\n" +
michael@0 40 " if (i === 0)\n" +
michael@0 41 " break;\n" +
michael@0 42 " " + long_throw_stmt +
michael@0 43 "}");
michael@0 44
michael@0 45 // long continue (JSOP_GOTOX)
michael@0 46 test("do {\n" +
michael@0 47 " if (i === 0)\n" +
michael@0 48 " continue;\n" +
michael@0 49 " " + long_throw_stmt +
michael@0 50 "} while (i !== 0);");
michael@0 51
michael@0 52 // long if consequent (JSOP_IFEQX)
michael@0 53 test("if (i === 2) {\n" +
michael@0 54 " " + long_throw_stmt +
michael@0 55 "}");
michael@0 56
michael@0 57 // long catch-block with finally (JSOP_GOSUBX)
michael@0 58 test("try {\n" +
michael@0 59 " i = 0;\n" +
michael@0 60 "} catch (exc) {\n" +
michael@0 61 " throw " + long_expr + ";\n" +
michael@0 62 "} finally {\n" +
michael@0 63 " i = 1;\n" +
michael@0 64 "}");
michael@0 65
michael@0 66 // long case (JSOP_TABLESWITCHX)
michael@0 67 test("switch (i) {\n" +
michael@0 68 " default:\n" +
michael@0 69 " case 1: " + long_throw_stmt +
michael@0 70 " case 0: i++; }");
michael@0 71
michael@0 72 test("switch (i) {\n" +
michael@0 73 " case 1: case 2: case 3: " + long_throw_stmt +
michael@0 74 " default: i++; }");
michael@0 75
michael@0 76 // long case (JSOP_LOOKUPSWITCHX)
michael@0 77 test("switch ('' + i) {\n" +
michael@0 78 " default:\n" +
michael@0 79 " case '1': " + long_throw_stmt +
michael@0 80 " case '0': i++; }");
michael@0 81
michael@0 82 test("switch (i) {\n" +
michael@0 83 " case '1': case '2': case '3': " + long_throw_stmt +
michael@0 84 " default: i++; }");
michael@0 85
michael@0 86 // long case or case-expression (JSOP_CASEX)
michael@0 87 test("switch (i) {\n" +
michael@0 88 " case i + 1 - i:\n" +
michael@0 89 " default:\n" +
michael@0 90 " " + long_throw_stmt +
michael@0 91 " case i + i:\n" +
michael@0 92 " i++; break; }");
michael@0 93
michael@0 94 // long case when JSOP_CASE is used (JSOP_DEFAULTX)
michael@0 95 test("switch (i) {\n" +
michael@0 96 " case i + 1 - i:\n" +
michael@0 97 " " + long_throw_stmt +
michael@0 98 " default:\n" +
michael@0 99 " i++; break; }");

mercurial