• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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    exec_state.prepareStep(Debug.StepAction.StepIn);
48  }
49}
50
51Debug.setListener(listener);
52
53
54function test1() {
55  debugger;
56  with ({x:1}) {
57    x = 2;
58  }
59}
60test1();
61
62
63function test2() {
64  if (true) {
65    with ({}) {
66      debugger;
67    }
68  } else {
69    with ({}) {
70      return 10;
71    }
72  }
73}
74test2();
75
76
77function test3() {
78  if (true) {
79    debugger;
80  } else {
81    with ({}) {
82      return 10;
83    }
84  }
85}
86test3();
87
88
89function test4() {
90  debugger;
91  with ({x:1}) x = 1
92}
93test4();
94
95
96function test5() {
97  debugger;
98  var dummy = 1;
99  with ({}) {
100    with ({}) {
101      dummy = 2;
102    }
103  }
104  dummy = 3;
105}
106test5();
107
108
109function test6() {
110  debugger;
111  try {
112    throw 'stuff';
113  } catch (e) {
114    e = 1;
115  }
116}
117test6();
118
119
120function test7() {
121  debugger;
122  function foo() {}
123}
124test7();
125
126
127function test8() {
128  debugger;
129  (function foo() {})();
130}
131test8();
132
133
134function test10() {
135  debugger;
136  with ({}) {
137    return 10;
138  }
139}
140test10();
141
142
143function test11() {
144  debugger;
145  try {
146    throw 'stuff';
147  } catch (e) {
148    return 10;
149  }
150}
151test11();
152
153
154var prefixes = [
155    "debugger; ",
156    "if (false) { try { throw 0; } catch(x) { return x; } }; debugger; " ];
157
158
159// Return from function constructed with Function constructor.
160var anon = 12;
161for (var i = 0; i < prefixes.length; ++i) {
162  var pre = prefixes[i];
163  Function(pre + "return 42")();
164  Function(pre + "return 42 ")();
165  Function(pre + "return 42;")();
166  Function(pre + "return 42; ")();
167  Function(pre + "return anon")();
168  Function(pre + "return anon ")();
169  Function(pre + "return anon;")();
170  Function(pre + "return anon; ")();
171}
172
173
174try {
175  with({}) {
176    debugger;
177    eval("{}$%:^");
178  }
179} catch(e) {
180  nop();
181}
182
183
184function nop() {}
185
186
187// With block as the last(!) statement in global code.
188with ({}) { debugger; }
189