OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-debug-as debug | 28 // Flags: --expose-debug-as debug |
29 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
30 Debug = debug.Debug | 30 Debug = debug.Debug |
31 | 31 |
32 listenerComplete = false; | 32 listenerComplete = false; |
33 exception = false; | 33 exception = false; |
34 | 34 |
35 | 35 |
36 function h() { | 36 function checkFrame0(name, value) { |
37 var a = 1; | 37 assertTrue(name == 'a' || name == 'b'); |
38 var b = 2; | 38 if (name == 'a') { |
39 debugger; // Breakpoint. | 39 assertEquals(1, value); |
40 } | 40 } |
41 | 41 if (name == 'b') { |
42 function checkFrame0(frame) { | 42 assertEquals(2, value); |
43 // Frame 0 (h) has normal variables a and b. | |
44 var count = frame.localCount(); | |
45 assertEquals(2, count); | |
46 for (var i = 0; i < count; ++i) { | |
47 var name = frame.localName(i); | |
48 var value = frame.localValue(i).value(); | |
49 if (name == 'a') { | |
50 assertEquals(1, value); | |
51 } else { | |
52 assertEquals('b', name); | |
53 assertEquals(2, value); | |
54 } | |
55 } | 43 } |
56 } | 44 } |
57 | 45 |
58 | 46 |
59 function g() { | 47 function checkFrame1(name, value) { |
60 var a = 3; | 48 assertTrue(name == '.arguments' || name == 'a'); |
61 eval("var b = 4;"); | 49 if (name == 'a') { |
62 h(); | 50 assertEquals(3, value); |
63 } | |
64 | |
65 function checkFrame1(frame) { | |
66 // Frame 1 (g) has normal variable a (and arguments). | |
67 var count = frame.localCount(); | |
68 assertEquals(2, count); | |
69 for (var i = 0; i < count; ++i) { | |
70 var name = frame.localName(i); | |
71 var value = frame.localValue(i).value(); | |
72 if (name == 'a') { | |
73 assertEquals(3, value); | |
74 } else { | |
75 assertEquals('arguments', name); | |
76 } | |
77 } | 51 } |
78 } | 52 } |
79 | 53 |
80 | 54 |
81 function f() { | 55 function checkFrame2(name, value) { |
82 var a = 5; | 56 assertTrue(name == '.arguments' || name == 'a' || |
83 var b = 0; | 57 name == 'arguments' || name == 'b'); |
84 with ({b:6}) { | 58 if (name == 'a') { |
85 g(); | 59 assertEquals(5, value); |
| 60 } |
| 61 if (name == 'b') { |
| 62 assertEquals(0, value); |
86 } | 63 } |
87 } | 64 } |
88 | 65 |
89 function checkFrame2(frame) { | |
90 // Frame 2 (f) has normal variables a and b (and arguments). | |
91 var count = frame.localCount(); | |
92 assertEquals(3, count); | |
93 for (var i = 0; i < count; ++i) { | |
94 var name = frame.localName(i); | |
95 var value = frame.localValue(i).value(); | |
96 if (name == 'a') { | |
97 assertEquals(5, value); | |
98 } else if (name == 'b') { | |
99 assertEquals(0, value); | |
100 } else { | |
101 assertEquals('arguments', name); | |
102 } | |
103 } | |
104 } | |
105 | |
106 | 66 |
107 function listener(event, exec_state, event_data, data) { | 67 function listener(event, exec_state, event_data, data) { |
108 try { | 68 try { |
109 if (event == Debug.DebugEvent.Break) | 69 if (event == Debug.DebugEvent.Break) |
110 { | 70 { |
111 checkFrame0(exec_state.frame(0)); | 71 // Frame 0 has normal variables a and b. |
112 checkFrame1(exec_state.frame(1)); | 72 var frame0 = exec_state.frame(0); |
113 checkFrame2(exec_state.frame(2)); | 73 checkFrame0(frame0.localName(0), frame0.localValue(0).value()); |
| 74 checkFrame0(frame0.localName(1), frame0.localValue(1).value()); |
| 75 |
| 76 // Frame 1 has normal variable a (and the .arguments variable). |
| 77 var frame1 = exec_state.frame(1); |
| 78 checkFrame1(frame1.localName(0), frame1.localValue(0).value()); |
| 79 checkFrame1(frame1.localName(1), frame1.localValue(1).value()); |
| 80 |
| 81 // Frame 2 has normal variables a and b (and both the .arguments and |
| 82 // arguments variable). |
| 83 var frame2 = exec_state.frame(2); |
| 84 checkFrame2(frame2.localName(0), frame2.localValue(0).value()); |
| 85 checkFrame2(frame2.localName(1), frame2.localValue(1).value()); |
| 86 checkFrame2(frame2.localName(2), frame2.localValue(2).value()); |
| 87 checkFrame2(frame2.localName(3), frame2.localValue(3).value()); |
114 | 88 |
115 // Evaluating a and b on frames 0, 1 and 2 produces 1, 2, 3, 4, 5 and 6. | 89 // Evaluating a and b on frames 0, 1 and 2 produces 1, 2, 3, 4, 5 and 6. |
116 assertEquals(1, exec_state.frame(0).evaluate('a').value()); | 90 assertEquals(1, exec_state.frame(0).evaluate('a').value()); |
117 assertEquals(2, exec_state.frame(0).evaluate('b').value()); | 91 assertEquals(2, exec_state.frame(0).evaluate('b').value()); |
118 assertEquals(3, exec_state.frame(1).evaluate('a').value()); | 92 assertEquals(3, exec_state.frame(1).evaluate('a').value()); |
119 assertEquals(4, exec_state.frame(1).evaluate('b').value()); | 93 assertEquals(4, exec_state.frame(1).evaluate('b').value()); |
120 assertEquals(5, exec_state.frame(2).evaluate('a').value()); | 94 assertEquals(5, exec_state.frame(2).evaluate('a').value()); |
121 assertEquals(6, exec_state.frame(2).evaluate('b').value()); | 95 assertEquals(6, exec_state.frame(2).evaluate('b').value()); |
122 | 96 |
123 // Indicate that all was processed. | 97 // Indicate that all was processed. |
124 listenerComplete = true; | 98 listenerComplete = true; |
125 } | 99 } |
126 } catch (e) { | 100 } catch (e) { |
127 exception = e | 101 exception = e |
128 }; | 102 }; |
129 }; | 103 }; |
130 | 104 |
131 // Add the debug event listener. | 105 // Add the debug event listener. |
132 Debug.setListener(listener); | 106 Debug.setListener(listener); |
133 | 107 |
| 108 function h() { |
| 109 var a = 1; |
| 110 var b = 2; |
| 111 debugger; // Breakpoint. |
| 112 }; |
| 113 |
| 114 function g() { |
| 115 var a = 3; |
| 116 eval("var b = 4;"); |
| 117 h(); |
| 118 }; |
| 119 |
| 120 function f() { |
| 121 var a = 5; |
| 122 var b = 0; |
| 123 with ({b:6}) { |
| 124 g(); |
| 125 } |
| 126 }; |
| 127 |
134 f(); | 128 f(); |
135 | 129 |
136 // Make sure that the debug event listener vas invoked. | 130 // Make sure that the debug event listener vas invoked. |
137 assertTrue(listenerComplete); | 131 assertTrue(listenerComplete); |
138 assertFalse(exception, "exception in listener") | 132 assertFalse(exception, "exception in listener") |
OLD | NEW |