| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 // Note: the following tests only checks the debugger handling of the | 32 // Note: the following tests only checks the debugger handling of the |
| 33 // setexceptionbreak command. It does not test whether the debugger | 33 // setexceptionbreak command. It does not test whether the debugger |
| 34 // actually breaks on exceptions or not. That functionality is tested | 34 // actually breaks on exceptions or not. That functionality is tested |
| 35 // in test-debug.cc instead. | 35 // in test-debug.cc instead. |
| 36 | 36 |
| 37 // Simple function which stores the last debug event. | 37 // Simple function which stores the last debug event. |
| 38 listenerComplete = false; | 38 listenerComplete = false; |
| 39 exception = false; | 39 exception = false; |
| 40 | 40 |
| 41 var breakpoint = -1; | 41 var breakpoint = -1; |
| 42 var base_request = '"seq":0,"type":"request","command":"setexceptionbreak"' | 42 var base_request = '"seq":0,"type":"request","command":"setexceptionbreak"'; |
| 43 | 43 |
| 44 function safeEval(code) { | 44 function safeEval(code) { |
| 45 try { | 45 try { |
| 46 return eval('(' + code + ')'); | 46 return eval('(' + code + ')'); |
| 47 } catch (e) { | 47 } catch (e) { |
| 48 assertEquals(void 0, e); | 48 assertEquals(void 0, e); |
| 49 return undefined; | 49 return undefined; |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 function testArguments(dcp, arguments, success, type, enabled) { | 53 function testArguments(dcp, arguments, success, type, enabled) { |
| 54 var request = '{' + base_request + ',"arguments":' + arguments + '}' | 54 var request = '{' + base_request + ',"arguments":' + arguments + '}'; |
| 55 var json_response = dcp.processDebugJSONRequest(request); | 55 var json_response = dcp.processDebugJSONRequest(request); |
| 56 var response = safeEval(json_response); | 56 var response = safeEval(json_response); |
| 57 if (success) { | 57 if (success) { |
| 58 assertTrue(response.success, json_response); | 58 assertTrue(response.success, json_response); |
| 59 assertEquals(response.body.type, type); | 59 assertEquals(response.body.type, type); |
| 60 assertEquals(response.body.enabled, enabled); | 60 assertEquals(response.body.enabled, enabled); |
| 61 } else { | 61 } else { |
| 62 assertFalse(response.success, json_response); | 62 assertFalse(response.success, json_response); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 function listener(event, exec_state, event_data, data) { | 66 function listener(event, exec_state, event_data, data) { |
| 67 try { | 67 try { |
| 68 if (event == Debug.DebugEvent.Break) { | 68 if (event == Debug.DebugEvent.Break) { |
| 69 // Get the debug command processor. | 69 // Get the debug command processor. |
| 70 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | 70 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
| 71 | 71 |
| 72 // Test some illegal setexceptionbreak requests. | 72 // Test some illegal setexceptionbreak requests. |
| 73 var request = '{' + base_request + '}' | 73 var request = '{' + base_request + '}'; |
| 74 var response = safeEval(dcp.processDebugJSONRequest(request)); | 74 var response = safeEval(dcp.processDebugJSONRequest(request)); |
| 75 assertFalse(response.success); | 75 assertFalse(response.success); |
| 76 | 76 |
| 77 testArguments(dcp, '{}', false); | 77 testArguments(dcp, '{}', false); |
| 78 testArguments(dcp, '{"type":0}', false); | 78 testArguments(dcp, '{"type":0}', false); |
| 79 | 79 |
| 80 // Test some legal setexceptionbreak requests with default. | 80 // Test some legal setexceptionbreak requests with default. |
| 81 // Note: by default, break on exceptions should be disabled. Hence, | 81 // Note: by default, break on exceptions should be disabled. Hence, |
| 82 // the first time, we send the command with no enabled arg, the debugger | 82 // the first time, we send the command with no enabled arg, the debugger |
| 83 // should toggle it on. The second time, it should toggle it off. | 83 // should toggle it on. The second time, it should toggle it off. |
| 84 testArguments(dcp, '{"type":"all"}', true, "all", true); | 84 testArguments(dcp, '{"type":"all"}', true, "all", true); |
| 85 testArguments(dcp, '{"type":"all"}', true, "all", false); | 85 testArguments(dcp, '{"type":"all"}', true, "all", false); |
| 86 testArguments(dcp, '{"type":"uncaught"}', true, "uncaught", true); | 86 testArguments(dcp, '{"type":"uncaught"}', true, "uncaught", true); |
| 87 testArguments(dcp, '{"type":"uncaught"}', true, "uncaught", false); | 87 testArguments(dcp, '{"type":"uncaught"}', true, "uncaught", false); |
| 88 | 88 |
| 89 // Test some legal setexceptionbreak requests with explicit enabled arg. | 89 // Test some legal setexceptionbreak requests with explicit enabled arg. |
| 90 testArguments(dcp, '{"type":"all","enabled":true}', true, "all", true); | 90 testArguments(dcp, '{"type":"all","enabled":true}', true, "all", true); |
| 91 testArguments(dcp, '{"type":"all","enabled":false}', true, "all", false); | 91 testArguments(dcp, '{"type":"all","enabled":false}', true, "all", false); |
| 92 | 92 |
| 93 testArguments(dcp, '{"type":"uncaught","enabled":true}', true, | 93 testArguments(dcp, '{"type":"uncaught","enabled":true}', true, |
| 94 "uncaught", true); | 94 "uncaught", true); |
| 95 testArguments(dcp, '{"type":"uncaught","enabled":false}', true, | 95 testArguments(dcp, '{"type":"uncaught","enabled":false}', true, |
| 96 "uncaught", false); | 96 "uncaught", false); |
| 97 | 97 |
| 98 // Indicate that all was processed. | 98 // Indicate that all was processed. |
| 99 listenerComplete = true; | 99 listenerComplete = true; |
| 100 | 100 |
| 101 } | 101 } |
| 102 } catch (e) { | 102 } catch (e) { |
| 103 exception = e | 103 exception = e; |
| 104 }; | 104 } |
| 105 }; | 105 } |
| 106 | 106 |
| 107 // Add the debug event listener. | 107 // Add the debug event listener. |
| 108 Debug.setListener(listener); | 108 Debug.setListener(listener); |
| 109 | 109 |
| 110 function g() {}; | 110 function g() {} |
| 111 | 111 |
| 112 | 112 |
| 113 // Set a break point and call to invoke the debug event listener. | 113 // Set a break point and call to invoke the debug event listener. |
| 114 breakpoint = Debug.setBreakPoint(g, 0, 0); | 114 breakpoint = Debug.setBreakPoint(g, 0, 0); |
| 115 g(); | 115 g(); |
| 116 | 116 |
| 117 // Make sure that the debug event listener vas invoked. | 117 // Make sure that the debug event listener vas invoked. |
| 118 assertFalse(exception, "exception in listener") | 118 assertFalse(exception, "exception in listener"); |
| 119 assertTrue(listenerComplete, "listener did not run to completion"); | 119 assertTrue(listenerComplete, "listener did not run to completion"); |
| OLD | NEW |