blob: 4b87829169586ed4885bee9236138ecbd51faa87 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2008 the V8 project authors. All rights reserved.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002// 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// Get the Debug object exposed from the debug context global object.
30Debug = debug.Debug
31
32listenerComplete = false;
33exception = false;
34
ager@chromium.org7c537e22008-10-16 08:43:32 +000035
36function checkFrame0(name, value) {
ager@chromium.org0ee099b2011-01-25 14:06:47 +000037 assertTrue(name == 'a' || name == 'b');
ager@chromium.org7c537e22008-10-16 08:43:32 +000038 if (name == 'a') {
39 assertEquals(1, value);
ager@chromium.org0ee099b2011-01-25 14:06:47 +000040 }
41 if (name == 'b') {
ager@chromium.org7c537e22008-10-16 08:43:32 +000042 assertEquals(2, value);
43 }
44}
45
46
47function checkFrame1(name, value) {
ager@chromium.org0ee099b2011-01-25 14:06:47 +000048 assertTrue(name == '.arguments' || name == 'a');
ager@chromium.org7c537e22008-10-16 08:43:32 +000049 if (name == 'a') {
50 assertEquals(3, value);
51 }
52}
53
54
55function checkFrame2(name, value) {
ager@chromium.org0ee099b2011-01-25 14:06:47 +000056 assertTrue(name == '.arguments' || name == 'a' ||
57 name == 'arguments' || name == 'b');
ager@chromium.org7c537e22008-10-16 08:43:32 +000058 if (name == 'a') {
59 assertEquals(5, value);
ager@chromium.org0ee099b2011-01-25 14:06:47 +000060 }
61 if (name == 'b') {
ager@chromium.org7c537e22008-10-16 08:43:32 +000062 assertEquals(0, value);
63 }
64}
65
66
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000067function listener(event, exec_state, event_data, data) {
68 try {
69 if (event == Debug.DebugEvent.Break)
70 {
71 // Frame 0 has normal variables a and b.
ager@chromium.org7c537e22008-10-16 08:43:32 +000072 var frame0 = exec_state.frame(0);
73 checkFrame0(frame0.localName(0), frame0.localValue(0).value());
74 checkFrame0(frame0.localName(1), frame0.localValue(1).value());
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000075
ager@chromium.org0ee099b2011-01-25 14:06:47 +000076 // Frame 1 has normal variable a (and the .arguments variable).
ager@chromium.org7c537e22008-10-16 08:43:32 +000077 var frame1 = exec_state.frame(1);
78 checkFrame1(frame1.localName(0), frame1.localValue(0).value());
79 checkFrame1(frame1.localName(1), frame1.localValue(1).value());
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000080
ager@chromium.org0ee099b2011-01-25 14:06:47 +000081 // Frame 2 has normal variables a and b (and both the .arguments and
82 // arguments variable).
ager@chromium.org7c537e22008-10-16 08:43:32 +000083 var frame2 = exec_state.frame(2);
84 checkFrame2(frame2.localName(0), frame2.localValue(0).value());
85 checkFrame2(frame2.localName(1), frame2.localValue(1).value());
ager@chromium.org0ee099b2011-01-25 14:06:47 +000086 checkFrame2(frame2.localName(2), frame2.localValue(2).value());
87 checkFrame2(frame2.localName(3), frame2.localValue(3).value());
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000088
89 // Evaluating a and b on frames 0, 1 and 2 produces 1, 2, 3, 4, 5 and 6.
90 assertEquals(1, exec_state.frame(0).evaluate('a').value());
91 assertEquals(2, exec_state.frame(0).evaluate('b').value());
92 assertEquals(3, exec_state.frame(1).evaluate('a').value());
93 assertEquals(4, exec_state.frame(1).evaluate('b').value());
94 assertEquals(5, exec_state.frame(2).evaluate('a').value());
95 assertEquals(6, exec_state.frame(2).evaluate('b').value());
96
97 // Indicate that all was processed.
98 listenerComplete = true;
99 }
100 } catch (e) {
101 exception = e
102 };
103};
104
105// Add the debug event listener.
iposva@chromium.org245aa852009-02-10 00:49:54 +0000106Debug.setListener(listener);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000107
108function h() {
109 var a = 1;
110 var b = 2;
111 debugger; // Breakpoint.
112};
113
114function g() {
115 var a = 3;
116 eval("var b = 4;");
117 h();
118};
119
120function f() {
121 var a = 5;
122 var b = 0;
123 with ({b:6}) {
124 g();
125 }
126};
127
128f();
129
130// Make sure that the debug event listener vas invoked.
131assertTrue(listenerComplete);
132assertFalse(exception, "exception in listener")