| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --expose-debug-as debug | 28 // Flags: --expose-debug-as debug |
| 29 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
| 30 Debug = debug.Debug | 30 Debug = debug.Debug; |
| 31 | 31 |
| 32 // Simple function which stores the last debug event. | 32 // Simple function which stores the last debug event. |
| 33 var listenerComplete = false; | 33 var listenerComplete = false; |
| 34 var exception = false; | 34 var exception = false; |
| 35 var f_script_id = 0; | 35 var f_script_id = 0; |
| 36 var g_script_id = 0; | 36 var g_script_id = 0; |
| 37 var h_script_id = 0; | 37 var h_script_id = 0; |
| 38 var f_line = 0; | 38 var f_line = 0; |
| 39 var g_line = 0; | 39 var g_line = 0; |
| 40 | 40 |
| 41 var base_request = '"seq":0,"type":"request","command":"setbreakpoint"' | 41 var base_request = '"seq":0,"type":"request","command":"setbreakpoint"'; |
| 42 | 42 |
| 43 function safeEval(code) { | 43 function safeEval(code) { |
| 44 try { | 44 try { |
| 45 return eval('(' + code + ')'); | 45 return eval('(' + code + ')'); |
| 46 } catch (e) { | 46 } catch (e) { |
| 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, request + ' -> ' + json_response); | 57 assertTrue(response.success, request + ' -> ' + json_response); |
| 58 if (is_script) { | 58 if (is_script) { |
| 59 assertEquals('scriptName', response.body.type, request + ' -> ' + json_res
ponse); | 59 assertEquals('scriptName', response.body.type, request + ' -> ' + json_res
ponse); |
| 60 } else { | 60 } else { |
| 61 assertEquals('scriptId', response.body.type, request + ' -> ' + json_respo
nse); | 61 assertEquals('scriptId', response.body.type, request + ' -> ' + json_respo
nse); |
| 62 } | 62 } |
| 63 } else { | 63 } else { |
| 64 assertFalse(response.success, request + ' -> ' + json_response); | 64 assertFalse(response.success, request + ' -> ' + json_response); |
| 65 } | 65 } |
| 66 return response; | 66 return response; |
| 67 } | 67 } |
| 68 | 68 |
| 69 function listener(event, exec_state, event_data, data) { | 69 function listener(event, exec_state, event_data, data) { |
| 70 try { | 70 try { |
| 71 if (event == Debug.DebugEvent.Break) { | 71 if (event == Debug.DebugEvent.Break) { |
| 72 // Get the debug command processor. | 72 // Get the debug command processor. |
| 73 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | 73 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
| 74 | 74 |
| 75 // Test some illegal setbreakpoint requests. | 75 // Test some illegal setbreakpoint requests. |
| 76 var request = '{' + base_request + '}' | 76 var request = '{' + base_request + '}'; |
| 77 var response = safeEval(dcp.processDebugJSONRequest(request)); | 77 var response = safeEval(dcp.processDebugJSONRequest(request)); |
| 78 assertFalse(response.success); | 78 assertFalse(response.success); |
| 79 | 79 |
| 80 var mirror; | 80 var mirror; |
| 81 | 81 |
| 82 testArguments(dcp, '{}', false); | 82 testArguments(dcp, '{}', false); |
| 83 testArguments(dcp, '{"type":"xx"}', false); | 83 testArguments(dcp, '{"type":"xx"}', false); |
| 84 testArguments(dcp, '{"type":"function"}', false); | 84 testArguments(dcp, '{"type":"function"}', false); |
| 85 testArguments(dcp, '{"type":"script"}', false); | 85 testArguments(dcp, '{"type":"script"}', false); |
| 86 testArguments(dcp, '{"target":"f"}', false); | 86 testArguments(dcp, '{"target":"f"}', false); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Set a break point on a line with the comment, and check that actual posit
ion | 122 // Set a break point on a line with the comment, and check that actual posit
ion |
| 123 // is the next line after the comment. | 123 // is the next line after the comment. |
| 124 request = '{"type":"scriptId","target":' + g_script_id + ',"line":' + (g_lin
e + 1) + '}'; | 124 request = '{"type":"scriptId","target":' + g_script_id + ',"line":' + (g_lin
e + 1) + '}'; |
| 125 response = testArguments(dcp, request, true, false); | 125 response = testArguments(dcp, request, true, false); |
| 126 assertEquals(g_line + 2, response.body.actual_locations[0].line); | 126 assertEquals(g_line + 2, response.body.actual_locations[0].line); |
| 127 | 127 |
| 128 // Indicate that all was processed. | 128 // Indicate that all was processed. |
| 129 listenerComplete = true; | 129 listenerComplete = true; |
| 130 } | 130 } |
| 131 } catch (e) { | 131 } catch (e) { |
| 132 exception = e | 132 exception = e; |
| 133 }; | 133 } |
| 134 }; | 134 } |
| 135 | 135 |
| 136 // Add the debug event listener. | 136 // Add the debug event listener. |
| 137 Debug.setListener(listener); | 137 Debug.setListener(listener); |
| 138 | 138 |
| 139 function f() { | 139 function f() { |
| 140 a=1 | 140 a=1; |
| 141 }; | 141 } |
| 142 | 142 |
| 143 function g() { | 143 function g() { |
| 144 // Comment. | 144 // Comment. |
| 145 f(); | 145 f(); |
| 146 }; | 146 } |
| 147 | 147 |
| 148 eval('function h(){}'); | 148 eval('function h(){}'); |
| 149 eval('function sourceUrlFunc() { a = 2; }\n//@ sourceURL=sourceUrlScript'); | 149 eval('function sourceUrlFunc() { a = 2; }\n//@ sourceURL=sourceUrlScript'); |
| 150 | 150 |
| 151 o = {a:function(){},b:function(){}} | 151 o = {a:function(){},b:function(){}}; |
| 152 | 152 |
| 153 // Check the script ids for the test functions. | 153 // Check the script ids for the test functions. |
| 154 f_script_id = Debug.findScript(f).id; | 154 f_script_id = Debug.findScript(f).id; |
| 155 g_script_id = Debug.findScript(g).id; | 155 g_script_id = Debug.findScript(g).id; |
| 156 h_script_id = Debug.findScript(h).id; | 156 h_script_id = Debug.findScript(h).id; |
| 157 sourceURL_script_id = Debug.findScript(sourceUrlFunc).id; | 157 sourceURL_script_id = Debug.findScript(sourceUrlFunc).id; |
| 158 | 158 |
| 159 assertTrue(f_script_id > 0, "invalid script id for f"); | 159 assertTrue(f_script_id > 0, "invalid script id for f"); |
| 160 assertTrue(g_script_id > 0, "invalid script id for g"); | 160 assertTrue(g_script_id > 0, "invalid script id for g"); |
| 161 assertTrue(h_script_id > 0, "invalid script id for h"); | 161 assertTrue(h_script_id > 0, "invalid script id for h"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 176 g(); | 176 g(); |
| 177 | 177 |
| 178 // Make sure that the debug event listener was invoked. | 178 // Make sure that the debug event listener was invoked. |
| 179 assertTrue(listenerComplete, "listener did not run to completion: " + exception)
; | 179 assertTrue(listenerComplete, "listener did not run to completion: " + exception)
; |
| 180 | 180 |
| 181 // Try setting breakpoint by url specified in sourceURL | 181 // Try setting breakpoint by url specified in sourceURL |
| 182 | 182 |
| 183 var breakListenerCalled = false; | 183 var breakListenerCalled = false; |
| 184 | 184 |
| 185 function breakListener(event) { | 185 function breakListener(event) { |
| 186 if (event == Debug.DebugEvent.Break) | 186 if (event == Debug.DebugEvent.Break) { |
| 187 breakListenerCalled = true; | 187 breakListenerCalled = true; |
| 188 } |
| 188 } | 189 } |
| 189 | 190 |
| 190 Debug.setListener(breakListener); | 191 Debug.setListener(breakListener); |
| 191 | 192 |
| 192 sourceUrlFunc(); | 193 sourceUrlFunc(); |
| 193 | 194 |
| 194 assertTrue(breakListenerCalled, "Break listener not called on breakpoint set by
sourceURL"); | 195 assertTrue(breakListenerCalled, "Break listener not called on breakpoint set by
sourceURL"); |
| 195 | 196 |
| 196 | 197 |
| 197 // Breakpoint in a script with no statements test case. If breakpoint is set | 198 // Breakpoint in a script with no statements test case. If breakpoint is set |
| (...skipping 10 matching lines...) Expand all Loading... |
| 208 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, | 209 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, |
| 209 i_script.id, 4); | 210 i_script.id, 4); |
| 210 } | 211 } |
| 211 | 212 |
| 212 // Creates the eval script and tries to set the breakpoint. | 213 // Creates the eval script and tries to set the breakpoint. |
| 213 // The tricky part is that the script function must be strongly reachable at the | 214 // The tricky part is that the script function must be strongly reachable at the |
| 214 // moment. Since there's no way of simply getting the pointer to the function, | 215 // moment. Since there's no way of simply getting the pointer to the function, |
| 215 // we run this code while the script function is being activated on stack. | 216 // we run this code while the script function is being activated on stack. |
| 216 eval('SetBreakpointInI1Script()\nfunction i1(){}\n\n\n\nfunction i2(){}\n'); | 217 eval('SetBreakpointInI1Script()\nfunction i1(){}\n\n\n\nfunction i2(){}\n'); |
| 217 | 218 |
| OLD | NEW |