• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016 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
9function BestEditor() {
10  throw 'Emacs';
11}
12
13var exception = null;
14var results = [];
15var log = []
16
17function listener(event, exec_state, event_data, data) {
18  if (event != Debug.DebugEvent.Exception) return;
19  try {
20    var source_line = event_data.sourceLineText();
21    print(source_line);
22    log.push(source_line);
23    switch (results.length) {
24      case 0:
25        Replace(BestEditor, "Emacs", "Eclipse");
26        break;
27      case 1:
28        Replace(BestEditor, "Eclipse", "Vim");
29        break;
30      case 2:
31        break;
32      default:
33        assertUnreachable();
34    }
35  } catch (e) {
36    exception = e;
37  }
38};
39
40function Replace(fun, original, patch) {
41  var script = Debug.findScript(fun);
42  if (fun.toString().indexOf(original) < 0) return;
43  var patch_pos = script.source.indexOf(original);
44  var change_log = [];
45  Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script, patch_pos, original.length, patch, change_log);
46}
47
48Debug.setListener(listener);
49Debug.setBreakOnException();
50
51for (var i = 0; i < 3; i++) {
52  try {
53    BestEditor();
54  } catch (e) {
55    results.push(e);
56  }
57}
58Debug.setListener(null);
59
60assertNull(exception);
61assertEquals(["Emacs", "Eclipse", "Vim"], results);
62print(JSON.stringify(log, 1));
63assertEquals([
64  "  throw 'Emacs';",
65  "  throw 'Eclipse';",
66  "  throw 'Vim';",
67], log);
68