| 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 | 32 |
| 33 function ParsedResponse(json) { | 33 function ParsedResponse(json) { |
| 34 this.response_ = eval('(' + json + ')'); | 34 this.response_ = eval('(' + json + ')'); |
| 35 this.refs_ = []; | 35 this.refs_ = []; |
| 36 if (this.response_.refs) { | 36 if (this.response_.refs) { |
| 37 for (var i = 0; i < this.response_.refs.length; i++) { | 37 for (var i = 0; i < this.response_.refs.length; i++) { |
| 38 this.refs_[this.response_.refs[i].handle] = this.response_.refs[i]; | 38 this.refs_[this.response_.refs[i].handle] = this.response_.refs[i]; |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 | 43 |
| 44 ParsedResponse.prototype.response = function() { | 44 ParsedResponse.prototype.response = function() { |
| 45 return this.response_; | 45 return this.response_; |
| 46 } | 46 }; |
| 47 | 47 |
| 48 | 48 |
| 49 ParsedResponse.prototype.body = function() { | 49 ParsedResponse.prototype.body = function() { |
| 50 return this.response_.body; | 50 return this.response_.body; |
| 51 } | 51 }; |
| 52 | 52 |
| 53 | 53 |
| 54 ParsedResponse.prototype.running = function() { | 54 ParsedResponse.prototype.running = function() { |
| 55 return this.response_.running; | 55 return this.response_.running; |
| 56 } | 56 }; |
| 57 | 57 |
| 58 | 58 |
| 59 ParsedResponse.prototype.lookup = function(handle) { | 59 ParsedResponse.prototype.lookup = function(handle) { |
| 60 return this.refs_[handle]; | 60 return this.refs_[handle]; |
| 61 } | 61 }; |
| 62 | 62 |
| 63 | 63 |
| 64 listener_complete = false; | 64 listener_complete = false; |
| 65 exception = false; | 65 exception = false; |
| 66 break_count = 0; | 66 break_count = 0; |
| 67 expected_return_value = 0; | 67 expected_return_value = 0; |
| 68 debugger_source_position = 0; | 68 debugger_source_position = 0; |
| 69 | 69 |
| 70 // Listener which expects to do four steps to reach returning from the function. | 70 // Listener which expects to do four steps to reach returning from the function. |
| 71 function listener(event, exec_state, event_data, data) { | 71 function listener(event, exec_state, event_data, data) { |
| 72 try { | 72 try { |
| 73 if (event == Debug.DebugEvent.Break) | 73 if (event == Debug.DebugEvent.Break) { |
| 74 { | |
| 75 break_count++; | 74 break_count++; |
| 76 if (break_count < 4) { | 75 if (break_count < 4) { |
| 77 assertFalse(exec_state.frame(0).isAtReturn()) | 76 assertFalse(exec_state.frame(0).isAtReturn()); |
| 78 switch (break_count) { | 77 switch (break_count) { |
| 79 case 1: | 78 case 1: |
| 80 // Collect the position of the debugger statement. | 79 // Collect the position of the debugger statement. |
| 81 debugger_source_position = exec_state.frame(0).sourcePosition(); | 80 debugger_source_position = exec_state.frame(0).sourcePosition(); |
| 82 break; | 81 break; |
| 83 case 2: | 82 case 2: |
| 84 // Position now at the if statement. | 83 // Position now at the if statement. |
| 85 assertEquals(debugger_source_position + 10, | 84 assertEquals(debugger_source_position + 10, |
| 86 exec_state.frame(0).sourcePosition()); | 85 exec_state.frame(0).sourcePosition()); |
| 87 break; | 86 break; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 98 default: | 97 default: |
| 99 fail("Unexpected"); | 98 fail("Unexpected"); |
| 100 } | 99 } |
| 101 exec_state.prepareStep(Debug.StepAction.StepIn, 1); | 100 exec_state.prepareStep(Debug.StepAction.StepIn, 1); |
| 102 } else { | 101 } else { |
| 103 // Position at the end of the function. | 102 // Position at the end of the function. |
| 104 assertEquals(debugger_source_position + 50, | 103 assertEquals(debugger_source_position + 50, |
| 105 exec_state.frame(0).sourcePosition()); | 104 exec_state.frame(0).sourcePosition()); |
| 106 | 105 |
| 107 // Just about to return from the function. | 106 // Just about to return from the function. |
| 108 assertTrue(exec_state.frame(0).isAtReturn()) | 107 assertTrue(exec_state.frame(0).isAtReturn()); |
| 109 assertEquals(expected_return_value, | 108 assertEquals(expected_return_value, |
| 110 exec_state.frame(0).returnValue().value()); | 109 exec_state.frame(0).returnValue().value()); |
| 111 | 110 |
| 112 // Check the same using the JSON commands. | 111 // Check the same using the JSON commands. |
| 113 var dcp = exec_state.debugCommandProcessor(false); | 112 var dcp = exec_state.debugCommandProcessor(false); |
| 114 var request = '{"seq":0,"type":"request","command":"backtrace"}'; | 113 var request = '{"seq":0,"type":"request","command":"backtrace"}'; |
| 115 var resp = dcp.processDebugJSONRequest(request); | 114 var resp = dcp.processDebugJSONRequest(request); |
| 116 response = new ParsedResponse(resp); | 115 response = new ParsedResponse(resp); |
| 117 frames = response.body().frames; | 116 frames = response.body().frames; |
| 118 assertTrue(frames[0].atReturn); | 117 assertTrue(frames[0].atReturn); |
| 119 assertEquals(expected_return_value, | 118 assertEquals(expected_return_value, |
| 120 response.lookup(frames[0].returnValue.ref).value); | 119 response.lookup(frames[0].returnValue.ref).value); |
| 121 | 120 |
| 122 listener_complete = true; | 121 listener_complete = true; |
| 123 } | 122 } |
| 124 } | 123 } |
| 125 } catch (e) { | 124 } catch (e) { |
| 126 exception = e | 125 exception = e; |
| 127 }; | 126 } |
| 128 }; | 127 } |
| 129 | 128 |
| 130 // Add the debug event listener. | 129 // Add the debug event listener. |
| 131 Debug.setListener(listener); | 130 Debug.setListener(listener); |
| 132 | 131 |
| 133 // Four steps from the debugger statement in this function will position us at | 132 // Four steps from the debugger statement in this function will position us at |
| 134 // the function return. | 133 // the function return. |
| 135 // 0 1 2 3 4 5 | 134 // 0 1 2 3 4 5 |
| 136 // 0123456789012345678901234567890123456789012345678901 | 135 // 0123456789012345678901234567890123456789012345678901 |
| 137 | 136 |
| 138 function f(x) {debugger; if (x) { return 1; } else { return 2; } }; | 137 function f(x) {debugger; if (x) { return 1; } else { return 2; } } |
| 139 | 138 |
| 140 // Call f expecting different return values. | 139 // Call f expecting different return values. |
| 141 break_count = 0; | 140 break_count = 0; |
| 142 expected_return_value = 2; | 141 expected_return_value = 2; |
| 143 listener_complete = false; | 142 listener_complete = false; |
| 144 f(); | 143 f(); |
| 145 assertFalse(exception, "exception in listener") | 144 assertFalse(exception, "exception in listener"); |
| 146 assertTrue(listener_complete); | 145 assertTrue(listener_complete); |
| 147 assertEquals(4, break_count); | 146 assertEquals(4, break_count); |
| 148 | 147 |
| 149 break_count = 0; | 148 break_count = 0; |
| 150 expected_return_value = 1; | 149 expected_return_value = 1; |
| 151 listener_complete = false; | 150 listener_complete = false; |
| 152 f(true); | 151 f(true); |
| 153 assertFalse(exception, "exception in listener") | 152 assertFalse(exception, "exception in listener"); |
| 154 assertTrue(listener_complete); | 153 assertTrue(listener_complete); |
| 155 assertEquals(4, break_count); | 154 assertEquals(4, break_count); |
| 156 | 155 |
| 157 break_count = 0; | 156 break_count = 0; |
| 158 expected_return_value = 2; | 157 expected_return_value = 2; |
| 159 listener_complete = false; | 158 listener_complete = false; |
| 160 f(false); | 159 f(false); |
| 161 assertFalse(exception, "exception in listener") | 160 assertFalse(exception, "exception in listener"); |
| 162 assertTrue(listener_complete); | 161 assertTrue(listener_complete); |
| 163 assertEquals(4, break_count); | 162 assertEquals(4, break_count); |
| OLD | NEW |