1// Copyright 2011 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// Flags: --expose-debug-as debug --expose-natives-as=builtins 29 30// Check that the ScopeIterator can properly recreate the scope at 31// every point when stepping through functions. 32 33var Debug = debug.Debug; 34 35function listener(event, exec_state, event_data, data) { 36 if (event == Debug.DebugEvent.Break) { 37 // Access scope details. 38 var scope_count = exec_state.frame().scopeCount(); 39 for (var i = 0; i < scope_count; i++) { 40 var scope = exec_state.frame().scope(i); 41 // assertTrue(scope.isScope()); 42 scope.scopeType(); 43 scope.scopeObject(); 44 } 45 46 // Do steps until we reach the global scope again. 47 if (true) { 48 exec_state.prepareStep(Debug.StepAction.StepInMin, 1); 49 } 50 } 51} 52 53Debug.setListener(listener); 54 55 56function nop() {} 57 58 59function stress() { 60 debugger; 61 62 L: with ({x:12}) { 63 break L; 64 } 65 66 67 with ({x: 'outer'}) { 68 label: { 69 with ({x: 'inner'}) { 70 break label; 71 } 72 } 73 } 74 75 76 with ({x: 'outer'}) { 77 label: { 78 with ({x: 'inner'}) { 79 break label; 80 } 81 } 82 nop(); 83 } 84 85 86 with ({x: 'outer'}) { 87 label: { 88 with ({x: 'middle'}) { 89 with ({x: 'inner'}) { 90 break label; 91 } 92 } 93 } 94 } 95 96 97 with ({x: 'outer'}) { 98 label: { 99 with ({x: 'middle'}) { 100 with ({x: 'inner'}) { 101 break label; 102 } 103 } 104 } 105 nop(); 106 } 107 108 109 with ({x: 'outer'}) { 110 for (var i = 0; i < 3; ++i) { 111 with ({x: 'inner' + i}) { 112 continue; 113 } 114 } 115 } 116 117 118 with ({x: 'outer'}) { 119 label: for (var i = 0; i < 3; ++i) { 120 with ({x: 'middle' + i}) { 121 for (var j = 0; j < 3; ++j) { 122 with ({x: 'inner' + j}) { 123 continue label; 124 } 125 } 126 } 127 } 128 } 129 130 131 with ({x: 'outer'}) { 132 try { 133 with ({x: 'inner'}) { 134 throw 0; 135 } 136 } catch (e) { 137 } 138 } 139 140 141 with ({x: 'outer'}) { 142 try { 143 with ({x: 'inner'}) { 144 throw 0; 145 } 146 } catch (e) { 147 nop(); 148 } 149 } 150 151 152 with ({x: 'outer'}) { 153 try { 154 with ({x: 'middle'}) { 155 with ({x: 'inner'}) { 156 throw 0; 157 } 158 } 159 } catch (e) { 160 } 161 } 162 163 164 try { 165 with ({x: 'outer'}) { 166 try { 167 with ({x: 'inner'}) { 168 throw 0; 169 } 170 } finally { 171 } 172 } 173 } catch (e) { 174 } 175 176 177 try { 178 with ({x: 'outer'}) { 179 try { 180 with ({x: 'inner'}) { 181 throw 0; 182 } 183 } finally { 184 nop(); 185 } 186 } 187 } catch (e) { 188 } 189 190 191 function stress1() { 192 with ({x:12}) { 193 return x; 194 } 195 } 196 stress1(); 197 198 199 function stress2() { 200 with ({x: 'outer'}) { 201 with ({x: 'inner'}) { 202 return x; 203 } 204 } 205 } 206 stress2(); 207 208 function stress3() { 209 try { 210 with ({x: 'inner'}) { 211 throw 0; 212 } 213 } catch (e) { 214 return e; 215 } 216 } 217 stress3(); 218 219 220 function stress4() { 221 try { 222 with ({x: 'inner'}) { 223 throw 0; 224 } 225 } catch (e) { 226 with ({x: 'inner'}) { 227 return e; 228 } 229 } 230 } 231 stress4(); 232 233} 234stress(); 235