debug-stepnext-for.js 3.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --expose-debug-as debug --harmony

Debug = debug.Debug;
var break_count = 0
var exception = null;
var log = []

var s = 0;
var a = [1, 2, 3];
14 15
var b = [1, 2, 3, 4];
var null_value = null;
16 17 18 19 20 21 22
var i = 0;

function f() {
  "use strict";
  debugger;                      // Break a
  var j;                         // Break b

23
  for (var i in null_value) {    // Break c
24 25 26
    s += a[i];
  }

27
  for (j in null_value) {        // Break d
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    s += a[j];
  }

  for (var i in a) {             // Break e
    s += a[i];                   // Break E
  }

  for (j in a) {                 // Break f
    s += a[j];                   // Break F
  }

  for (let i in a) {             // Break g
    s += a[i];                   // Break G
  }

  for (var i of a) {             // Break h
    s += i;                      // Break H
  }

  for (j of a) {                 // Break i
    s += j;                      // Break I
  }

51
  for (let i  of  a) {           // Break j
52 53 54 55 56 57 58 59 60 61 62
    s += i;                      // Break J
  }

  for (var i = 0; i < 3; i++) {  // Break k
    s += a[i];                   // Break K
  }

  for (j = 0; j < 3; j++) {      // Break l
    s += a[j];                   // Break L
  }

63 64 65
  for (let i = 0; i < 3; i++) {  // Break m
    s += a[i];                   // Break M
  }
66 67 68 69 70

  for (let i of a) {}            // Break n

  [1, ...a]                      // Break o

71 72 73 74 75 76 77 78 79 80 81
}                                // Break y

function listener(event, exec_state, event_data, data) {
  if (event != Debug.DebugEvent.Break) return;
  try {
    var line = exec_state.frame(0).sourceLineText();
    var col = exec_state.frame(0).sourceColumn();
    print(line);
    var match = line.match(/\/\/ Break (\w)$/);
    assertEquals(2, match.length);
    log.push(match[1] + col);
82
    exec_state.prepareStep(Debug.StepAction.StepNext);
83 84 85 86 87 88 89 90 91 92
    break_count++;
  } catch (e) {
    exception = e;
  }
}

Debug.setListener(listener);
f();
Debug.setListener(null);         // Break z

93
print("log:\n"+ JSON.stringify(log));
94 95
// The let declaration differs from var in that the loop variable
// is declared in every iteration.
96 97 98
// TODO(verwaest): For-of has hacky position numbers for Symbol.iterator and
// .next. Restore to proper positions once the CallPrinter can disambiguate
// based on other values.
99 100
var expected = [
  // Entry
101
  "a2",
102 103
  // Empty for-in-var: get enumerable
  "c16",
104 105
  // Empty for-in: get enumerable
  "d12",
106 107
  // For-in-var: get enumerable, assign, body, assign, body, ...
  "e16","e11","E4","e11","E4","e11","E4","e11",
108 109
  // For-in: get enumerable, assign, body, assign, body, ...
  "f12","f7","F4","f7","F4","f7","F4","f7",
110 111
  // For-in-let: get enumerable, next, body, next,  ...
  "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 119
  // For-var: init, condition, body, next, condition, body, ...
  "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 125 126 127
  // For-of, empty: [Symbol.iterator](), next() once
  "n16", "n13",
  // Spread: expression statement, spread
  "o2", "o9",
128 129 130
  // Exit.
  "y0","z0",
]
131
print("expected:\n"+ JSON.stringify(expected));
132 133

assertArrayEquals(expected, log);
134
assertEquals(54, s);
135
assertNull(exception);