OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 15 matching lines...) Expand all Loading... |
27 | 27 |
28 // Flags: --expose-debug-as debug --allow-natives-syntax | 28 // Flags: --expose-debug-as debug --allow-natives-syntax |
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 var listenerComplete = false; | 32 var listenerComplete = false; |
33 var exception = false; | 33 var exception = false; |
34 | 34 |
35 var testingConstructCall = false; | 35 var testingConstructCall = false; |
36 | 36 |
| 37 var expected = [ |
| 38 { locals: {a0: 1, b0: 2}, args: { names: ["i", "x0", "y0"], values: [0, 3, 4]
} }, |
| 39 { locals: {a1: 3, b1: 4}, args: { names: ["i", "x1", "y1"], values: [1, 5, 6]
} }, |
| 40 { locals: {a2: 5, b2: 6}, args: { names: ["i"], values: [2] } }, |
| 41 { locals: {a3: 7, b3: 8}, args: { names: ["i", "x3", "y3", "z3"], values: [3,
9, 10, undefined] } }, |
| 42 { locals: {a4: 9, b4: 10}, args: { names: ["i", "x4", "y4"], values: [4, 11, 1
2] } } |
| 43 ]; |
| 44 |
| 45 function arraySum(arr) { |
| 46 return arr.reduce(function (a, b) { return a + b; }, 0); |
| 47 } |
37 | 48 |
38 function listener(event, exec_state, event_data, data) { | 49 function listener(event, exec_state, event_data, data) { |
39 try { | 50 try { |
40 if (event == Debug.DebugEvent.Break) | 51 if (event == Debug.DebugEvent.Break) |
41 { | 52 { |
42 assertEquals(6, exec_state.frameCount()); | 53 assertEquals(6, exec_state.frameCount()); |
43 | 54 |
44 for (var i = 0; i < exec_state.frameCount(); i++) { | 55 for (var i = 0; i < exec_state.frameCount(); i++) { |
45 var frame = exec_state.frame(i); | 56 var frame = exec_state.frame(i); |
46 if (i < exec_state.frameCount() - 1) { | 57 if (i < exec_state.frameCount() - 1) { |
47 var expected_a = i * 2 + 1; | 58 var expected_args = expected[i].args; |
48 var expected_b = i * 2 + 2; | 59 var expected_locals = expected[i].locals; |
49 var expected_x = (i + 1) * 2 + 1; | |
50 var expected_y = (i + 1) * 2 + 2; | |
51 | 60 |
52 // All frames except the bottom one has normal variables a and b. | 61 // All frames except the bottom one have expected locals. |
53 var a = ('a' === frame.localName(0)) ? 0 : 1; | 62 var locals = {}; |
54 var b = 1 - a; | 63 for (var j = 0; j < frame.localCount(); j++) { |
55 assertEquals('a', frame.localName(a)); | 64 locals[frame.localName(j)] = frame.localValue(j).value(); |
56 assertEquals('b', frame.localName(b)); | 65 } |
57 assertEquals(expected_a, frame.localValue(a).value()); | 66 assertPropertiesEqual(expected_locals, locals); |
58 assertEquals(expected_b, frame.localValue(b).value()); | |
59 | 67 |
60 // All frames except the bottom one has arguments variables x and y. | 68 // All frames except the bottom one have expected arguments. |
61 assertEquals('x', frame.argumentName(0)); | 69 for (var j = 0; j < expected_args.names.length; j++) { |
62 assertEquals('y', frame.argumentName(1)); | 70 assertEquals(expected_args.names[j], frame.argumentName(j)); |
63 assertEquals(expected_x, frame.argumentValue(0).value()); | 71 assertEquals(expected_args.values[j], frame.argumentValue(j).value()
); |
64 assertEquals(expected_y, frame.argumentValue(1).value()); | 72 } |
65 | 73 |
66 // All frames except the bottom one have two scopes. | 74 // All frames except the bottom one have two scopes. |
67 assertEquals(2, frame.scopeCount()); | 75 assertEquals(2, frame.scopeCount()); |
68 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); | 76 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); |
69 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); | 77 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); |
70 assertEquals(expected_a, frame.scope(0).scopeObject().value()['a']); | 78 |
71 assertEquals(expected_b, frame.scope(0).scopeObject().value()['b']); | 79 Object.keys(expected_locals).forEach(function (name) { |
72 assertEquals(expected_x, frame.scope(0).scopeObject().value()['x']); | 80 assertEquals(expected_locals[name], frame.scope(0).scopeObject().val
ue()[name]); |
73 assertEquals(expected_y, frame.scope(0).scopeObject().value()['y']); | 81 }); |
| 82 |
| 83 for (var j = 0; j < expected_args.names.length; j++) { |
| 84 var arg_name = expected_args.names[j]; |
| 85 var arg_value = expected_args.values[j]; |
| 86 assertEquals(arg_value, frame.scope(0).scopeObject().value()[arg_nam
e]); |
| 87 } |
74 | 88 |
75 // Evaluate in the inlined frame. | 89 // Evaluate in the inlined frame. |
76 assertEquals(expected_a, frame.evaluate('a').value()); | 90 Object.keys(expected_locals).forEach(function (name) { |
77 assertEquals(expected_x, frame.evaluate('x').value()); | 91 assertEquals(expected_locals[name], frame.evaluate(name).value()); |
78 assertEquals(expected_x, frame.evaluate('arguments[0]').value()); | 92 }); |
79 assertEquals(expected_a + expected_b + expected_x + expected_y, | 93 |
80 frame.evaluate('a + b + x + y').value()); | 94 for (var j = 0; j < expected_args.names.length; j++) { |
81 assertEquals(expected_x + expected_y, | 95 var arg_name = expected_args.names[j]; |
82 frame.evaluate('arguments[0] + arguments[1]').value()); | 96 var arg_value = expected_args.values[j]; |
| 97 assertEquals(arg_value, frame.evaluate(arg_name).value()); |
| 98 assertEquals(arg_value, frame.evaluate('arguments['+j+']').value()); |
| 99 } |
| 100 |
| 101 var expected_args_sum = arraySum(expected_args.values); |
| 102 var expected_locals_sum = |
| 103 arraySum(Object.keys(expected_locals). |
| 104 map(function (k) { return expected_locals[k]; })); |
| 105 |
| 106 assertEquals(expected_locals_sum + expected_args_sum, |
| 107 frame.evaluate(Object.keys(expected_locals).join('+') + '
+ ' + |
| 108 expected_args.names.join('+')).value()); |
| 109 |
| 110 var arguments_sum = expected_args.names.map(function(_, idx) { |
| 111 return "arguments[" + idx + "]"; |
| 112 }).join('+'); |
| 113 assertEquals(expected_args_sum, |
| 114 frame.evaluate(arguments_sum).value()); |
83 } else { | 115 } else { |
84 // The bottom frame only have the global scope. | 116 // The bottom frame only have the global scope. |
85 assertEquals(1, frame.scopeCount()); | 117 assertEquals(1, frame.scopeCount()); |
86 assertEquals(debug.ScopeType.Global, frame.scope(0).scopeType()); | 118 assertEquals(debug.ScopeType.Global, frame.scope(0).scopeType()); |
87 } | 119 } |
88 | 120 |
89 // Check the frame function. | 121 // Check the frame function. |
90 switch (i) { | 122 switch (i) { |
91 case 0: assertEquals(h, frame.func().value()); break; | 123 case 0: assertEquals(h, frame.func().value()); break; |
92 case 1: assertEquals(g3, frame.func().value()); break; | 124 case 1: assertEquals(g3, frame.func().value()); break; |
(...skipping 21 matching lines...) Expand all Loading... |
114 assertFalse(frame.isOptimizedFrame()); | 146 assertFalse(frame.isOptimizedFrame()); |
115 assertFalse(frame.isInlinedFrame()); | 147 assertFalse(frame.isInlinedFrame()); |
116 } | 148 } |
117 } | 149 } |
118 } | 150 } |
119 | 151 |
120 // Indicate that all was processed. | 152 // Indicate that all was processed. |
121 listenerComplete = true; | 153 listenerComplete = true; |
122 } | 154 } |
123 } catch (e) { | 155 } catch (e) { |
124 exception = e.stack; | 156 exception = e.toString() + e.stack; |
125 }; | 157 }; |
126 }; | 158 }; |
127 | 159 |
128 f();f();f(); | 160 for (var i = 0; i < 4; i++) f(expected.length - 1, 11, 12); |
129 %OptimizeFunctionOnNextCall(f); | 161 %OptimizeFunctionOnNextCall(f); |
130 f(); | 162 f(expected.length - 1, 11, 12); |
131 | 163 |
132 // Add the debug event listener. | 164 // Add the debug event listener. |
133 Debug.setListener(listener); | 165 Debug.setListener(listener); |
134 | 166 |
135 function h(x, y) { | 167 function h(i, x0, y0) { |
136 var a = 1; | 168 var a0 = expected[i].locals.a0; |
137 var b = 2; | 169 var b0 = expected[i].locals.b0; |
138 debugger; // Breakpoint. | 170 debugger; // Breakpoint. |
139 }; | 171 } |
140 | 172 |
141 function g3(x, y) { | 173 function g3(i, x1, y1) { |
142 var a = 3; | 174 var a1 = expected[i].locals.a1; |
143 var b = 4; | 175 var b1 = expected[i].locals.b1; |
144 h(a, b); | 176 h(i - 1, a1, b1); |
145 }; | 177 } |
146 | 178 |
147 function g2(x, y) { | 179 function g2(i) { |
148 var a = 5; | 180 var a2 = expected[i].locals.a2; |
149 var b = 6; | 181 var b2 = expected[i].locals.b2; |
150 g3(a, b); | 182 g3(i - 1, a2, b2); |
151 }; | 183 } |
152 | 184 |
153 function g1(x, y) { | 185 function g1(i, x3, y3, z3) { |
154 var a = 7; | 186 var a3 = expected[i].locals.a3; |
155 var b = 8; | 187 var b3 = expected[i].locals.b3; |
156 g2(a, b); | 188 g2(i - 1, a3, b3); |
157 }; | 189 } |
158 | 190 |
159 function f(x, y) { | 191 function f(i, x4, y4) { |
160 var a = 9; | 192 var a4 = expected[i].locals.a4; |
161 var b = 10; | 193 var b4 = expected[i].locals.b4; |
162 g1(a, b); | 194 g1(i - 1, a4, b4); |
163 }; | 195 } |
164 | 196 |
165 // Test calling f normally and as a constructor. | 197 // Test calling f normally and as a constructor. |
166 f(11, 12); | 198 f(expected.length - 1, 11, 12); |
| 199 f(expected.length - 1, 11, 12, 0); |
167 testingConstructCall = true; | 200 testingConstructCall = true; |
168 new f(11, 12); | 201 new f(expected.length - 1, 11, 12); |
| 202 new f(expected.length - 1, 11, 12, 0); |
169 | 203 |
170 // Make sure that the debug event listener vas invoked. | 204 // Make sure that the debug event listener vas invoked. |
171 assertFalse(exception, "exception in listener " + exception) | 205 assertFalse(exception, "exception in listener " + exception) |
172 assertTrue(listenerComplete); | 206 assertTrue(listenerComplete); |
173 | 207 |
174 Debug.setListener(null); | 208 Debug.setListener(null); |
OLD | NEW |