OLD | NEW |
| (Empty) |
1 // Copyright 2010 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 // Flags: --expose-debug-as debug | |
29 // Get the Debug object exposed from the debug context global object. | |
30 Debug = debug.Debug | |
31 | |
32 listener_complete = false; | |
33 exception = false; | |
34 break_count = 0; | |
35 expected_return_value = 0; | |
36 debugger_source_position = 0; | |
37 | |
38 // Listener which expects to do four steps to reach returning from the function. | |
39 function listener(event, exec_state, event_data, data) { | |
40 try { | |
41 if (event == Debug.DebugEvent.Break) | |
42 { | |
43 break_count++; | |
44 if (break_count < 4) { | |
45 assertFalse(exec_state.frame(0).isAtReturn()) | |
46 switch (break_count) { | |
47 case 1: | |
48 // Collect the position of the debugger statement. | |
49 debugger_source_position = exec_state.frame(0).sourcePosition(); | |
50 break; | |
51 case 2: | |
52 // Position now at the if statement. | |
53 assertEquals(debugger_source_position + 10, | |
54 exec_state.frame(0).sourcePosition()); | |
55 break; | |
56 case 3: | |
57 // Position now at either of the returns. | |
58 if (expected_return_value == 1) { | |
59 assertEquals(debugger_source_position + 19, | |
60 exec_state.frame(0).sourcePosition()); | |
61 } else { | |
62 assertEquals(debugger_source_position + 38, | |
63 exec_state.frame(0).sourcePosition()); | |
64 } | |
65 break; | |
66 default: | |
67 fail("Unexpected"); | |
68 } | |
69 exec_state.prepareStep(Debug.StepAction.StepIn); | |
70 } else { | |
71 // Position at the end of the function. | |
72 assertEquals(debugger_source_position + 50, | |
73 exec_state.frame(0).sourcePosition()); | |
74 | |
75 // Just about to return from the function. | |
76 assertTrue(exec_state.frame(0).isAtReturn()) | |
77 assertEquals(expected_return_value, | |
78 exec_state.frame(0).returnValue().value()); | |
79 | |
80 listener_complete = true; | |
81 } | |
82 } | |
83 } catch (e) { | |
84 exception = e | |
85 print(e + e.stack) | |
86 }; | |
87 }; | |
88 | |
89 // Add the debug event listener. | |
90 Debug.setListener(listener); | |
91 | |
92 // Four steps from the debugger statement in this function will position us at | |
93 // the function return. | |
94 // 0 1 2 3 4 5 | |
95 // 0123456789012345678901234567890123456789012345678901 | |
96 | |
97 function f(x) {debugger; if (x) { return 1; } else { return 2; } }; | |
98 | |
99 // Call f expecting different return values. | |
100 break_count = 0; | |
101 expected_return_value = 2; | |
102 listener_complete = false; | |
103 f(); | |
104 assertFalse(exception, "exception in listener") | |
105 assertTrue(listener_complete); | |
106 assertEquals(4, break_count); | |
107 | |
108 break_count = 0; | |
109 expected_return_value = 1; | |
110 listener_complete = false; | |
111 f(true); | |
112 assertFalse(exception, "exception in listener") | |
113 assertTrue(listener_complete); | |
114 assertEquals(4, break_count); | |
115 | |
116 break_count = 0; | |
117 expected_return_value = 2; | |
118 listener_complete = false; | |
119 f(false); | |
120 assertFalse(exception, "exception in listener") | |
121 assertTrue(listener_complete); | |
122 assertEquals(4, break_count); | |
OLD | NEW |