1// Copyright 2015 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
6
7Debug = debug.Debug
8
9var exception = null;
10var log = [];
11
12function listener(event, exec_state, event_data, data) {
13  if (event != Debug.DebugEvent.Break) return;
14  try {
15    print(event_data.sourceLineText());
16    var entry = "";
17    for (var i = 0; i < exec_state.frameCount(); i++) {
18      entry += exec_state.frame(i).sourceLineText().substr(-1);
19      entry += exec_state.frame(i).sourceColumn();
20    }
21    log.push(entry);
22    exec_state.prepareStep(Debug.StepAction.StepIn);
23  } catch (e) {
24    exception = e;
25  }
26};
27
28function u(x) {
29  return x.toUpperCase();                         // d
30}                                                 // e
31
32var n = 3;
33
34var o = {
35  toString: function() {
36    return "D";                                   // f
37  }                                               // g
38}
39
40
41
42Debug.setListener(listener);
43debugger;                                         // a
44var s = `1 ${u("a")} 2 ${u("b")} 3 ${n} 4 ${o}`;  // b
45Debug.setListener(null);                          // c
46
47assertNull(exception);
48
49assertEquals([
50  "a0",
51  "b0",
52  "d2b13",
53  "e0b13",
54  "b25",
55  "d2b25",
56  "e0b25",
57  "f4b44",
58  "g2b44",
59  "c0"
60], log);
61