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 7 Debug = debug.Debug 8 9 function BestEditor() { 10 throw 'Emacs'; 11 } 12 13 var exception = null; 14 var results = []; 15 var log = [] 16 17 function 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 40 function 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 48 Debug.setListener(listener); 49 Debug.setBreakOnException(); 50 51 for (var i = 0; i < 3; i++) { 52 try { 53 BestEditor(); 54 } catch (e) { 55 results.push(e); 56 } 57 } 58 Debug.setListener(null); 59 60 assertNull(exception); 61 assertEquals(["Emacs", "Eclipse", "Vim"], results); 62 print(JSON.stringify(log, 1)); 63 assertEquals([ 64 " throw 'Emacs';", 65 " throw 'Eclipse';", 66 " throw 'Vim';", 67 ], log); 68