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

http://github.com/zpao/v8monkey · JavaScript · 65 lines · 51 code · 9 blank · 5 comment · 2 complexity · c382e5f959930186462f6dcb258bc90c MD5 · raw file

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