| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 assertEquals(void 0, e); | 47 assertEquals(void 0, e); |
| 48 return undefined; | 48 return undefined; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 function testArguments(dcp, arguments, success, is_script) { | 52 function testArguments(dcp, arguments, success, is_script) { |
| 53 var request = '{' + base_request + ',"arguments":' + arguments + '}' | 53 var request = '{' + base_request + ',"arguments":' + arguments + '}' |
| 54 var json_response = dcp.processDebugJSONRequest(request); | 54 var json_response = dcp.processDebugJSONRequest(request); |
| 55 var response = safeEval(json_response); | 55 var response = safeEval(json_response); |
| 56 if (success) { | 56 if (success) { |
| 57 assertTrue(response.success, json_response); | 57 assertTrue(response.success, request + ' -> ' + json_response); |
| 58 if (is_script) { | 58 if (is_script) { |
| 59 assertEquals('scriptName', response.body.type, json_response); | 59 assertEquals('scriptName', response.body.type, request + ' -> ' + json_res
ponse); |
| 60 } else { | 60 } else { |
| 61 assertEquals('scriptId', response.body.type, json_response); | 61 assertEquals('scriptId', response.body.type, request + ' -> ' + json_respo
nse); |
| 62 } | 62 } |
| 63 } else { | 63 } else { |
| 64 assertFalse(response.success, json_response); | 64 assertFalse(response.success, request + ' -> ' + json_response); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 function listener(event, exec_state, event_data, data) { | 68 function listener(event, exec_state, event_data, data) { |
| 69 try { | 69 try { |
| 70 if (event == Debug.DebugEvent.Break) { | 70 if (event == Debug.DebugEvent.Break) { |
| 71 // Get the debug command processor. | 71 // Get the debug command processor. |
| 72 var dcp = exec_state.debugCommandProcessor(); | 72 var dcp = exec_state.debugCommandProcessor(); |
| 73 | 73 |
| 74 // Test some illegal setbreakpoint requests. | 74 // Test some illegal setbreakpoint requests. |
| 75 var request = '{' + base_request + '}' | 75 var request = '{' + base_request + '}' |
| 76 var response = safeEval(dcp.processDebugJSONRequest(request)); | 76 var response = safeEval(dcp.processDebugJSONRequest(request)); |
| 77 assertFalse(response.success); | 77 assertFalse(response.success); |
| 78 |
| 79 var mirror; |
| 78 | 80 |
| 79 testArguments(dcp, '{}', false); | 81 testArguments(dcp, '{}', false); |
| 80 testArguments(dcp, '{"type":"xx"}', false); | 82 testArguments(dcp, '{"type":"xx"}', false); |
| 81 testArguments(dcp, '{"type":"function"}', false); | 83 testArguments(dcp, '{"type":"function"}', false); |
| 82 testArguments(dcp, '{"type":"script"}', false); | 84 testArguments(dcp, '{"type":"script"}', false); |
| 83 testArguments(dcp, '{"target":"f"}', false); | 85 testArguments(dcp, '{"target":"f"}', false); |
| 84 testArguments(dcp, '{"type":"xx","target":"xx"}', false); | 86 testArguments(dcp, '{"type":"xx","target":"xx"}', false); |
| 85 testArguments(dcp, '{"type":"function","target":1}', false); | 87 testArguments(dcp, '{"type":"function","target":1}', false); |
| 86 testArguments(dcp, '{"type":"function","target":"f","line":-1}', false); | 88 testArguments(dcp, '{"type":"function","target":"f","line":-1}', false); |
| 87 testArguments(dcp, '{"type":"function","target":"f","column":-1}', false); | 89 testArguments(dcp, '{"type":"function","target":"f","column":-1}', false); |
| 88 testArguments(dcp, '{"type":"function","target":"f","ignoreCount":-1}', fals
e); | 90 testArguments(dcp, '{"type":"function","target":"f","ignoreCount":-1}', fals
e); |
| 91 testArguments(dcp, '{"type":"handle","target":"-1"}', false); |
| 92 mirror = debug.MakeMirror(o); |
| 93 testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', fal
se); |
| 89 | 94 |
| 90 // Test some legal setbreakpoint requests. | 95 // Test some legal setbreakpoint requests. |
| 91 testArguments(dcp, '{"type":"function","target":"f"}', true, false); | 96 testArguments(dcp, '{"type":"function","target":"f"}', true, false); |
| 92 testArguments(dcp, '{"type":"function","target":"h"}', true, false); | 97 testArguments(dcp, '{"type":"function","target":"h"}', true, false); |
| 93 testArguments(dcp, '{"type":"function","target":"f","line":1}', true, false)
; | 98 testArguments(dcp, '{"type":"function","target":"f","line":1}', true, false)
; |
| 94 testArguments(dcp, '{"type":"function","target":"f","position":1}', true, fa
lse); | 99 testArguments(dcp, '{"type":"function","target":"f","position":1}', true, fa
lse); |
| 95 testArguments(dcp, '{"type":"function","target":"f","condition":"i == 1"}',
true, false); | 100 testArguments(dcp, '{"type":"function","target":"f","condition":"i == 1"}',
true, false); |
| 96 testArguments(dcp, '{"type":"function","target":"f","enabled":true}', true,
false); | 101 testArguments(dcp, '{"type":"function","target":"f","enabled":true}', true,
false); |
| 97 testArguments(dcp, '{"type":"function","target":"f","enabled":false}', true,
false); | 102 testArguments(dcp, '{"type":"function","target":"f","enabled":false}', true,
false); |
| 98 testArguments(dcp, '{"type":"function","target":"f","ignoreCount":7}', true,
false); | 103 testArguments(dcp, '{"type":"function","target":"f","ignoreCount":7}', true,
false); |
| 99 | 104 |
| 100 testArguments(dcp, '{"type":"script","target":"test"}', true, true); | 105 testArguments(dcp, '{"type":"script","target":"test"}', true, true); |
| 101 testArguments(dcp, '{"type":"script","target":"test"}', true, true); | 106 testArguments(dcp, '{"type":"script","target":"test"}', true, true); |
| 102 testArguments(dcp, '{"type":"script","target":"test","line":1}', true, true)
; | 107 testArguments(dcp, '{"type":"script","target":"test","line":1}', true, true)
; |
| 103 testArguments(dcp, '{"type":"script","target":"test","column":1}', true, tru
e); | 108 testArguments(dcp, '{"type":"script","target":"test","column":1}', true, tru
e); |
| 104 | 109 |
| 105 testArguments(dcp, '{"type":"scriptId","target":' + f_script_id + ',"line":'
+ f_line + '}', true, false); | 110 testArguments(dcp, '{"type":"scriptId","target":' + f_script_id + ',"line":'
+ f_line + '}', true, false); |
| 106 testArguments(dcp, '{"type":"scriptId","target":' + g_script_id + ',"line":'
+ g_line + '}', true, false); | 111 testArguments(dcp, '{"type":"scriptId","target":' + g_script_id + ',"line":'
+ g_line + '}', true, false); |
| 107 testArguments(dcp, '{"type":"scriptId","target":' + h_script_id + ',"line":'
+ h_line + '}', true, false); | 112 testArguments(dcp, '{"type":"scriptId","target":' + h_script_id + ',"line":'
+ h_line + '}', true, false); |
| 108 | 113 |
| 114 mirror = debug.MakeMirror(f); |
| 115 testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', tru
e, false); |
| 116 mirror = debug.MakeMirror(o.a); |
| 117 testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', tru
e, false); |
| 118 |
| 109 // Indicate that all was processed. | 119 // Indicate that all was processed. |
| 110 listenerComplete = true; | 120 listenerComplete = true; |
| 111 } | 121 } |
| 112 } catch (e) { | 122 } catch (e) { |
| 113 exception = e | 123 exception = e |
| 114 }; | 124 }; |
| 115 }; | 125 }; |
| 116 | 126 |
| 117 // Add the debug event listener. | 127 // Add the debug event listener. |
| 118 Debug.setListener(listener); | 128 Debug.setListener(listener); |
| 119 | 129 |
| 120 function f() { | 130 function f() { |
| 121 a=1 | 131 a=1 |
| 122 }; | 132 }; |
| 123 | 133 |
| 124 function g() { | 134 function g() { |
| 125 f(); | 135 f(); |
| 126 }; | 136 }; |
| 127 | 137 |
| 128 eval('function h(){}'); | 138 eval('function h(){}'); |
| 129 | 139 |
| 140 o = {a:function(){},b:function(){}} |
| 141 |
| 130 // Check the script ids for the test functions. | 142 // Check the script ids for the test functions. |
| 131 f_script_id = Debug.findScript(f).id; | 143 f_script_id = Debug.findScript(f).id; |
| 132 g_script_id = Debug.findScript(g).id; | 144 g_script_id = Debug.findScript(g).id; |
| 133 h_script_id = Debug.findScript(h).id; | 145 h_script_id = Debug.findScript(h).id; |
| 134 assertTrue(f_script_id > 0, "invalid script id for f"); | 146 assertTrue(f_script_id > 0, "invalid script id for f"); |
| 135 assertTrue(g_script_id > 0, "invalid script id for g"); | 147 assertTrue(g_script_id > 0, "invalid script id for g"); |
| 136 assertTrue(h_script_id > 0, "invalid script id for h"); | 148 assertTrue(h_script_id > 0, "invalid script id for h"); |
| 137 assertEquals(f_script_id, g_script_id); | 149 assertEquals(f_script_id, g_script_id); |
| 138 | 150 |
| 139 // Get the source line for the test functions. | 151 // Get the source line for the test functions. |
| 140 f_line = Debug.findFunctionSourceLocation(f).line; | 152 f_line = Debug.findFunctionSourceLocation(f).line; |
| 141 g_line = Debug.findFunctionSourceLocation(g).line; | 153 g_line = Debug.findFunctionSourceLocation(g).line; |
| 142 h_line = Debug.findFunctionSourceLocation(h).line; | 154 h_line = Debug.findFunctionSourceLocation(h).line; |
| 143 assertTrue(f_line > 0, "invalid line for f"); | 155 assertTrue(f_line > 0, "invalid line for f"); |
| 144 assertTrue(g_line > 0, "invalid line for g"); | 156 assertTrue(g_line > 0, "invalid line for g"); |
| 145 assertTrue(f_line < g_line); | 157 assertTrue(f_line < g_line); |
| 146 assertEquals(h_line, 0, "invalid line for h"); | 158 assertEquals(h_line, 0, "invalid line for h"); |
| 147 | 159 |
| 148 // Set a break point and call to invoke the debug event listener. | 160 // Set a break point and call to invoke the debug event listener. |
| 149 Debug.setBreakPoint(g, 0, 0); | 161 Debug.setBreakPoint(g, 0, 0); |
| 150 g(); | 162 g(); |
| 151 | 163 |
| 152 // Make sure that the debug event listener vas invoked. | 164 // Make sure that the debug event listener vas invoked. |
| 153 assertTrue(listenerComplete, "listener did not run to completion: " + exception)
; | 165 assertTrue(listenerComplete, "listener did not run to completion: " + exception)
; |
| OLD | NEW |