| 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 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 // TODO(yangguo): add test case for for-let. | |
| 62 } // Break y | |
| 63 | |
| 64 function listener(event, exec_state, event_data, data) { | |
| 65 if (event != Debug.DebugEvent.Break) return; | |
| 66 try { | |
| 67 var line = exec_state.frame(0).sourceLineText(); | |
| 68 var col = exec_state.frame(0).sourceColumn(); | |
| 69 print(line); | |
| 70 var match = line.match(/\/\/ Break (\w)$/); | |
| 71 assertEquals(2, match.length); | |
| 72 log.push(match[1] + col); | |
| 73 exec_state.prepareStep(Debug.StepAction.StepNext, 1); | |
| 74 break_count++; | |
| 75 } catch (e) { | |
| 76 exception = e; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 Debug.setListener(listener); | |
| 81 f(); | |
| 82 Debug.setListener(null); // Break z | |
| 83 | |
| 84 print(JSON.stringify(log)); | |
| 85 // The let declaration differs from var in that the loop variable | |
| 86 // is declared in every iteration. | |
| 87 var expected = [ | |
| 88 // Entry | |
| 89 "a2","b2", | |
| 90 // Empty for-in-var: var decl, get enumerable | |
| 91 "c7","c16", | |
| 92 // Empty for-in: get enumerable | |
| 93 "d12", | |
| 94 // For-in-var: var decl, get enumerable, assign, body, assign, body, ... | |
| 95 "e7","e16","e11","E4","e11","E4","e11","E4", | |
| 96 // For-in: get enumerable, assign, body, assign, body, ... | |
| 97 "f12","f7","F4","f7","F4","f7","F4", | |
| 98 // For-in-let: get enumerable, assign new let, body, assign new let, ... | |
| 99 "g16","g7","G4","g7","G4","g7","G4", | |
| 100 // For-of-var: var decl, next(), body, next(), body, ... | |
| 101 "h7","h16","H4","h16","H4","h16","H4","h16", | |
| 102 // For-of: next(), body, next(), body, ... | |
| 103 "i12","I4","i12","I4","i12","I4","i12", | |
| 104 // For-of-let: next(), assign new let, body, next(), assign new let, ... | |
| 105 "j16","j7","J4","j16","j7","J4","j16","j7","J4","j16", | |
| 106 // For-var: var decl, condition, body, next, condition, body, ... | |
| 107 "k7","k20","K4","k23","k20","K4","k23","k20","K4","k23","k20", | |
| 108 // For: init, condition, body, next, condition, body, ... | |
| 109 "l11","l16","L4","l19","l16","L4","l19","l16","L4","l19","l16", | |
| 110 // Exit. | |
| 111 "y0","z0", | |
| 112 ] | |
| 113 | |
| 114 assertArrayEquals(expected, log); | |
| 115 assertEquals(48, s); | |
| 116 assertNull(exception); | |
| OLD | NEW |