| 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 listenerComplete = false; | 32 listenerComplete = false; |
| 33 exception = false; | 33 exception = false; |
| 34 | 34 |
| 35 // The base part of all evaluate requests. | 35 // The base part of all evaluate requests. |
| 36 var base_request = '"seq":0,"type":"request","command":"evaluate"' | 36 var base_request = '"seq":0,"type":"request","command":"evaluate"'; |
| 37 | 37 |
| 38 function safeEval(code) { | 38 function safeEval(code) { |
| 39 try { | 39 try { |
| 40 return eval('(' + code + ')'); | 40 return eval('(' + code + ')'); |
| 41 } catch (e) { | 41 } catch (e) { |
| 42 assertEquals(void 0, e); | 42 assertEquals(void 0, e); |
| 43 return undefined; | 43 return undefined; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 function testRequest(exec_state, arguments, success, result) { | 47 function testRequest(exec_state, arguments, success, result) { |
| 48 // Get the debug command processor in paused state. | 48 // Get the debug command processor in paused state. |
| 49 var dcp = exec_state.debugCommandProcessor(false); | 49 var dcp = exec_state.debugCommandProcessor(false); |
| 50 | 50 |
| 51 // Generate request with the supplied arguments. | 51 // Generate request with the supplied arguments. |
| 52 var request; | 52 var request; |
| 53 if (arguments) { | 53 if (arguments) { |
| 54 request = '{' + base_request + ',"arguments":' + arguments + '}'; | 54 request = '{' + base_request + ',"arguments":' + arguments + '}'; |
| 55 } else { | 55 } else { |
| 56 request = '{' + base_request + '}' | 56 request = '{' + base_request + '}'; |
| 57 } | 57 } |
| 58 var response = safeEval(dcp.processDebugJSONRequest(request)); | 58 var response = safeEval(dcp.processDebugJSONRequest(request)); |
| 59 if (success) { | 59 if (success) { |
| 60 assertTrue(response.success, request + ' -> ' + response.message); | 60 assertTrue(response.success, request + ' -> ' + response.message); |
| 61 assertEquals(result, response.body.value); | 61 assertEquals(result, response.body.value); |
| 62 } else { | 62 } else { |
| 63 assertFalse(response.success, request + ' -> ' + response.message); | 63 assertFalse(response.success, request + ' -> ' + response.message); |
| 64 } | 64 } |
| 65 assertFalse(response.running, request + ' -> expected not running'); | 65 assertFalse(response.running, request + ' -> expected not running'); |
| 66 } | 66 } |
| 67 | 67 |
| 68 | 68 |
| 69 // Event listener which evaluates with break disabled. | 69 // Event listener which evaluates with break disabled. |
| 70 function listener(event, exec_state, event_data, data) { | 70 function listener(event, exec_state, event_data, data) { |
| 71 try { | 71 try { |
| 72 if (event == Debug.DebugEvent.Break) | 72 if (event == Debug.DebugEvent.Break) { |
| 73 { | |
| 74 // Call functions with break using the FrameMirror directly. | 73 // Call functions with break using the FrameMirror directly. |
| 75 assertEquals(1, exec_state.evaluateGlobal('f()', true).value()); | 74 assertEquals(1, exec_state.evaluateGlobal('f()', true).value()); |
| 76 assertEquals(2, exec_state.evaluateGlobal('g()', true).value()); | 75 assertEquals(2, exec_state.evaluateGlobal('g()', true).value()); |
| 77 assertEquals(1, exec_state.frame(0).evaluate('f()', true).value()); | 76 assertEquals(1, exec_state.frame(0).evaluate('f()', true).value()); |
| 78 assertEquals(2, exec_state.frame(0).evaluate('g()', true).value()); | 77 assertEquals(2, exec_state.frame(0).evaluate('g()', true).value()); |
| 79 | 78 |
| 80 // Call functions with break using the JSON protocol. Tests that argument | 79 // Call functions with break using the JSON protocol. Tests that argument |
| 81 // disable_break is default true. | 80 // disable_break is default true. |
| 82 testRequest(exec_state, '{"expression":"f()"}', true, 1); | 81 testRequest(exec_state, '{"expression":"f()"}', true, 1); |
| 83 testRequest(exec_state, '{"expression":"f()","frame":0}', true, 1); | 82 testRequest(exec_state, '{"expression":"f()","frame":0}', true, 1); |
| 84 testRequest(exec_state, '{"expression":"g()"}', true, 2); | 83 testRequest(exec_state, '{"expression":"g()"}', true, 2); |
| 85 testRequest(exec_state, '{"expression":"g()","frame":0}', true, 2); | 84 testRequest(exec_state, '{"expression":"g()","frame":0}', true, 2); |
| 86 | 85 |
| 87 // Call functions with break using the JSON protocol. Tests passing | 86 // Call functions with break using the JSON protocol. Tests passing |
| 88 // argument disable_break is default true. | 87 // argument disable_break is default true. |
| 89 testRequest(exec_state, '{"expression":"f()","disable_break":true}', true,
1); | 88 testRequest(exec_state, '{"expression":"f()","disable_break":true}', true,
1); |
| 90 testRequest(exec_state, '{"expression":"f()","frame":0,"disable_break":tru
e}', | 89 testRequest(exec_state, '{"expression":"f()","frame":0,"disable_break":tru
e}', |
| 91 true, 1); | 90 true, 1); |
| 92 testRequest(exec_state, '{"expression":"g()","disable_break":true}', true,
2); | 91 testRequest(exec_state, '{"expression":"g()","disable_break":true}', true,
2); |
| 93 testRequest(exec_state, '{"expression":"g()","frame":0,"disable_break":tru
e}', | 92 testRequest(exec_state, '{"expression":"g()","frame":0,"disable_break":tru
e}', |
| 94 true, 2); | 93 true, 2); |
| 95 | 94 |
| 96 // Indicate that all was processed. | 95 // Indicate that all was processed. |
| 97 listenerComplete = true; | 96 listenerComplete = true; |
| 98 } | 97 } |
| 99 } catch (e) { | 98 } catch (e) { |
| 100 exception = e | 99 exception = e; |
| 101 }; | 100 } |
| 102 }; | 101 } |
| 103 | 102 |
| 104 | 103 |
| 105 // Event listener which evaluates with break enabled one time and the second | 104 // Event listener which evaluates with break enabled one time and the second |
| 106 // time evaluates with break disabled. | 105 // time evaluates with break disabled. |
| 107 var break_count = 0; | 106 var break_count = 0; |
| 108 function listener_recurse(event, exec_state, event_data, data) { | 107 function listener_recurse(event, exec_state, event_data, data) { |
| 109 try { | 108 try { |
| 110 if (event == Debug.DebugEvent.Break) | 109 if (event == Debug.DebugEvent.Break) { |
| 111 { | |
| 112 break_count++; | 110 break_count++; |
| 113 | 111 |
| 114 // Call functions with break using the FrameMirror directly. | 112 // Call functions with break using the FrameMirror directly. |
| 115 if (break_count == 1) { | 113 if (break_count == 1) { |
| 116 // First break event evaluates with break enabled. | 114 // First break event evaluates with break enabled. |
| 117 assertEquals(1, exec_state.frame(0).evaluate('f()', false).value()); | 115 assertEquals(1, exec_state.frame(0).evaluate('f()', false).value()); |
| 118 listenerComplete = true; | 116 listenerComplete = true; |
| 119 } else { | 117 } else { |
| 120 // Second break event evaluates with break disabled. | 118 // Second break event evaluates with break disabled. |
| 121 assertEquals(2, break_count); | 119 assertEquals(2, break_count); |
| 122 assertFalse(listenerComplete); | 120 assertFalse(listenerComplete); |
| 123 assertEquals(1, exec_state.frame(0).evaluate('f()', true).value()); | 121 assertEquals(1, exec_state.frame(0).evaluate('f()', true).value()); |
| 124 } | 122 } |
| 125 } | 123 } |
| 126 } catch (e) { | 124 } catch (e) { |
| 127 exception = e | 125 exception = e; |
| 128 }; | 126 } |
| 129 }; | 127 } |
| 130 | 128 |
| 131 // Add the debug event listener. | 129 // Add the debug event listener. |
| 132 Debug.setListener(listener); | 130 Debug.setListener(listener); |
| 133 | 131 |
| 134 // Test functions - one with break point and one with debugger statement. | 132 // Test functions - one with break point and one with debugger statement. |
| 135 function f() { | 133 function f() { |
| 136 return 1; | 134 return 1; |
| 137 }; | 135 } |
| 138 | 136 |
| 139 function g() { | 137 function g() { |
| 140 debugger; | 138 debugger; |
| 141 return 2; | 139 return 2; |
| 142 }; | 140 } |
| 143 | 141 |
| 144 Debug.setBreakPoint(f, 2, 0); | 142 Debug.setBreakPoint(f, 2, 0); |
| 145 | 143 |
| 146 // Cause a debug break event. | 144 // Cause a debug break event. |
| 147 debugger; | 145 debugger; |
| 148 | 146 |
| 149 assertFalse(exception, "exception in listener") | 147 assertFalse(exception, "exception in listener"); |
| 150 // Make sure that the debug event listener vas invoked. | 148 // Make sure that the debug event listener vas invoked. |
| 151 assertTrue(listenerComplete); | 149 assertTrue(listenerComplete); |
| 152 | 150 |
| 153 // Remove the debug event listener. | 151 // Remove the debug event listener. |
| 154 Debug.setListener(null); | 152 Debug.setListener(null); |
| 155 | 153 |
| 156 // Set debug event listener wich uses recursive breaks. | 154 // Set debug event listener wich uses recursive breaks. |
| 157 Debug.setListener(listener_recurse); | 155 Debug.setListener(listener_recurse); |
| 158 listenerComplete = false; | 156 listenerComplete = false; |
| 159 | 157 |
| 160 Debug.setBreakPoint(f, 2, 0); | 158 Debug.setBreakPoint(f, 2, 0); |
| 161 | 159 |
| 162 debugger; | 160 debugger; |
| 163 | 161 |
| 164 assertFalse(exception, "exception in listener") | 162 assertFalse(exception, "exception in listener"); |
| 165 // Make sure that the debug event listener vas invoked. | 163 // Make sure that the debug event listener vas invoked. |
| 166 assertTrue(listenerComplete); | 164 assertTrue(listenerComplete); |
| 167 assertEquals(2, break_count); | 165 assertEquals(2, break_count); |
| OLD | NEW |