OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 ParsedResponse.prototype.response = function() { | 62 ParsedResponse.prototype.response = function() { |
63 return this.response_; | 63 return this.response_; |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 ParsedResponse.prototype.body = function() { | 67 ParsedResponse.prototype.body = function() { |
68 return this.response_.body; | 68 return this.response_.body; |
69 } | 69 } |
70 | 70 |
71 | 71 |
| 72 ParsedResponse.prototype.running = function() { |
| 73 return this.response_.running; |
| 74 } |
| 75 |
| 76 |
72 ParsedResponse.prototype.lookup = function(handle) { | 77 ParsedResponse.prototype.lookup = function(handle) { |
73 return this.refs_[handle]; | 78 return this.refs_[handle]; |
74 } | 79 } |
75 | 80 |
76 | 81 |
77 function listener(event, exec_state, event_data, data) { | 82 function listener(event, exec_state, event_data, data) { |
78 try { | 83 try { |
79 if (event == Debug.DebugEvent.Break) { | 84 if (event == Debug.DebugEvent.Break) { |
80 // The expected backtrace is | 85 // The expected backtrace is |
81 // 0: f | 86 // 0: f |
82 // 1: m | 87 // 1: m |
83 // 2: g | 88 // 2: g |
84 // 3: [anonymous] | 89 // 3: [anonymous] |
85 | 90 |
86 var response; | 91 var response; |
87 var backtrace; | 92 var backtrace; |
88 var frame; | 93 var frame; |
89 var source; | 94 var source; |
90 | 95 |
91 // Get the debug command processor. | 96 var dcp; |
92 var dcp = exec_state.debugCommandProcessor(); | 97 // New copy of debug command processor paused state. |
| 98 dcp = exec_state.debugCommandProcessor(false); |
93 | 99 |
94 // Get the backtrace. | 100 // Get the backtrace. |
95 var json; | 101 var json; |
96 json = '{"seq":0,"type":"request","command":"backtrace"}' | 102 json = '{"seq":0,"type":"request","command":"backtrace"}' |
97 var resp = dcp.processDebugJSONRequest(json); | 103 var resp = dcp.processDebugJSONRequest(json); |
98 response = new ParsedResponse(resp); | 104 response = new ParsedResponse(resp); |
99 backtrace = response.body(); | 105 backtrace = response.body(); |
100 assertEquals(0, backtrace.fromFrame); | 106 assertEquals(0, backtrace.fromFrame); |
101 assertEquals(4, backtrace.toFrame); | 107 assertEquals(4, backtrace.toFrame); |
102 assertEquals(4, backtrace.totalFrames); | 108 assertEquals(4, backtrace.totalFrames); |
103 var frames = backtrace.frames; | 109 var frames = backtrace.frames; |
104 assertEquals(4, frames.length); | 110 assertEquals(4, frames.length); |
105 for (var i = 0; i < frames.length; i++) { | 111 for (var i = 0; i < frames.length; i++) { |
106 assertEquals('frame', frames[i].type); | 112 assertEquals('frame', frames[i].type); |
107 } | 113 } |
108 assertEquals(0, frames[0].index); | 114 assertEquals(0, frames[0].index); |
109 assertEquals("f", response.lookup(frames[0].func.ref).name); | 115 assertEquals("f", response.lookup(frames[0].func.ref).name); |
110 assertEquals(1, frames[1].index); | 116 assertEquals(1, frames[1].index); |
111 assertEquals("", response.lookup(frames[1].func.ref).name); | 117 assertEquals("", response.lookup(frames[1].func.ref).name); |
112 assertEquals("m", response.lookup(frames[1].func.ref).inferredName); | 118 assertEquals("m", response.lookup(frames[1].func.ref).inferredName); |
113 assertEquals(2, frames[2].index); | 119 assertEquals(2, frames[2].index); |
114 assertEquals("g", response.lookup(frames[2].func.ref).name); | 120 assertEquals("g", response.lookup(frames[2].func.ref).name); |
115 assertEquals(3, frames[3].index); | 121 assertEquals(3, frames[3].index); |
116 assertEquals("", response.lookup(frames[3].func.ref).name); | 122 assertEquals("", response.lookup(frames[3].func.ref).name); |
| 123 assertFalse(response.running(), "expected not running"); |
117 | 124 |
118 // Get backtrace with two frames. | 125 // Get backtrace with two frames. |
119 json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"from
Frame":1,"toFrame":3}}' | 126 json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"from
Frame":1,"toFrame":3}}' |
120 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | 127 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
121 backtrace = response.body(); | 128 backtrace = response.body(); |
122 assertEquals(1, backtrace.fromFrame); | 129 assertEquals(1, backtrace.fromFrame); |
123 assertEquals(3, backtrace.toFrame); | 130 assertEquals(3, backtrace.toFrame); |
124 assertEquals(4, backtrace.totalFrames); | 131 assertEquals(4, backtrace.totalFrames); |
125 var frames = backtrace.frames; | 132 var frames = backtrace.frames; |
126 assertEquals(2, frames.length); | 133 assertEquals(2, frames.length); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 '"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}' | 234 '"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}' |
228 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | 235 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
229 assertFalse(response.response().success); | 236 assertFalse(response.response().success); |
230 | 237 |
231 // Test without arguments. | 238 // Test without arguments. |
232 json = '{"seq":0,"type":"request","command":"source"}' | 239 json = '{"seq":0,"type":"request","command":"source"}' |
233 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | 240 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
234 source = response.body(); | 241 source = response.body(); |
235 assertEquals(Debug.findScript(f).source, source.source); | 242 assertEquals(Debug.findScript(f).source, source.source); |
236 | 243 |
| 244 // New copy of debug command processor in running state. |
| 245 dcp = exec_state.debugCommandProcessor(true); |
| 246 // Get the backtrace. |
| 247 json = '{"seq":0,"type":"request","command":"backtrace"}' |
| 248 resp = dcp.processDebugJSONRequest(json); |
| 249 response = new ParsedResponse(resp); |
| 250 // It might be argueable, but we expect response to have body when |
| 251 // not suspended |
| 252 assertTrue(!!response.body(), "response should be null"); |
| 253 assertTrue(response.running(), "expected running"); |
| 254 |
237 listenerCalled = true; | 255 listenerCalled = true; |
238 } | 256 } |
239 } catch (e) { | 257 } catch (e) { |
240 exception = e | 258 exception = e |
241 }; | 259 }; |
242 }; | 260 }; |
243 | 261 |
244 // Add the debug event listener. | 262 // Add the debug event listener. |
245 Debug.setListener(listener); | 263 Debug.setListener(listener); |
246 | 264 |
247 // Set a break point and call to invoke the debug event listener. | 265 // Set a break point and call to invoke the debug event listener. |
248 Debug.setBreakPoint(f, 0, 0); | 266 Debug.setBreakPoint(f, 0, 0); |
249 g(); | 267 g(); |
250 | 268 |
251 // Make sure that the debug event listener vas invoked. | 269 // Make sure that the debug event listener vas invoked. |
252 assertFalse(exception, "exception in listener"); | 270 assertFalse(exception, "exception in listener"); |
253 assertTrue(listenerCalled); | 271 assertTrue(listenerCalled); |
254 | 272 |
OLD | NEW |