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 --harmony | |
6 | |
7 Debug = debug.Debug; | |
8 var break_count = 0 | |
9 var exception = null; | |
10 var log = [] | |
11 | |
12 var s = 0; | |
13 var a = [1, 2, 3]; | |
14 var b = [1, 2, 3, 4]; | |
15 var null_value = null; | |
16 var i = 0; | |
17 | |
18 function f() { | |
19 "use strict"; | |
20 debugger; // Break a | |
21 var j; // Break b | |
22 | |
23 for (var i in null_value) { // Break c | |
24 s += a[i]; | |
25 } | |
26 | |
27 for (j in null_value) { // Break d | |
28 s += a[j]; | |
29 } | |
30 | |
31 for (var i in a) { // Break e | |
32 s += a[i]; // Break E | |
33 } | |
34 | |
35 for (j in a) { // Break f | |
36 s += a[j]; // Break F | |
37 } | |
38 | |
39 for (let i in a) { // Break g | |
40 s += a[i]; // Break G | |
41 } | |
42 | |
43 for (var i of a) { // Break h | |
44 s += i; // Break H | |
45 } | |
46 | |
47 for (j of a) { // Break i | |
48 s += j; // Break I | |
49 } | |
50 | |
51 for (let i of a) { // Break j | |
52 s += i; // Break J | |
53 } | |
54 | |
55 for (var i = 0; i < 3; i++) { // Break k | |
56 s += a[i]; // Break K | |
57 } | |
58 | |
59 for (j = 0; j < 3; j++) { // Break l | |
60 s += a[j]; // Break L | |
61 } | |
62 | |
63 for (let i = 0; i < 3; i++) { // Break m | |
64 s += a[i]; // Break M | |
65 } | |
66 | |
67 for (let i of a) {} // Break n | |
68 | |
69 [1, ...a] // Break o | |
70 | |
71 } // Break y | |
72 | |
73 function listener(event, exec_state, event_data, data) { | |
74 if (event != Debug.DebugEvent.Break) return; | |
75 try { | |
76 var line = exec_state.frame(0).sourceLineText(); | |
77 var col = exec_state.frame(0).sourceColumn(); | |
78 print(line); | |
79 var match = line.match(/\/\/ Break (\w)$/); | |
80 assertEquals(2, match.length); | |
81 log.push(match[1] + col); | |
82 exec_state.prepareStep(Debug.StepAction.StepNext); | |
83 break_count++; | |
84 } catch (e) { | |
85 exception = e; | |
86 } | |
87 } | |
88 | |
89 Debug.setListener(listener); | |
90 f(); | |
91 Debug.setListener(null); // Break z | |
92 | |
93 print("log:\n"+ JSON.stringify(log)); | |
94 // The let declaration differs from var in that the loop variable | |
95 // is declared in every iteration. | |
96 // TODO(verwaest): For-of has hacky position numbers for Symbol.iterator and | |
97 // .next. Restore to proper positions once the CallPrinter can disambiguate | |
98 // based on other values. | |
99 var expected = [ | |
100 // Entry | |
101 "a2", | |
102 // Empty for-in-var: get enumerable | |
103 "c16", | |
104 // Empty for-in: get enumerable | |
105 "d12", | |
106 // For-in-var: get enumerable, assign, body, assign, body, ... | |
107 "e16","e11","E4","e11","E4","e11","E4","e11", | |
108 // For-in: get enumerable, assign, body, assign, body, ... | |
109 "f12","f7","F4","f7","F4","f7","F4","f7", | |
110 // For-in-let: get enumerable, next, body, next, ... | |
111 "g16","g11","G4","g11","G4","g11","G4","g11", | |
112 // For-of-var: [Symbol.iterator](), next(), body, next(), body, ... | |
113 "h16","h13","H4","h13","H4","h13","H4","h13", | |
114 // For-of: [Symbol.iterator](), next(), body, next(), body, ... | |
115 "i12","i9","I4","i9","I4","i9","I4","i9", | |
116 // For-of-let: [Symbol.iterator](), next(), body, next(), ... | |
117 "j18","j14","J4","j14","J4","j14","J4","j14", | |
118 // For-var: init, condition, body, next, condition, body, ... | |
119 "k15","k20","K4","k26","k20","K4","k26","k20","K4","k26","k20", | |
120 // For: init, condition, body, next, condition, body, ... | |
121 "l7","l16","L4","l22","l16","L4","l22","l16","L4","l22","l16", | |
122 // For-let: init, condition, body, next, condition, body, ... | |
123 "m15","m20","M4","m26","m20","M4","m26","m20","M4","m26","m20", | |
124 // For-of, empty: [Symbol.iterator](), next() once | |
125 "n16", "n13", | |
126 // Spread: expression statement, spread | |
127 "o2", "o9", | |
128 // Exit. | |
129 "y0","z0", | |
130 ] | |
131 print("expected:\n"+ JSON.stringify(expected)); | |
132 | |
133 assertArrayEquals(expected, log); | |
134 assertEquals(54, s); | |
135 assertNull(exception); | |
OLD | NEW |