test_breakpoint-13.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Check that execution doesn't pause twice while stepping, when encountering
  5. * either a breakpoint or a debugger statement.
  6. */
  7. var gDebuggee;
  8. var gClient;
  9. var gThreadClient;
  10. var gCallback;
  11. function run_test()
  12. {
  13. run_test_with_server(DebuggerServer, function () {
  14. run_test_with_server(WorkerDebuggerServer, do_test_finished);
  15. });
  16. do_test_pending();
  17. }
  18. function run_test_with_server(aServer, aCallback)
  19. {
  20. gCallback = aCallback;
  21. initTestDebuggerServer(aServer);
  22. gDebuggee = addTestGlobal("test-stack", aServer);
  23. gClient = new DebuggerClient(aServer.connectPipe());
  24. gClient.connect().then(function () {
  25. attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) {
  26. gThreadClient = aThreadClient;
  27. test_simple_breakpoint();
  28. });
  29. });
  30. }
  31. function test_simple_breakpoint()
  32. {
  33. gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  34. let source = gThreadClient.source(aPacket.frame.where.source);
  35. let location = { line: gDebuggee.line0 + 2 };
  36. source.setBreakpoint(location, Task.async(function* (aResponse, bpClient) {
  37. const testCallbacks = [
  38. function (aPacket) {
  39. // Check that the stepping worked.
  40. do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 5);
  41. do_check_eq(aPacket.why.type, "resumeLimit");
  42. },
  43. function (aPacket) {
  44. // Entered the foo function call frame.
  45. do_check_eq(aPacket.frame.where.line, location.line);
  46. do_check_neq(aPacket.why.type, "breakpoint");
  47. do_check_eq(aPacket.why.type, "resumeLimit");
  48. },
  49. function (aPacket) {
  50. // At the end of the foo function call frame.
  51. do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 3);
  52. do_check_neq(aPacket.why.type, "breakpoint");
  53. do_check_eq(aPacket.why.type, "resumeLimit");
  54. },
  55. function (aPacket) {
  56. // Check that the breakpoint wasn't the reason for this pause, but
  57. // that the frame is about to be popped while stepping.
  58. do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 3);
  59. do_check_neq(aPacket.why.type, "breakpoint");
  60. do_check_eq(aPacket.why.type, "resumeLimit");
  61. do_check_eq(aPacket.why.frameFinished.return.type, "undefined");
  62. },
  63. function (aPacket) {
  64. // The foo function call frame was just popped from the stack.
  65. do_check_eq(gDebuggee.a, 1);
  66. do_check_eq(gDebuggee.b, undefined);
  67. do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 5);
  68. do_check_eq(aPacket.why.type, "resumeLimit");
  69. do_check_eq(aPacket.poppedFrames.length, 1);
  70. },
  71. function (aPacket) {
  72. // Check that the debugger statement wasn't the reason for this pause.
  73. do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 6);
  74. do_check_neq(aPacket.why.type, "debuggerStatement");
  75. do_check_eq(aPacket.why.type, "resumeLimit");
  76. },
  77. function (aPacket) {
  78. // Check that the debugger statement wasn't the reason for this pause.
  79. do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 7);
  80. do_check_neq(aPacket.why.type, "debuggerStatement");
  81. do_check_eq(aPacket.why.type, "resumeLimit");
  82. },
  83. ];
  84. for (let callback of testCallbacks) {
  85. let waiter = waitForPause(gThreadClient);
  86. gThreadClient.stepIn();
  87. let packet = yield waiter;
  88. callback(packet);
  89. }
  90. // Remove the breakpoint and finish.
  91. let waiter = waitForPause(gThreadClient);
  92. gThreadClient.stepIn();
  93. yield waiter;
  94. bpClient.remove(() => gThreadClient.resume(() => gClient.close().then(gCallback)));
  95. }));
  96. });
  97. Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
  98. "function foo() {\n" + // line0 + 1
  99. " this.a = 1;\n" + // line0 + 2 <-- Breakpoint is set here.
  100. "}\n" + // line0 + 3
  101. "debugger;\n" + // line0 + 4
  102. "foo();\n" + // line0 + 5
  103. "debugger;\n" + // line0 + 6
  104. "var b = 2;\n", // line0 + 7
  105. gDebuggee);
  106. }