blob: 932840a6f9247b4d799394abcee12a7a12e9b979 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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
7Debug = debug.Debug;
8var break_count = 0
9var exception = null;
10var log = []
11
12var s = 0;
13var a = [1, 2, 3];
14var i = 0;
15
16function f() {
17 "use strict";
18 debugger; // Break a
19 var j; // Break b
20
21 for (var i in null) { // Break c
22 s += a[i];
23 }
24
25 for (j in null) { // Break d
26 s += a[j];
27 }
28
29 for (var i in a) { // Break e
30 s += a[i]; // Break E
31 }
32
33 for (j in a) { // Break f
34 s += a[j]; // Break F
35 }
36
37 for (let i in a) { // Break g
38 s += a[i]; // Break G
39 }
40
41 for (var i of a) { // Break h
42 s += i; // Break H
43 }
44
45 for (j of a) { // Break i
46 s += j; // Break I
47 }
48
49 for (let i of a) { // Break j
50 s += i; // Break J
51 }
52
53 for (var i = 0; i < 3; i++) { // Break k
54 s += a[i]; // Break K
55 }
56
57 for (j = 0; j < 3; j++) { // Break l
58 s += a[j]; // Break L
59 }
60
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000061 for (let i = 0; i < 3; i++) { // Break m
62 s += a[i]; // Break M
63 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040064} // Break y
65
66function listener(event, exec_state, event_data, data) {
67 if (event != Debug.DebugEvent.Break) return;
68 try {
69 var line = exec_state.frame(0).sourceLineText();
70 var col = exec_state.frame(0).sourceColumn();
71 print(line);
72 var match = line.match(/\/\/ Break (\w)$/);
73 assertEquals(2, match.length);
74 log.push(match[1] + col);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000075 exec_state.prepareStep(Debug.StepAction.StepNext);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040076 break_count++;
77 } catch (e) {
78 exception = e;
79 }
80}
81
82Debug.setListener(listener);
83f();
84Debug.setListener(null); // Break z
85
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000086print("log:\n"+ JSON.stringify(log));
Emily Bernierd0a1eb72015-03-24 16:35:39 -040087// The let declaration differs from var in that the loop variable
88// is declared in every iteration.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089// TODO(verwaest): For-of has hacky position numbers for Symbol.iterator and
90// .next. Restore to proper positions once the CallPrinter can disambiguate
91// based on other values.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040092var expected = [
93 // Entry
94 "a2","b2",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000095 // Empty for-in-var: get enumerable
96 "c16",
Emily Bernierd0a1eb72015-03-24 16:35:39 -040097 // Empty for-in: get enumerable
98 "d12",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000099 // For-in-var: get enumerable, assign, body, assign, body, ...
100 "e16","e11","E4","e11","E4","e11","E4","e11",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400101 // For-in: get enumerable, assign, body, assign, body, ...
102 "f12","f7","F4","f7","F4","f7","F4","f7",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000103 // For-in-let: get enumerable, next, body, next, ...
104 "g16","g11","G4","g11","G4","g11","G4","g11",
105 // For-of-var: [Symbol.iterator](), next(), body, next(), body, ...
106 "h16","h14","h15","H4","h15","H4","h15","H4","h15",
107 // For-of: [Symbol.iterator](), next(), body, next(), body, ...
108 "i12","i10","i11","I4","i11","I4","i11","I4","i11",
109 // For-of-let: [Symbol.iterator](), next(), body, next(), ...
110 "j16","j14","j15","J4","j15","J4","j15","J4","j15",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400111 // For-var: var decl, condition, body, next, condition, body, ...
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000112 "k7","k20","K4","k26","k20","K4","k26","k20","K4","k26","k20",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400113 // For: init, condition, body, next, condition, body, ...
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000114 "l7","l16","L4","l22","l16","L4","l22","l16","L4","l22","l16",
115 // For-let: init, condition, body, next, condition, body, ...
116 "m7","m20","M4","m26","m20","M4","m26","m20","M4","m26","m20",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400117 // Exit.
118 "y0","z0",
119]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000120print("expected:\n"+ JSON.stringify(expected));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400121
122assertArrayEquals(expected, log);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000123assertEquals(54, s);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400124assertNull(exception);