PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/zpao/v8monkey
JavaScript | 99 lines | 77 code | 13 blank | 9 comment | 1 complexity | ff70166b36dd88a413de4034efaf989a MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, LGPL-2.1, BSD-3-Clause, GPL-2.0, JSON, Apache-2.0, 0BSD
  1. // getLineOffsets works with extended instructions, such as JSOP_GOTOX.
  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;
  8. var offs;
  9. var lineno = g.line0 + where;
  10. offs = s.getLineOffsets(lineno);
  11. for (var i = 0; i < offs.length; i++) {
  12. assertEq(s.getOffsetLine(offs[i]), lineno);
  13. s.setBreakpoint(offs[i], {hit: function (frame) { g.log += 'B'; }});
  14. }
  15. g.log += 'A';
  16. };
  17. function test(s) {
  18. assertEq(s.charAt(s.length - 1) !== '\n', true);
  19. var count = s.split(/\n/).length; // number of lines in s
  20. g.i = 0;
  21. g.log = '';
  22. where = 1 + count;
  23. g.eval("line0 = Error().lineNumber;\n" +
  24. "debugger;\n" + // line0 + 1
  25. s + // line0 + 2 ... line0 + where
  26. " log += 'C';\n");
  27. assertEq(g.log, 'ABC');
  28. }
  29. function repeat(s) {
  30. return Array((1 << 14) + 1).join(s); // 16K copies of s
  31. }
  32. var long_expr = "i" + repeat(" + i");
  33. var long_throw_stmt = "throw " + long_expr + ";\n";
  34. // long break (JSOP_GOTOX)
  35. test("for (;;) {\n" +
  36. " if (i === 0)\n" +
  37. " break;\n" +
  38. " " + long_throw_stmt +
  39. "}");
  40. // long continue (JSOP_GOTOX)
  41. test("do {\n" +
  42. " if (i === 0)\n" +
  43. " continue;\n" +
  44. " " + long_throw_stmt +
  45. "} while (i !== 0);");
  46. // long if consequent (JSOP_IFEQX)
  47. test("if (i === 2) {\n" +
  48. " " + long_throw_stmt +
  49. "}");
  50. // long catch-block with finally (JSOP_GOSUBX)
  51. test("try {\n" +
  52. " i = 0;\n" +
  53. "} catch (exc) {\n" +
  54. " throw " + long_expr + ";\n" +
  55. "} finally {\n" +
  56. " i = 1;\n" +
  57. "}");
  58. // long case (JSOP_TABLESWITCHX)
  59. test("switch (i) {\n" +
  60. " default:\n" +
  61. " case 1: " + long_throw_stmt +
  62. " case 0: i++; }");
  63. test("switch (i) {\n" +
  64. " case 1: case 2: case 3: " + long_throw_stmt +
  65. " default: i++; }");
  66. // long case (JSOP_LOOKUPSWITCHX)
  67. test("switch ('' + i) {\n" +
  68. " default:\n" +
  69. " case '1': " + long_throw_stmt +
  70. " case '0': i++; }");
  71. test("switch (i) {\n" +
  72. " case '1': case '2': case '3': " + long_throw_stmt +
  73. " default: i++; }");
  74. // long case or case-expression (JSOP_CASEX)
  75. test("switch (i) {\n" +
  76. " case i + 1 - i:\n" +
  77. " default:\n" +
  78. " " + long_throw_stmt +
  79. " case i + i:\n" +
  80. " i++; break; }");
  81. // long case when JSOP_CASE is used (JSOP_DEFAULTX)
  82. test("switch (i) {\n" +
  83. " case i + 1 - i:\n" +
  84. " " + long_throw_stmt +
  85. " default:\n" +
  86. " i++; break; }");