blob: 790caca7c3a9c9c8a7d8fd093e59d6fd37ceba21 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028// Flags: --expose-debug-as debug
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029
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.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000047 exec_state.prepareStep(Debug.StepAction.StepIn);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000048 }
49}
50
51Debug.setListener(listener);
52
53
54function nop() {}
55
56
57function stress() {
58 debugger;
59
60 L: with ({x:12}) {
61 break L;
62 }
63
64
65 with ({x: 'outer'}) {
66 label: {
67 with ({x: 'inner'}) {
68 break label;
69 }
70 }
71 }
72
73
74 with ({x: 'outer'}) {
75 label: {
76 with ({x: 'inner'}) {
77 break label;
78 }
79 }
80 nop();
81 }
82
83
84 with ({x: 'outer'}) {
85 label: {
86 with ({x: 'middle'}) {
87 with ({x: 'inner'}) {
88 break label;
89 }
90 }
91 }
92 }
93
94
95 with ({x: 'outer'}) {
96 label: {
97 with ({x: 'middle'}) {
98 with ({x: 'inner'}) {
99 break label;
100 }
101 }
102 }
103 nop();
104 }
105
106
107 with ({x: 'outer'}) {
108 for (var i = 0; i < 3; ++i) {
109 with ({x: 'inner' + i}) {
110 continue;
111 }
112 }
113 }
114
115
116 with ({x: 'outer'}) {
117 label: for (var i = 0; i < 3; ++i) {
118 with ({x: 'middle' + i}) {
119 for (var j = 0; j < 3; ++j) {
120 with ({x: 'inner' + j}) {
121 continue label;
122 }
123 }
124 }
125 }
126 }
127
128
129 with ({x: 'outer'}) {
130 try {
131 with ({x: 'inner'}) {
132 throw 0;
133 }
134 } catch (e) {
135 }
136 }
137
138
139 with ({x: 'outer'}) {
140 try {
141 with ({x: 'inner'}) {
142 throw 0;
143 }
144 } catch (e) {
145 nop();
146 }
147 }
148
149
150 with ({x: 'outer'}) {
151 try {
152 with ({x: 'middle'}) {
153 with ({x: 'inner'}) {
154 throw 0;
155 }
156 }
157 } catch (e) {
158 }
159 }
160
161
162 try {
163 with ({x: 'outer'}) {
164 try {
165 with ({x: 'inner'}) {
166 throw 0;
167 }
168 } finally {
169 }
170 }
171 } catch (e) {
172 }
173
174
175 try {
176 with ({x: 'outer'}) {
177 try {
178 with ({x: 'inner'}) {
179 throw 0;
180 }
181 } finally {
182 nop();
183 }
184 }
185 } catch (e) {
186 }
187
188
189 function stress1() {
190 with ({x:12}) {
191 return x;
192 }
193 }
194 stress1();
195
196
197 function stress2() {
198 with ({x: 'outer'}) {
199 with ({x: 'inner'}) {
200 return x;
201 }
202 }
203 }
204 stress2();
205
206 function stress3() {
207 try {
208 with ({x: 'inner'}) {
209 throw 0;
210 }
211 } catch (e) {
212 return e;
213 }
214 }
215 stress3();
216
217
218 function stress4() {
219 try {
220 with ({x: 'inner'}) {
221 throw 0;
222 }
223 } catch (e) {
224 with ({x: 'inner'}) {
225 return e;
226 }
227 }
228 }
229 stress4();
230
231}
232stress();