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

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

Issue 10078014: Enable stepping into callback passed to builtins (e.g. Array.forEach). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 8 months 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 | Annotate | Revision Log
« src/runtime.cc ('K') | « src/string.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 // Flags: --expose-debug-as debug
29
30 // Test stepping into callbacks passed to builtin functions.
31
32 Debug = debug.Debug
33
34 var exception = false;
35
36 function array_listener(event, exec_state, event_data, data) {
37 try {
38 if (event == Debug.DebugEvent.Break) {
39 if (breaks == 0) {
40 exec_state.prepareStep(Debug.StepAction.StepIn, 2);
41 breaks = 1;
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 }
50 } catch (e) {
51 exception = true;
52 }
53 };
54
55 function cb_false(num) {
56 print("element " + num); // Expected to step to this point.
57 return false;
58 }
59
60 function cb_true(num) {
61 print("element " + num); // Expected to step to this point.
62 return true;
63 }
64
65 function cb_reduce(a, b) {
66 print("elements " + a + " and " + b); // Expected to step to this point.
67 return a + b;
68 }
69
70 var a = [1, 2, 3, 4];
71
72 Debug.setListener(array_listener);
73
74 var breaks = 0;
75 debugger;
76 a.forEach(cb_true);
77 assertFalse(exception);
78 assertEquals(4, breaks);
79
80 breaks = 0;
81 debugger;
82 a.some(cb_false);
83 assertFalse(exception);
84 assertEquals(4, breaks);
85
86 breaks = 0;
87 debugger;
88 a.every(cb_true);
89 assertEquals(4, breaks);
90 assertFalse(exception);
91
92 breaks = 0;
93 debugger;
94 a.map(cb_true);
95 assertFalse(exception);
96 assertEquals(4, breaks);
97
98 breaks = 0;
99 debugger;
100 a.filter(cb_true);
101 assertFalse(exception);
102 assertEquals(4, breaks);
103
104 breaks = 0;
105 debugger;
106 a.reduce(cb_reduce);
107 assertFalse(exception);
108 assertEquals(4, breaks);
109
110 breaks = 0;
111 debugger;
112 a.reduceRight(cb_reduce);
113 assertFalse(exception);
114 assertEquals(4, breaks);
115
116 Debug.setListener(null);
117
118
119 // Test two levels of builtin callbacks:
120 // Array.forEach calls a callback function, which by itself uses
121 // Array.forEach with another callback function.
122
123 function second_level_listener(event, exec_state, event_data, data) {
124 try {
125 if (event == Debug.DebugEvent.Break) {
126 if (breaks == 0) {
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
144 function cb_foreach(num) {
145 a.forEach(cb_true);
146 print("back to the first level of recursion.");
147 }
148
149 Debug.setListener(second_level_listener);
150
151 breaks = 0;
152 debugger;
153 a.forEach(cb_foreach);
154 assertFalse(exception);
155 assertEquals(17, breaks);
156
157 Debug.setListener(null);
158
159
160 //Test replace callback in String.replace.
161
162 function replace_listener(event, exec_state, event_data, data) {
163 try {
164 if (event == Debug.DebugEvent.Break) {
165 if (breaks == 0) {
166 exec_state.prepareStep(Debug.StepAction.StepIn, 2);
167 breaks = 1;
168 } else {
169 // Check whether we break at the expected line.
170 assertTrue(event_data.sourceLineText().indexOf("Expected to step") > 0);
171 }
172 }
173 } catch (e) {
174 exception = true;
175 }
176 };
177
178 function cb_replace(match) {
179 print("matching string: " + match); // Expected to step to this point.
180 return "_";
181 }
182
183 var s = "abcdefgehijke";
184
185 Debug.setListener(replace_listener);
186
187 breaks = 0;
188 debugger;
189 assertEquals("ab_defgehijke", s.replace("c", cb_replace));
190 assertFalse(exception);
191 assertEquals(1, breaks);
192
193 breaks = 0;
194 debugger;
195 assertEquals("abcdefgehij_", s.replace(/..$/, cb_replace));
196 assertFalse(exception);
197 assertEquals(1, breaks);
198
199 breaks = 0;
200 debugger;
201 assertEquals("abcd_fg_hijk_", s.replace(/e/g, cb_replace));
202 assertFalse(exception);
203 assertEquals(1, breaks);
204
205
206 Debug.setListener(null);
OLDNEW
« src/runtime.cc ('K') | « src/string.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698