OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-debug-as debug | 5 // Flags: --expose-debug-as debug |
6 // Tests stepping into through Array.prototype.forEach callbacks. | |
7 | 6 |
8 Debug = debug.Debug | 7 Debug = debug.Debug |
9 var exception = null; | 8 var exception = null; |
10 var break_count = 0; | 9 var break_count = 0; |
11 var expected_breaks = -1; | 10 |
| 11 var expected_values = |
| 12 [ReferenceError, ReferenceError, 0, 0, 0, 0, 0, 1, ReferenceError, ReferenceEr
ror]; |
12 | 13 |
13 function listener(event, exec_state, event_data, data) { | 14 function listener(event, exec_state, event_data, data) { |
14 try { | 15 try { |
15 if (event == Debug.DebugEvent.Break) { | 16 if (event == Debug.DebugEvent.Break) { |
16 assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace"); | 17 assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace"); |
| 18 // Count number of expected breakpoints in this source file. |
17 if (!break_count) { | 19 if (!break_count) { |
18 // Count number of expected breakpoints in this source file. | |
19 var source_text = exec_state.frame(0).func().script().source(); | 20 var source_text = exec_state.frame(0).func().script().source(); |
20 expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length; | 21 expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length; |
21 print("Expected breaks: " + expected_breaks); | 22 print("Expected breaks: " + expected_breaks); |
22 } | 23 } |
23 var source = exec_state.frame(0).sourceLineText(); | 24 var frameMirror = exec_state.frame(0); |
| 25 |
| 26 var v = null;; |
| 27 try { |
| 28 v = frameMirror.evaluate('i').value(); |
| 29 } catch(e) { |
| 30 v = e; |
| 31 } |
| 32 |
| 33 var source = frameMirror.sourceLineText(); |
24 print("paused at: " + source); | 34 print("paused at: " + source); |
25 assertTrue(source.indexOf("// Break " + break_count + ".") > 0, | 35 assertTrue(source.indexOf("// Break " + break_count + ".") > 0, |
26 "Unexpected pause at: " + source + "\n" + | 36 "Unexpected pause at: " + source + "\n" + |
27 "Expected: // Break " + break_count + "."); | 37 "Expected: // Break " + break_count + "."); |
| 38 if (expected_values[break_count] === ReferenceError) { |
| 39 assertTrue(v instanceof ReferenceError); |
| 40 } else { |
| 41 assertSame(expected_values[break_count], v); |
| 42 } |
28 ++break_count; | 43 ++break_count; |
| 44 |
29 if (break_count !== expected_breaks) { | 45 if (break_count !== expected_breaks) { |
30 exec_state.prepareStep(Debug.StepAction.StepIn, 1); | 46 exec_state.prepareStep(Debug.StepAction.StepIn, 1); |
| 47 print("Next step prepared"); |
31 } | 48 } |
32 } | 49 } |
33 } catch(e) { | 50 } catch(e) { |
34 exception = e; | 51 exception = e; |
35 print(e, e.stack); | 52 print(e, e.stack); |
36 } | 53 } |
37 }; | 54 }; |
38 | 55 |
39 Debug.setListener(listener); | 56 Debug.setListener(listener); |
40 var bound_callback = callback.bind(null); | |
41 | 57 |
42 debugger; // Break 0. | 58 var sum = 0; |
43 [1,2].forEach(callback); // Break 1. | 59 (function (){ |
44 [3,4].forEach(bound_callback); // Break 6. | 60 'use strict'; |
45 | 61 |
46 function callback(x) { | 62 debugger; // Break 0. |
47 return x; // Break 2. // Break 4. // Break 7. // Break 9. | |
48 } // Break 3. // Break 5. // Break 8. // Break 10. | |
49 | 63 |
50 assertNull(exception); // Break 11. | 64 for (let i=0; // Break 1. |
| 65 i < 1; // Break 2. // Break 3. // Break 6. // Break 7. |
| 66 i++) { |
| 67 let key = i; // Break 4. |
| 68 sum += key; // Break 5. |
| 69 } |
| 70 }()); // Break 8. |
| 71 |
| 72 assertNull(exception); // Break 9. |
51 assertEquals(expected_breaks, break_count); | 73 assertEquals(expected_breaks, break_count); |
52 | 74 |
53 Debug.setListener(null); | 75 Debug.setListener(null); |
OLD | NEW |