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