|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Check that execution doesn't pause twice while stepping, when encountering |
|
6 * either a breakpoint or a debugger statement. |
|
7 */ |
|
8 |
|
9 var gDebuggee; |
|
10 var gClient; |
|
11 var gThreadClient; |
|
12 |
|
13 function run_test() |
|
14 { |
|
15 initTestDebuggerServer(); |
|
16 gDebuggee = addTestGlobal("test-stack"); |
|
17 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
18 gClient.connect(function () { |
|
19 attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) { |
|
20 gThreadClient = aThreadClient; |
|
21 test_simple_breakpoint(); |
|
22 }); |
|
23 }); |
|
24 do_test_pending(); |
|
25 } |
|
26 |
|
27 function test_simple_breakpoint() |
|
28 { |
|
29 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
30 let path = getFilePath('test_breakpoint-13.js'); |
|
31 let location = { url: path, line: gDebuggee.line0 + 2}; |
|
32 gThreadClient.setBreakpoint(location, function (aResponse, bpClient) { |
|
33 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
34 // Check that the stepping worked. |
|
35 do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 5); |
|
36 do_check_eq(aPacket.why.type, "resumeLimit"); |
|
37 |
|
38 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
39 // Entered the foo function call frame. |
|
40 do_check_eq(aPacket.frame.where.line, location.line); |
|
41 do_check_neq(aPacket.why.type, "breakpoint"); |
|
42 do_check_eq(aPacket.why.type, "resumeLimit"); |
|
43 |
|
44 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
45 // Check that the breakpoint wasn't the reason for this pause, but |
|
46 // that the frame is about to be popped while stepping. |
|
47 do_check_eq(aPacket.frame.where.line, location.line); |
|
48 do_check_neq(aPacket.why.type, "breakpoint"); |
|
49 do_check_eq(aPacket.why.type, "resumeLimit"); |
|
50 do_check_eq(aPacket.why.frameFinished.return.type, "undefined"); |
|
51 |
|
52 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
53 // The foo function call frame was just popped from the stack. |
|
54 do_check_eq(gDebuggee.a, 1); |
|
55 do_check_eq(gDebuggee.b, undefined); |
|
56 do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 5); |
|
57 do_check_eq(aPacket.why.type, "resumeLimit"); |
|
58 do_check_eq(aPacket.poppedFrames.length, 1); |
|
59 |
|
60 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
61 // Check that the debugger statement wasn't the reason for this pause. |
|
62 do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 6); |
|
63 do_check_neq(aPacket.why.type, "debuggerStatement"); |
|
64 do_check_eq(aPacket.why.type, "resumeLimit"); |
|
65 |
|
66 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
67 // Check that the debugger statement wasn't the reason for this pause. |
|
68 do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 7); |
|
69 do_check_neq(aPacket.why.type, "debuggerStatement"); |
|
70 do_check_eq(aPacket.why.type, "resumeLimit"); |
|
71 |
|
72 // Remove the breakpoint and finish. |
|
73 bpClient.remove(() => gThreadClient.resume(() => finishClient(gClient))); |
|
74 |
|
75 }); |
|
76 // Step past the debugger statement. |
|
77 gThreadClient.stepIn(); |
|
78 }); |
|
79 // Step into the debugger statement. |
|
80 gThreadClient.stepIn(); |
|
81 }); |
|
82 // Get back to the frame above. |
|
83 gThreadClient.stepIn(); |
|
84 }); |
|
85 // Step to the end of the function call frame. |
|
86 gThreadClient.stepIn(); |
|
87 }); |
|
88 |
|
89 // Step into the function call. |
|
90 gThreadClient.stepIn(); |
|
91 }); |
|
92 // Step into the next line with the function call. |
|
93 gThreadClient.stepIn(); |
|
94 }); |
|
95 }); |
|
96 |
|
97 gDebuggee.eval("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 } |