blob: d425a46b8445739a13cdd190e8e99985f553d9df [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];
Ben Murdochc5610432016-08-08 18:44:38 +010014var b = [1, 2, 3, 4];
15var null_value = null;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040016var i = 0;
17
18function f() {
19 "use strict";
20 debugger; // Break a
21 var j; // Break b
22
Ben Murdochc5610432016-08-08 18:44:38 +010023 for (var i in null_value) { // Break c
Emily Bernierd0a1eb72015-03-24 16:35:39 -040024 s += a[i];
25 }
26
Ben Murdochc5610432016-08-08 18:44:38 +010027 for (j in null_value) { // Break d
Emily Bernierd0a1eb72015-03-24 16:35:39 -040028 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
Ben Murdochc5610432016-08-08 18:44:38 +010051 for (let i of a) { // Break j
Emily Bernierd0a1eb72015-03-24 16:35:39 -040052 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000063 for (let i = 0; i < 3; i++) { // Break m
64 s += a[i]; // Break M
65 }
Ben Murdochc5610432016-08-08 18:44:38 +010066
67 for (let i of a) {} // Break n
68
69 [1, ...a] // Break o
70
Emily Bernierd0a1eb72015-03-24 16:35:39 -040071} // Break y
72
73function 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);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000082 exec_state.prepareStep(Debug.StepAction.StepNext);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040083 break_count++;
84 } catch (e) {
85 exception = e;
86 }
87}
88
89Debug.setListener(listener);
90f();
91Debug.setListener(null); // Break z
92
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000093print("log:\n"+ JSON.stringify(log));
Emily Bernierd0a1eb72015-03-24 16:35:39 -040094// The let declaration differs from var in that the loop variable
95// is declared in every iteration.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000096// 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.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040099var expected = [
100 // Entry
Ben Murdochda12d292016-06-02 14:46:10 +0100101 "a2",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000102 // Empty for-in-var: get enumerable
103 "c16",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400104 // Empty for-in: get enumerable
105 "d12",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000106 // For-in-var: get enumerable, assign, body, assign, body, ...
107 "e16","e11","E4","e11","E4","e11","E4","e11",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400108 // For-in: get enumerable, assign, body, assign, body, ...
109 "f12","f7","F4","f7","F4","f7","F4","f7",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000110 // 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, ...
Ben Murdochc5610432016-08-08 18:44:38 +0100113 "h16","h13","H4","h13","H4","h13","H4","h13",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000114 // For-of: [Symbol.iterator](), next(), body, next(), body, ...
Ben Murdochc5610432016-08-08 18:44:38 +0100115 "i12","i9","I4","i9","I4","i9","I4","i9",
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000116 // For-of-let: [Symbol.iterator](), next(), body, next(), ...
Ben Murdochc5610432016-08-08 18:44:38 +0100117 "j18","j14","J4","j14","J4","j14","J4","j14",
Ben Murdochda12d292016-06-02 14:46:10 +0100118 // For-var: init, condition, body, next, condition, body, ...
119 "k15","k20","K4","k26","k20","K4","k26","k20","K4","k26","k20",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400120 // For: init, condition, body, next, condition, body, ...
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000121 "l7","l16","L4","l22","l16","L4","l22","l16","L4","l22","l16",
122 // For-let: init, condition, body, next, condition, body, ...
Ben Murdochda12d292016-06-02 14:46:10 +0100123 "m15","m20","M4","m26","m20","M4","m26","m20","M4","m26","m20",
Ben Murdochc5610432016-08-08 18:44:38 +0100124 // For-of, empty: [Symbol.iterator](), next() once
125 "n16", "n13",
126 // Spread: expression statement, spread
127 "o2", "o9",
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400128 // Exit.
129 "y0","z0",
130]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131print("expected:\n"+ JSON.stringify(expected));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400132
133assertArrayEquals(expected, log);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000134assertEquals(54, s);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400135assertNull(exception);