| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 ParsedResponse.prototype.lookup = function(handle) { | 72 ParsedResponse.prototype.lookup = function(handle) { |
| 73 return this.refs_[handle]; | 73 return this.refs_[handle]; |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 function listener(event, exec_state, event_data, data) { | 77 function listener(event, exec_state, event_data, data) { |
| 78 try { | 78 try { |
| 79 if (event == Debug.DebugEvent.Break) | 79 if (event == Debug.DebugEvent.Break) { |
| 80 { | 80 // The expected backtrace is |
| 81 // The expected backtrace is | 81 // 0: f |
| 82 // 0: f | 82 // 1: m |
| 83 // 1: m | 83 // 2: g |
| 84 // 2: g | 84 // 3: [anonymous] |
| 85 // 3: [anonymous] | |
| 86 | |
| 87 var response; | |
| 88 var backtrace; | |
| 89 var frame; | |
| 90 var source; | |
| 91 | |
| 92 // Get the debug command processor. | |
| 93 var dcp = exec_state.debugCommandProcessor(); | |
| 94 | 85 |
| 95 // Get the backtrace. | 86 var response; |
| 96 var json; | 87 var backtrace; |
| 97 json = '{"seq":0,"type":"request","command":"backtrace"}' | 88 var frame; |
| 98 var resp = dcp.processDebugJSONRequest(json); | 89 var source; |
| 99 response = new ParsedResponse(resp); | 90 |
| 100 backtrace = response.body(); | 91 // Get the debug command processor. |
| 101 assertEquals(0, backtrace.fromFrame); | 92 var dcp = exec_state.debugCommandProcessor(); |
| 102 assertEquals(4, backtrace.toFrame); | 93 |
| 103 assertEquals(4, backtrace.totalFrames); | 94 // Get the backtrace. |
| 104 var frames = backtrace.frames; | 95 var json; |
| 105 assertEquals(4, frames.length); | 96 json = '{"seq":0,"type":"request","command":"backtrace"}' |
| 106 for (var i = 0; i < frames.length; i++) { | 97 var resp = dcp.processDebugJSONRequest(json); |
| 107 assertEquals('frame', frames[i].type); | 98 response = new ParsedResponse(resp); |
| 99 backtrace = response.body(); |
| 100 assertEquals(0, backtrace.fromFrame); |
| 101 assertEquals(4, backtrace.toFrame); |
| 102 assertEquals(4, backtrace.totalFrames); |
| 103 var frames = backtrace.frames; |
| 104 assertEquals(4, frames.length); |
| 105 for (var i = 0; i < frames.length; i++) { |
| 106 assertEquals('frame', frames[i].type); |
| 107 } |
| 108 assertEquals(0, frames[0].index); |
| 109 assertEquals("f", response.lookup(frames[0].func.ref).name); |
| 110 assertEquals(1, frames[1].index); |
| 111 assertEquals("", response.lookup(frames[1].func.ref).name); |
| 112 assertEquals("m", response.lookup(frames[1].func.ref).inferredName); |
| 113 assertEquals(2, frames[2].index); |
| 114 assertEquals("g", response.lookup(frames[2].func.ref).name); |
| 115 assertEquals(3, frames[3].index); |
| 116 assertEquals("", response.lookup(frames[3].func.ref).name); |
| 117 |
| 118 // Get backtrace with two frames. |
| 119 json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"from
Frame":1,"toFrame":3}}' |
| 120 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 121 backtrace = response.body(); |
| 122 assertEquals(1, backtrace.fromFrame); |
| 123 assertEquals(3, backtrace.toFrame); |
| 124 assertEquals(4, backtrace.totalFrames); |
| 125 var frames = backtrace.frames; |
| 126 assertEquals(2, frames.length); |
| 127 for (var i = 0; i < frames.length; i++) { |
| 128 assertEquals('frame', frames[i].type); |
| 129 } |
| 130 assertEquals(1, frames[0].index); |
| 131 assertEquals("", response.lookup(frames[0].func.ref).name); |
| 132 assertEquals("m", response.lookup(frames[0].func.ref).inferredName); |
| 133 assertEquals(2, frames[1].index); |
| 134 assertEquals("g", response.lookup(frames[1].func.ref).name); |
| 135 |
| 136 // Get backtrace with bottom two frames. |
| 137 json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"from
Frame":0,"toFrame":2, "bottom":true}}' |
| 138 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 139 backtrace = response.body(); |
| 140 assertEquals(2, backtrace.fromFrame); |
| 141 assertEquals(4, backtrace.toFrame); |
| 142 assertEquals(4, backtrace.totalFrames); |
| 143 var frames = backtrace.frames; |
| 144 assertEquals(2, frames.length); |
| 145 for (var i = 0; i < frames.length; i++) { |
| 146 assertEquals('frame', frames[i].type); |
| 147 } |
| 148 assertEquals(2, frames[0].index); |
| 149 assertEquals("g", response.lookup(frames[0].func.ref).name); |
| 150 assertEquals(3, frames[1].index); |
| 151 assertEquals("", response.lookup(frames[1].func.ref).name); |
| 152 |
| 153 // Get the individual frames. |
| 154 json = '{"seq":0,"type":"request","command":"frame"}' |
| 155 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 156 frame = response.body(); |
| 157 assertEquals(0, frame.index); |
| 158 assertEquals("f", response.lookup(frame.func.ref).name); |
| 159 assertTrue(frame.constructCall); |
| 160 assertEquals(31, frame.line); |
| 161 assertEquals(3, frame.column); |
| 162 assertEquals(2, frame.arguments.length); |
| 163 assertEquals('x', frame.arguments[0].name); |
| 164 assertEquals('number', response.lookup(frame.arguments[0].value.ref).type)
; |
| 165 assertEquals(1, response.lookup(frame.arguments[0].value.ref).value); |
| 166 assertEquals('y', frame.arguments[1].name); |
| 167 assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).ty
pe); |
| 168 |
| 169 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":
0}}' |
| 170 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 171 frame = response.body(); |
| 172 assertEquals(0, frame.index); |
| 173 assertEquals("f", response.lookup(frame.func.ref).name); |
| 174 assertEquals(31, frame.line); |
| 175 assertEquals(3, frame.column); |
| 176 assertEquals(2, frame.arguments.length); |
| 177 assertEquals('x', frame.arguments[0].name); |
| 178 assertEquals('number', response.lookup(frame.arguments[0].value.ref).type)
; |
| 179 assertEquals(1, response.lookup(frame.arguments[0].value.ref).value); |
| 180 assertEquals('y', frame.arguments[1].name); |
| 181 assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).ty
pe); |
| 182 |
| 183 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":
1}}' |
| 184 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 185 frame = response.body(); |
| 186 assertEquals(1, frame.index); |
| 187 assertEquals("", response.lookup(frame.func.ref).name); |
| 188 assertEquals("m", response.lookup(frame.func.ref).inferredName); |
| 189 assertFalse(frame.constructCall); |
| 190 assertEquals(35, frame.line); |
| 191 assertEquals(2, frame.column); |
| 192 assertEquals(0, frame.arguments.length); |
| 193 |
| 194 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":
3}}' |
| 195 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 196 frame = response.body(); |
| 197 assertEquals(3, frame.index); |
| 198 assertEquals("", response.lookup(frame.func.ref).name); |
| 199 |
| 200 // Source slices for the individual frames (they all refer to this script)
. |
| 201 json = '{"seq":0,"type":"request","command":"source",' + |
| 202 '"arguments":{"frame":0,"fromLine":30,"toLine":32}}' |
| 203 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 204 source = response.body(); |
| 205 assertEquals("function f(x, y) {", source.source.substring(0, 18)); |
| 206 assertEquals(30, source.fromLine); |
| 207 assertEquals(32, source.toLine); |
| 208 |
| 209 json = '{"seq":0,"type":"request","command":"source",' + |
| 210 '"arguments":{"frame":1,"fromLine":31,"toLine":32}}' |
| 211 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 212 source = response.body(); |
| 213 assertEquals(" a=1;", source.source.substring(0, 6)); |
| 214 assertEquals(31, source.fromLine); |
| 215 assertEquals(32, source.toLine); |
| 216 |
| 217 json = '{"seq":0,"type":"request","command":"source",' + |
| 218 '"arguments":{"frame":2,"fromLine":35,"toLine":36}}' |
| 219 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 220 source = response.body(); |
| 221 assertEquals(" new f(1);", source.source.substring(0, 11)); |
| 222 assertEquals(35, source.fromLine); |
| 223 assertEquals(36, source.toLine); |
| 224 |
| 225 // Test line interval way beyond this script will result in an error. |
| 226 json = '{"seq":0,"type":"request","command":"source",' + |
| 227 '"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}' |
| 228 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 229 assertFalse(response.response().success); |
| 230 |
| 231 // Test without arguments. |
| 232 json = '{"seq":0,"type":"request","command":"source"}' |
| 233 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); |
| 234 source = response.body(); |
| 235 assertEquals(Debug.findScript(f).source, source.source); |
| 236 |
| 237 listenerCalled = true; |
| 108 } | 238 } |
| 109 assertEquals(0, frames[0].index); | |
| 110 assertEquals("f", response.lookup(frames[0].func.ref).name); | |
| 111 assertEquals(1, frames[1].index); | |
| 112 assertEquals("", response.lookup(frames[1].func.ref).name); | |
| 113 assertEquals("m", response.lookup(frames[1].func.ref).inferredName); | |
| 114 assertEquals(2, frames[2].index); | |
| 115 assertEquals("g", response.lookup(frames[2].func.ref).name); | |
| 116 assertEquals(3, frames[3].index); | |
| 117 assertEquals("", response.lookup(frames[3].func.ref).name); | |
| 118 | |
| 119 // Get backtrace with two frames. | |
| 120 json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFr
ame":1,"toFrame":3}}' | |
| 121 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 122 backtrace = response.body(); | |
| 123 assertEquals(1, backtrace.fromFrame); | |
| 124 assertEquals(3, backtrace.toFrame); | |
| 125 assertEquals(4, backtrace.totalFrames); | |
| 126 var frames = backtrace.frames; | |
| 127 assertEquals(2, frames.length); | |
| 128 for (var i = 0; i < frames.length; i++) { | |
| 129 assertEquals('frame', frames[i].type); | |
| 130 } | |
| 131 assertEquals(1, frames[0].index); | |
| 132 assertEquals("", response.lookup(frames[0].func.ref).name); | |
| 133 assertEquals("m", response.lookup(frames[0].func.ref).inferredName); | |
| 134 assertEquals(2, frames[1].index); | |
| 135 assertEquals("g", response.lookup(frames[1].func.ref).name); | |
| 136 | |
| 137 // Get backtrace with bottom two frames. | |
| 138 json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFr
ame":0,"toFrame":2, "bottom":true}}' | |
| 139 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 140 backtrace = response.body(); | |
| 141 assertEquals(2, backtrace.fromFrame); | |
| 142 assertEquals(4, backtrace.toFrame); | |
| 143 assertEquals(4, backtrace.totalFrames); | |
| 144 var frames = backtrace.frames; | |
| 145 assertEquals(2, frames.length); | |
| 146 for (var i = 0; i < frames.length; i++) { | |
| 147 assertEquals('frame', frames[i].type); | |
| 148 } | |
| 149 assertEquals(2, frames[0].index); | |
| 150 assertEquals("g", response.lookup(frames[0].func.ref).name); | |
| 151 assertEquals(3, frames[1].index); | |
| 152 assertEquals("", response.lookup(frames[1].func.ref).name); | |
| 153 | |
| 154 // Get the individual frames. | |
| 155 json = '{"seq":0,"type":"request","command":"frame"}' | |
| 156 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 157 frame = response.body(); | |
| 158 assertEquals(0, frame.index); | |
| 159 assertEquals("f", response.lookup(frame.func.ref).name); | |
| 160 assertTrue(frame.constructCall); | |
| 161 assertEquals(31, frame.line); | |
| 162 assertEquals(3, frame.column); | |
| 163 assertEquals(2, frame.arguments.length); | |
| 164 assertEquals('x', frame.arguments[0].name); | |
| 165 assertEquals('number', response.lookup(frame.arguments[0].value.ref).type); | |
| 166 assertEquals(1, response.lookup(frame.arguments[0].value.ref).value); | |
| 167 assertEquals('y', frame.arguments[1].name); | |
| 168 assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).type
); | |
| 169 | |
| 170 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":0}
}' | |
| 171 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 172 frame = response.body(); | |
| 173 assertEquals(0, frame.index); | |
| 174 assertEquals("f", response.lookup(frame.func.ref).name); | |
| 175 assertEquals(31, frame.line); | |
| 176 assertEquals(3, frame.column); | |
| 177 assertEquals(2, frame.arguments.length); | |
| 178 assertEquals('x', frame.arguments[0].name); | |
| 179 assertEquals('number', response.lookup(frame.arguments[0].value.ref).type); | |
| 180 assertEquals(1, response.lookup(frame.arguments[0].value.ref).value); | |
| 181 assertEquals('y', frame.arguments[1].name); | |
| 182 assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).type
); | |
| 183 | |
| 184 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":1}
}' | |
| 185 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 186 frame = response.body(); | |
| 187 assertEquals(1, frame.index); | |
| 188 assertEquals("", response.lookup(frame.func.ref).name); | |
| 189 assertEquals("m", response.lookup(frame.func.ref).inferredName); | |
| 190 assertFalse(frame.constructCall); | |
| 191 assertEquals(35, frame.line); | |
| 192 assertEquals(2, frame.column); | |
| 193 assertEquals(0, frame.arguments.length); | |
| 194 | |
| 195 json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":3}
}' | |
| 196 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 197 frame = response.body(); | |
| 198 assertEquals(3, frame.index); | |
| 199 assertEquals("", response.lookup(frame.func.ref).name); | |
| 200 | |
| 201 // Source slices for the individual frames (they all refer to this script). | |
| 202 json = '{"seq":0,"type":"request","command":"source",' + | |
| 203 '"arguments":{"frame":0,"fromLine":30,"toLine":32}}' | |
| 204 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 205 source = response.body(); | |
| 206 assertEquals("function f(x, y) {", source.source.substring(0, 18)); | |
| 207 assertEquals(30, source.fromLine); | |
| 208 assertEquals(32, source.toLine); | |
| 209 | |
| 210 json = '{"seq":0,"type":"request","command":"source",' + | |
| 211 '"arguments":{"frame":1,"fromLine":31,"toLine":32}}' | |
| 212 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 213 source = response.body(); | |
| 214 assertEquals(" a=1;", source.source.substring(0, 6)); | |
| 215 assertEquals(31, source.fromLine); | |
| 216 assertEquals(32, source.toLine); | |
| 217 | |
| 218 json = '{"seq":0,"type":"request","command":"source",' + | |
| 219 '"arguments":{"frame":2,"fromLine":35,"toLine":36}}' | |
| 220 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 221 source = response.body(); | |
| 222 assertEquals(" new f(1);", source.source.substring(0, 11)); | |
| 223 assertEquals(35, source.fromLine); | |
| 224 assertEquals(36, source.toLine); | |
| 225 | |
| 226 // Test line interval way beyond this script will result in an error. | |
| 227 json = '{"seq":0,"type":"request","command":"source",' + | |
| 228 '"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}' | |
| 229 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 230 assertFalse(response.response().success); | |
| 231 | |
| 232 // Test without arguments. | |
| 233 json = '{"seq":0,"type":"request","command":"source"}' | |
| 234 response = new ParsedResponse(dcp.processDebugJSONRequest(json)); | |
| 235 source = response.body(); | |
| 236 assertEquals(Debug.findScript(f).source, source.source); | |
| 237 | |
| 238 listenerCalled = true; | |
| 239 } | |
| 240 } catch (e) { | 239 } catch (e) { |
| 241 exception = e | 240 exception = e |
| 242 }; | 241 }; |
| 243 }; | 242 }; |
| 244 | 243 |
| 245 // Add the debug event listener. | 244 // Add the debug event listener. |
| 246 Debug.setListener(listener); | 245 Debug.setListener(listener); |
| 247 | 246 |
| 248 // Set a break point and call to invoke the debug event listener. | 247 // Set a break point and call to invoke the debug event listener. |
| 249 Debug.setBreakPoint(f, 0, 0); | 248 Debug.setBreakPoint(f, 0, 0); |
| 250 g(); | 249 g(); |
| 251 | 250 |
| 252 // Make sure that the debug event listener vas invoked. | 251 // Make sure that the debug event listener vas invoked. |
| 253 assertFalse(exception, "exception in listener"); | 252 assertFalse(exception, "exception in listener"); |
| 254 assertTrue(listenerCalled); | 253 assertTrue(listenerCalled); |
| 255 | 254 |
| OLD | NEW |