OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 // | |
5 // Flags: --expose-debug-as debug | |
6 | |
7 Debug = debug.Debug | |
8 | |
9 var exception = null; | |
10 | |
11 function listener(event, exec_state, event_data, data) { | |
12 try { | |
13 if (event == Debug.DebugEvent.Break) { | |
14 exec_state.prepareStep(Debug.StepAction.StepIn); | |
15 print(event_data.sourceLineText()); | |
16 assertTrue( | |
17 event_data.sourceLineText().indexOf(`B${breaks++}`) > 0); | |
18 } | |
19 } catch (e) { | |
20 print(e); | |
21 quit(); | |
22 exception = e; | |
23 } | |
24 } | |
25 | |
26 function cb_set(num) { | |
27 print("element " + num); // B2 B5 B8 | |
28 return true; // B3 B6 B9 | |
29 } // B4 B7 B10 | |
30 | |
31 function cb_map(key, val) { | |
32 print("key " + key + ", value " + val); // B2 B5 B8 | |
33 return true; // B3 B6 B9 | |
34 } // B4 B7 B10 | |
35 | |
36 var s = new Set(); | |
37 s.add(1); | |
38 s.add(2); | |
39 s.add(3); | |
40 | |
41 var m = new Map(); | |
42 m.set('foo', 1); | |
43 m.set('bar', 2); | |
44 m.set('baz', 3); | |
45 | |
46 var breaks = 0; | |
47 Debug.setListener(listener); | |
48 debugger; // B0 | |
49 s.forEach(cb_set); // B1 | |
50 Debug.setListener(null); // B11 | |
51 assertNull(exception); | |
52 assertEquals(12, breaks); | |
53 | |
54 breaks = 0; | |
55 Debug.setListener(listener); | |
56 debugger; // B0 | |
57 m.forEach(cb_map); // B1 | |
58 Debug.setListener(null); // B11 | |
59 assertNull(exception); | |
60 assertEquals(12, breaks); | |
61 | |
62 // Test two levels of builtin callbacks: | |
63 // Array.forEach calls a callback function, which by itself uses | |
64 // Array.forEach with another callback function. | |
65 | |
66 function cb_set_2(num) { | |
67 print("element " + num); // B3 B6 B9 B15 B18 B21 B27 B30 B33 | |
68 return true; // B4 B7 B10 B16 B19 B22 B28 B31 B34 | |
69 } // B5 B8 B11 B17 B20 B23 B29 B32 B35 | |
70 | |
71 function cb_map_2(k, v) { | |
72 print(`key ${k}, value ${v}`); // B3 B6 B9 B15 B18 B21 B27 B30 B33 | |
73 return true; // B4 B7 B10 B16 B19 B22 B28 B31 B34 | |
74 } // B5 B8 B11 B17 B20 B23 B29 B32 B35 | |
75 | |
76 function cb_set_foreach(num) { | |
77 s.forEach(cb_set_2); // B2 B14 B26 | |
78 print("back."); // B12 B24 B36 | |
79 } // B13 B25 B37 | |
80 | |
81 function cb_map_foreach(key, val) { | |
82 m.forEach(cb_map_2); // B2 B14 B26 | |
83 print("back."); // B12 B24 B36 | |
84 } // B13 B25 B37 | |
85 | |
86 breaks = 0; | |
87 Debug.setListener(listener); | |
88 debugger; // B0 | |
89 s.forEach(cb_set_foreach); // B1 | |
90 Debug.setListener(null); // B38 | |
91 assertNull(exception); | |
92 assertEquals(39, breaks); | |
93 | |
94 breaks = 0; | |
95 Debug.setListener(listener); | |
96 debugger; // B0 | |
97 m.forEach(cb_map_foreach); // B1 | |
98 Debug.setListener(null); // B38 | |
99 assertNull(exception); | |
100 assertEquals(39, breaks); | |
OLD | NEW |