OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 |
| 28 |
| 29 var Debug = debug.Debug; |
| 30 |
| 31 const ScopeType = debug.ScopeType; |
| 32 |
| 33 let exception = null; |
| 34 let listenerDelegate = null; |
| 35 |
| 36 const expected_break_count = 5; |
| 37 let break_count = 0; |
| 38 |
| 39 Debug.setListener(function(event, exec_state, event_data, data) { |
| 40 if (event != Debug.DebugEvent.Break) return; |
| 41 try { |
| 42 break_count++; |
| 43 listenerDelegate(exec_state); |
| 44 } catch (e) { |
| 45 exception = e; |
| 46 print(e, e.stack); |
| 47 } |
| 48 }); |
| 49 |
| 50 function CheckScope(scope_frame, scope_expectations, expected_scope_type) { |
| 51 assertEquals(expected_scope_type, scope_frame.scopeType()); |
| 52 |
| 53 var scope_object = scope_frame.scopeObject().value(); |
| 54 |
| 55 for (var name in scope_expectations) { |
| 56 var actual = scope_object[name]; |
| 57 var expected = scope_expectations[name]; |
| 58 assertEquals(expected, actual); |
| 59 } |
| 60 } |
| 61 |
| 62 // --- |
| 63 |
| 64 listenerDelegate = function(exec_state) { |
| 65 const frame = exec_state.frame(0); |
| 66 |
| 67 assertEquals(7, frame.scopeCount()); |
| 68 |
| 69 CheckScope(frame.scope(0), {}, ScopeType.Local); |
| 70 CheckScope(frame.scope(1), { a: 4, b: 5 }, ScopeType.Closure); |
| 71 CheckScope(frame.scope(2), { w: 5, v: "Capybara" }, ScopeType.With); |
| 72 CheckScope(frame.scope(3), { z: 22 }, ScopeType.Closure); |
| 73 CheckScope(frame.scope(4), { x: 5 }, ScopeType.Closure); |
| 74 CheckScope(frame.scope(5), {}, ScopeType.Script); |
| 75 CheckScope(frame.scope(6), {}, ScopeType.Global); |
| 76 }; |
| 77 |
| 78 (function F1(x) { |
| 79 function F2(y) { |
| 80 var z = x + y; |
| 81 with ({w: 5, v: "Capybara"}) { |
| 82 var F3 = function(a, b) { |
| 83 function F4(p) { |
| 84 debugger; |
| 85 return p + a + b + z + w + v.length; |
| 86 } |
| 87 return F4; |
| 88 } |
| 89 return F3(4, 5); |
| 90 } |
| 91 } |
| 92 return F2(17); |
| 93 })(5)(); |
| 94 |
| 95 // --- |
| 96 |
| 97 listenerDelegate = function(exec_state) { |
| 98 const frame = exec_state.frame(0); |
| 99 |
| 100 assertEquals(3, frame.scopeCount()); |
| 101 |
| 102 CheckScope(frame.scope(0), {}, ScopeType.Local); |
| 103 CheckScope(frame.scope(1), {}, ScopeType.Script); |
| 104 CheckScope(frame.scope(2), {}, ScopeType.Global); |
| 105 }; |
| 106 |
| 107 (function() { debugger; return 5; })(); |
| 108 |
| 109 // --- |
| 110 |
| 111 listenerDelegate = function(exec_state) { |
| 112 const frame = exec_state.frame(0); |
| 113 |
| 114 assertEquals(5, frame.scopeCount()); |
| 115 |
| 116 CheckScope(frame.scope(0), {}, ScopeType.Local); |
| 117 CheckScope(frame.scope(1), { visible2: 20 }, ScopeType.Closure); |
| 118 CheckScope(frame.scope(2), { visible1: 10 }, ScopeType.Closure); |
| 119 CheckScope(frame.scope(3), {}, ScopeType.Script); |
| 120 CheckScope(frame.scope(4), {}, ScopeType.Global); |
| 121 }; |
| 122 |
| 123 (function F1(invisible_parameter) { |
| 124 var invisible1 = 1; |
| 125 var visible1 = 10; |
| 126 return (function F2() { |
| 127 var invisible2 = 2; |
| 128 return (function F3() { |
| 129 var visible2 = 20; |
| 130 return (function () { debugger; return visible1 + visible2; }); |
| 131 })(); |
| 132 })(); |
| 133 })(5)(); |
| 134 |
| 135 // --- |
| 136 |
| 137 listenerDelegate = function(exec_state) { |
| 138 const frame = exec_state.frame(0); |
| 139 |
| 140 assertEquals(5, frame.scopeCount()); |
| 141 |
| 142 CheckScope(frame.scope(0), {}, ScopeType.Local); |
| 143 CheckScope(frame.scope(1), { e2: "I'm error 2" }, ScopeType.Catch); |
| 144 CheckScope(frame.scope(2), { e1: "I'm error 1" }, ScopeType.Catch); |
| 145 CheckScope(frame.scope(3), {}, ScopeType.Script); |
| 146 CheckScope(frame.scope(4), {}, ScopeType.Global); |
| 147 }; |
| 148 |
| 149 (function One() { |
| 150 try { |
| 151 throw "I'm error 1"; |
| 152 } catch (e1) { |
| 153 try { |
| 154 throw "I'm error 2"; |
| 155 } catch (e2) { |
| 156 return function GetError() { |
| 157 debugger; |
| 158 return e1 + e2; |
| 159 }; |
| 160 } |
| 161 } |
| 162 })()(); |
| 163 |
| 164 // --- |
| 165 |
| 166 listenerDelegate = function(exec_state) { |
| 167 const frame = exec_state.frame(0); |
| 168 |
| 169 assertEquals(5, frame.scopeCount()); |
| 170 |
| 171 CheckScope(frame.scope(0), {}, ScopeType.Local); |
| 172 CheckScope(frame.scope(1), { p4: 20, p6: 22 }, ScopeType.Closure); |
| 173 CheckScope(frame.scope(2), { p1: 1 }, ScopeType.Closure); |
| 174 CheckScope(frame.scope(3), {}, ScopeType.Script); |
| 175 CheckScope(frame.scope(4), {}, ScopeType.Global); |
| 176 }; |
| 177 |
| 178 (function Raz(p1, p2) { |
| 179 var p3 = p1 + p2; |
| 180 return (function() { |
| 181 var p4 = 20; |
| 182 var p5 = 21; |
| 183 var p6 = 22; |
| 184 return eval("(function(p7){ debugger; return p1 + p4 + p6 + p7})"); |
| 185 })(); |
| 186 })(1,2)(); |
| 187 |
| 188 // --- |
| 189 |
| 190 assertNull(exception); |
| 191 assertEquals(expected_break_count, break_count); |
OLD | NEW |