OLD | NEW |
(Empty) | |
| 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 |
| 7 Debug = debug.Debug |
| 8 |
| 9 function BestEditor() { |
| 10 var best_editor = "Emacs"; |
| 11 return best_editor; |
| 12 } |
| 13 |
| 14 var exception = null; |
| 15 var results = []; |
| 16 var log = [] |
| 17 |
| 18 function listener(event, exec_state, event_data, data) { |
| 19 if (event != Debug.DebugEvent.Break) return; |
| 20 try { |
| 21 var source_line = event_data.sourceLineText(); |
| 22 log.push(source_line); |
| 23 if (source_line.indexOf("return") >= 0) { |
| 24 switch (results.length) { |
| 25 case 0: |
| 26 break; |
| 27 case 1: |
| 28 Replace(BestEditor, "Emacs", "Eclipse"); |
| 29 break; |
| 30 case 2: |
| 31 Replace(BestEditor, "Eclipse", "Vim"); |
| 32 break; |
| 33 default: |
| 34 assertUnreachable(); |
| 35 } |
| 36 } |
| 37 exec_state.prepareStep(Debug.StepAction.StepIn, 1); |
| 38 } catch (e) { |
| 39 exception = e; |
| 40 } |
| 41 }; |
| 42 |
| 43 function Replace(fun, original, patch) { |
| 44 var script = Debug.findScript(fun); |
| 45 if (fun.toString().indexOf(original) < 0) return; |
| 46 var patch_pos = script.source.indexOf(original); |
| 47 var change_log = []; |
| 48 Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script, patch_pos, original.lengt
h, patch, change_log); |
| 49 } |
| 50 |
| 51 Debug.setListener(listener); |
| 52 |
| 53 debugger; |
| 54 results.push(BestEditor()); |
| 55 results.push(BestEditor()); |
| 56 results.push(BestEditor()); |
| 57 Debug.setListener(null); |
| 58 |
| 59 assertNull(exception); |
| 60 assertEquals(["Emacs", "Eclipse", "Vim"], results); |
| 61 print(JSON.stringify(log, 1)); |
| 62 assertEquals([ |
| 63 "debugger;", |
| 64 "results.push(BestEditor());", |
| 65 " var best_editor = \"Emacs\";", |
| 66 " return best_editor;","}", |
| 67 "results.push(BestEditor());", |
| 68 "results.push(BestEditor());", |
| 69 " var best_editor = \"Emacs\";", |
| 70 " return best_editor;", |
| 71 " var best_editor = \"Eclipse\";", |
| 72 " return best_editor;","}", |
| 73 "results.push(BestEditor());", |
| 74 "results.push(BestEditor());", |
| 75 " var best_editor = \"Eclipse\";", |
| 76 " return best_editor;", |
| 77 " var best_editor = \"Vim\";", |
| 78 " return best_editor;", |
| 79 "}","results.push(BestEditor());", |
| 80 "Debug.setListener(null);" |
| 81 ], log); |
OLD | NEW |