Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(670)

Side by Side Diff: test/mjsunit/debug-stepin-builtin-callback.js

Issue 1525173003: [debugger] remove step count parameter from prepare step. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 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
(...skipping 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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 29
30 // Test stepping into callbacks passed to builtin functions. 30 // Test stepping into callbacks passed to builtin functions.
31 31
32 Debug = debug.Debug 32 Debug = debug.Debug
33 33
34 var exception = false; 34 var exception = null;
35 35
36 function array_listener(event, exec_state, event_data, data) { 36 function array_listener(event, exec_state, event_data, data) {
37 try { 37 try {
38 if (event == Debug.DebugEvent.Break) { 38 if (event == Debug.DebugEvent.Break) {
39 if (breaks == 0) { 39 print(event_data.sourceLineText(), breaks);
40 exec_state.prepareStep(Debug.StepAction.StepIn, 2); 40 assertTrue(event_data.sourceLineText().indexOf(`B${breaks++}`) > 0);
41 breaks = 1; 41 exec_state.prepareStep(Debug.StepAction.StepIn);
42 } else if (breaks <= 3) {
43 breaks++;
44 // Check whether we break at the expected line.
45 print(event_data.sourceLineText());
46 assertTrue(event_data.sourceLineText().indexOf("Expected to step") > 0);
47 exec_state.prepareStep(Debug.StepAction.StepIn, 3);
48 }
49 } 42 }
50 } catch (e) { 43 } catch (e) {
51 exception = true; 44 print(e);
45 quit();
46 exception = e;
52 } 47 }
53 }; 48 };
54 49
55 function cb_false(num) { 50 function cb_false(num) {
56 print("element " + num); // Expected to step to this point. 51 print("element " + num); // B2 B5 B8
57 return false; 52 return false; // B3 B6 B9
58 } 53 } // B4 B7 B10
59 54
60 function cb_true(num) { 55 function cb_true(num) {
61 print("element " + num); // Expected to step to this point. 56 print("element " + num); // B2 B5 B8
62 return true; 57 return true; // B3 B6 B9
63 } 58 } // B4 B7 B10
64 59
65 function cb_reduce(a, b) { 60 function cb_reduce(a, b) {
66 print("elements " + a + " and " + b); // Expected to step to this point. 61 print("elements " + a + " and " + b); // B2 B5
67 return a + b; 62 return a + b; // B3 B6
68 } 63 } // B4 B7
69 64
70 var a = [1, 2, 3, 4]; 65 var a = [1, 2, 3];
71
72 Debug.setListener(array_listener);
73 66
74 var breaks = 0; 67 var breaks = 0;
75 debugger; 68 Debug.setListener(array_listener);
76 a.forEach(cb_true); 69 debugger; // B0
77 assertFalse(exception); 70 a.forEach(cb_true); // B1
78 assertEquals(4, breaks); 71 Debug.setListener(null); // B11
72 assertNull(exception);
73 assertEquals(12, breaks);
79 74
80 breaks = 0; 75 breaks = 0;
81 debugger; 76 Debug.setListener(array_listener);
82 a.some(cb_false); 77 debugger; // B0
83 assertFalse(exception); 78 a.some(cb_false); // B1
84 assertEquals(4, breaks); 79 Debug.setListener(null); // B11
80 assertNull(exception);
81 assertEquals(12, breaks);
85 82
86 breaks = 0; 83 breaks = 0;
87 debugger; 84 Debug.setListener(array_listener);
88 a.every(cb_true); 85 debugger; // B0
89 assertEquals(4, breaks); 86 a.every(cb_true); // B1
90 assertFalse(exception); 87 Debug.setListener(null); // B11
88 assertNull(exception);
89 assertEquals(12, breaks);
91 90
92 breaks = 0; 91 breaks = 0;
93 debugger; 92 Debug.setListener(array_listener);
94 a.map(cb_true); 93 debugger; // B0
95 assertFalse(exception); 94 a.map(cb_true); // B1
96 assertEquals(4, breaks); 95 Debug.setListener(null); // B11
96 assertNull(exception);
97 assertEquals(12, breaks);
97 98
98 breaks = 0; 99 breaks = 0;
99 debugger; 100 Debug.setListener(array_listener);
100 a.filter(cb_true); 101 debugger; // B0
101 assertFalse(exception); 102 a.filter(cb_true); // B1
102 assertEquals(4, breaks); 103 Debug.setListener(null); // B11
104 assertNull(exception);
105 assertEquals(12, breaks);
103 106
104 breaks = 0; 107 breaks = 0;
105 debugger; 108 Debug.setListener(array_listener);
106 a.reduce(cb_reduce); 109 debugger; // B0
107 assertFalse(exception); 110 a.reduce(cb_reduce); // B1
108 assertEquals(4, breaks); 111 Debug.setListener(null); // B8
112 assertNull(exception);
113 assertEquals(9, breaks);
109 114
110 breaks = 0; 115 breaks = 0;
111 debugger; 116 Debug.setListener(array_listener);
112 a.reduceRight(cb_reduce); 117 debugger; // B0
113 assertFalse(exception); 118 a.reduceRight(cb_reduce); // B1
114 assertEquals(4, breaks); 119 Debug.setListener(null); // B8
115 120 assertNull(exception);
116 Debug.setListener(null); 121 assertEquals(9, breaks);
117 122
118 123
119 // Test two levels of builtin callbacks: 124 // Test two levels of builtin callbacks:
120 // Array.forEach calls a callback function, which by itself uses 125 // Array.forEach calls a callback function, which by itself uses
121 // Array.forEach with another callback function. 126 // Array.forEach with another callback function.
122 127
123 function second_level_listener(event, exec_state, event_data, data) { 128 function cb_true_2(num) {
124 try { 129 print("element " + num); // B3 B6 B9 B15 B18 B21 B27 B30 B33
125 if (event == Debug.DebugEvent.Break) { 130 return true; // B4 B7 B10 B16 B19 B22 B28 B31 B34
126 if (breaks == 0) { 131 } // B5 B8 B11 B17 B20 B23 B29 B32 B35
127 exec_state.prepareStep(Debug.StepAction.StepIn, 3);
128 breaks = 1;
129 } else if (breaks <= 16) {
130 breaks++;
131 // Check whether we break at the expected line.
132 assertTrue(event_data.sourceLineText().indexOf("Expected to step") > 0);
133 // Step two steps further every four breaks to skip the
134 // forEach call in the first level of recurision.
135 var step = (breaks % 4 == 1) ? 6 : 3;
136 exec_state.prepareStep(Debug.StepAction.StepIn, step);
137 }
138 }
139 } catch (e) {
140 exception = true;
141 }
142 };
143 132
144 function cb_foreach(num) { 133 function cb_foreach(num) {
145 a.forEach(cb_true); 134 a.forEach(cb_true_2); // B2 B14 B20 B26
146 print("back to the first level of recursion."); 135 print("back."); // B12 B18 B24 B36
147 } 136 } // B13 B19 B25 B37
148
149 Debug.setListener(second_level_listener);
150 137
151 breaks = 0; 138 breaks = 0;
152 debugger; 139 Debug.setListener(array_listener);
153 a.forEach(cb_foreach); 140 debugger; // B0
154 assertFalse(exception); 141 a.forEach(cb_foreach); // B1
155 assertEquals(17, breaks); 142 Debug.setListener(null); // B38
156 143 assertNull(exception);
157 Debug.setListener(null); 144 assertEquals(39, breaks);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698