summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/debug-liveedit-stepin.js
blob: c6070ce284a82293450ddf2a402814c0312a522d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2015 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

Debug = debug.Debug

function BestEditor() {
  return 'Emacs';
}

var exception = null;
var results = [];
var log = []

function listener(event, exec_state, event_data, data) {
  if (event != Debug.DebugEvent.Break) return;
  try {
    var source_line = event_data.sourceLineText();
    log.push(source_line);
    if (source_line.indexOf("return") >= 0) {
      switch (results.length) {
        case 0:
          break;
        case 1:
          Replace(BestEditor, "Emacs", "Eclipse");
          break;
        case 2:
          Replace(BestEditor, "Eclipse", "Vim");
          break;
        default:
          assertUnreachable();
      }
    }
    exec_state.prepareStep(Debug.StepAction.StepIn);
  } catch (e) {
    exception = e;
  }
};

function Replace(fun, original, patch) {
  var script = Debug.findScript(fun);
  if (fun.toString().indexOf(original) < 0) return;
  var patch_pos = script.source.indexOf(original);
  var change_log = [];
  Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script, patch_pos, original.length, patch, change_log);
}

Debug.setListener(listener);

debugger;
results.push(BestEditor());
results.push(BestEditor());
results.push(BestEditor());
Debug.setListener(null);

assertNull(exception);
assertEquals(["Emacs", "Eclipse", "Vim"], results);
print(JSON.stringify(log, 1));
assertEquals([
  "debugger;",
  "results.push(BestEditor());",
  "  return 'Emacs';","}",
  "results.push(BestEditor());",
  "results.push(BestEditor());",
  "  return 'Emacs';",
  "  return 'Eclipse';","}",
  "results.push(BestEditor());",
  "results.push(BestEditor());",
  "  return 'Eclipse';",
  "  return 'Vim';",
  "}","results.push(BestEditor());",
  "Debug.setListener(null);"
], log);