| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 | 6 |
| 7 Debug = debug.Debug | 7 Debug = debug.Debug |
| 8 | 8 |
| 9 var exception = false; | 9 var exception = null; |
| 10 | 10 |
| 11 function listener(event, exec_state, event_data, data) { | 11 function listener(event, exec_state, event_data, data) { |
| 12 try { | 12 try { |
| 13 if (event == Debug.DebugEvent.Break) { | 13 if (event == Debug.DebugEvent.Break) { |
| 14 if (breaks == 0) { | 14 exec_state.prepareStep(Debug.StepAction.StepIn); |
| 15 exec_state.prepareStep(Debug.StepAction.StepIn, 2); | 15 print(event_data.sourceLineText()); |
| 16 breaks = 1; | 16 assertTrue( |
| 17 } else if (breaks <= 3) { | 17 event_data.sourceLineText().indexOf(`B${breaks++}`) > 0); |
| 18 breaks++; | |
| 19 // Check whether we break at the expected line. | |
| 20 print(event_data.sourceLineText()); | |
| 21 assertTrue(event_data.sourceLineText().indexOf("Expected to step") > 0); | |
| 22 exec_state.prepareStep(Debug.StepAction.StepIn, 3); | |
| 23 } | |
| 24 } | 18 } |
| 25 } catch (e) { | 19 } catch (e) { |
| 26 exception = true; | 20 print(e); |
| 21 quit(); |
| 22 exception = e; |
| 27 } | 23 } |
| 28 } | 24 } |
| 29 | 25 |
| 30 function cb_set(num) { | 26 function cb_set(num) { |
| 31 print("element " + num); // Expected to step to this point. | 27 print("element " + num); // B2 B5 B8 |
| 32 return true; | 28 return true; // B3 B6 B9 |
| 33 } | 29 } // B4 B7 B10 |
| 34 | 30 |
| 35 function cb_map(key, val) { | 31 function cb_map(key, val) { |
| 36 print("key " + key + ", value " + val); // Expected to step to this point. | 32 print("key " + key + ", value " + val); // B2 B5 B8 |
| 37 return true; | 33 return true; // B3 B6 B9 |
| 38 } | 34 } // B4 B7 B10 |
| 39 | 35 |
| 40 var s = new Set(); | 36 var s = new Set(); |
| 41 s.add(1); | 37 s.add(1); |
| 42 s.add(2); | 38 s.add(2); |
| 43 s.add(3); | 39 s.add(3); |
| 44 s.add(4); | |
| 45 | 40 |
| 46 var m = new Map(); | 41 var m = new Map(); |
| 47 m.set('foo', 1); | 42 m.set('foo', 1); |
| 48 m.set('bar', 2); | 43 m.set('bar', 2); |
| 49 m.set('baz', 3); | 44 m.set('baz', 3); |
| 50 m.set('bat', 4); | |
| 51 | |
| 52 Debug.setListener(listener); | |
| 53 | 45 |
| 54 var breaks = 0; | 46 var breaks = 0; |
| 55 debugger; | 47 Debug.setListener(listener); |
| 56 s.forEach(cb_set); | 48 debugger; // B0 |
| 57 assertFalse(exception); | 49 s.forEach(cb_set); // B1 |
| 58 assertEquals(4, breaks); | 50 Debug.setListener(null); // B11 |
| 51 assertNull(exception); |
| 52 assertEquals(12, breaks); |
| 59 | 53 |
| 60 breaks = 0; | 54 breaks = 0; |
| 61 debugger; | 55 Debug.setListener(listener); |
| 62 m.forEach(cb_map); | 56 debugger; // B0 |
| 63 assertFalse(exception); | 57 m.forEach(cb_map); // B1 |
| 64 assertEquals(4, breaks); | 58 Debug.setListener(null); // B11 |
| 65 | 59 assertNull(exception); |
| 66 Debug.setListener(null); | 60 assertEquals(12, breaks); |
| 67 | |
| 68 | 61 |
| 69 // Test two levels of builtin callbacks: | 62 // Test two levels of builtin callbacks: |
| 70 // Array.forEach calls a callback function, which by itself uses | 63 // Array.forEach calls a callback function, which by itself uses |
| 71 // Array.forEach with another callback function. | 64 // Array.forEach with another callback function. |
| 72 | 65 |
| 73 function second_level_listener(event, exec_state, event_data, data) { | 66 function cb_set_2(num) { |
| 74 try { | 67 print("element " + num); // B3 B6 B9 B15 B18 B21 B27 B30 B33 |
| 75 if (event == Debug.DebugEvent.Break) { | 68 return true; // B4 B7 B10 B16 B19 B22 B28 B31 B34 |
| 76 if (breaks == 0) { | 69 } // B5 B8 B11 B17 B20 B23 B29 B32 B35 |
| 77 exec_state.prepareStep(Debug.StepAction.StepIn, 3); | 70 |
| 78 breaks = 1; | 71 function cb_map_2(k, v) { |
| 79 } else if (breaks <= 16) { | 72 print(`key ${k}, value ${v}`); // B3 B6 B9 B15 B18 B21 B27 B30 B33 |
| 80 breaks++; | 73 return true; // B4 B7 B10 B16 B19 B22 B28 B31 B34 |
| 81 // Check whether we break at the expected line. | 74 } // B5 B8 B11 B17 B20 B23 B29 B32 B35 |
| 82 assertTrue(event_data.sourceLineText().indexOf("Expected to step") > 0); | |
| 83 // Step two steps further every four breaks to skip the | |
| 84 // forEach call in the first level of recurision. | |
| 85 var step = (breaks % 4 == 1) ? 6 : 3; | |
| 86 exec_state.prepareStep(Debug.StepAction.StepIn, step); | |
| 87 } | |
| 88 } | |
| 89 } catch (e) { | |
| 90 exception = true; | |
| 91 } | |
| 92 } | |
| 93 | 75 |
| 94 function cb_set_foreach(num) { | 76 function cb_set_foreach(num) { |
| 95 s.forEach(cb_set); | 77 s.forEach(cb_set_2); // B2 B14 B26 |
| 96 print("back to the first level of recursion."); | 78 print("back."); // B12 B24 B36 |
| 97 } | 79 } // B13 B25 B37 |
| 98 | 80 |
| 99 function cb_map_foreach(key, val) { | 81 function cb_map_foreach(key, val) { |
| 100 m.forEach(cb_set); | 82 m.forEach(cb_map_2); // B2 B14 B26 |
| 101 print("back to the first level of recursion."); | 83 print("back."); // B12 B24 B36 |
| 102 } | 84 } // B13 B25 B37 |
| 103 | |
| 104 Debug.setListener(second_level_listener); | |
| 105 | 85 |
| 106 breaks = 0; | 86 breaks = 0; |
| 107 debugger; | 87 Debug.setListener(listener); |
| 108 s.forEach(cb_set_foreach); | 88 debugger; // B0 |
| 109 assertFalse(exception); | 89 s.forEach(cb_set_foreach); // B1 |
| 110 assertEquals(17, breaks); | 90 Debug.setListener(null); // B38 |
| 91 assertNull(exception); |
| 92 assertEquals(39, breaks); |
| 111 | 93 |
| 112 breaks = 0; | 94 breaks = 0; |
| 113 debugger; | 95 Debug.setListener(listener); |
| 114 m.forEach(cb_map_foreach); | 96 debugger; // B0 |
| 115 assertFalse(exception); | 97 m.forEach(cb_map_foreach); // B1 |
| 116 assertEquals(17, breaks); | 98 Debug.setListener(null); // B38 |
| 117 | 99 assertNull(exception); |
| 118 Debug.setListener(null); | 100 assertEquals(39, breaks); |
| OLD | NEW |