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 i = 0; 15 16 function 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 61 for (let i = 0; i < 3; i++) { // Break m 62 s += a[i]; // Break M 63 } 64 } // Break y 65 66 function 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); 75 exec_state.prepareStep(Debug.StepAction.StepNext); 76 break_count++; 77 } catch (e) { 78 exception = e; 79 } 80 } 81 82 Debug.setListener(listener); 83 f(); 84 Debug.setListener(null); // Break z 85 86 print("log:\n"+ JSON.stringify(log)); 87 // The let declaration differs from var in that the loop variable 88 // is declared in every iteration. 89 // 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. 92 var expected = [ 93 // Entry 94 "a2","b2", 95 // Empty for-in-var: get enumerable 96 "c16", 97 // Empty for-in: get enumerable 98 "d12", 99 // For-in-var: get enumerable, assign, body, assign, body, ... 100 "e16","e11","E4","e11","E4","e11","E4","e11", 101 // For-in: get enumerable, assign, body, assign, body, ... 102 "f12","f7","F4","f7","F4","f7","F4","f7", 103 // 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", 111 // For-var: var decl, condition, body, next, condition, body, ... 112 "k7","k20","K4","k26","k20","K4","k26","k20","K4","k26","k20", 113 // For: init, condition, body, next, condition, body, ... 114 "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", 117 // Exit. 118 "y0","z0", 119 ] 120 print("expected:\n"+ JSON.stringify(expected)); 121 122 assertArrayEquals(expected, log); 123 assertEquals(54, s); 124 assertNull(exception); 125