OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var Debug = debug.Debug; | 5 var Debug = debug.Debug; |
6 var LiveEdit = Debug.LiveEdit; | 6 var LiveEdit = Debug.LiveEdit; |
7 | 7 |
8 unique_id = 0; | 8 unique_id = 0; |
9 | 9 |
10 var AsyncFunction = (async function(){}).constructor; | 10 var AsyncFunction = (async function(){}).constructor; |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 // First, try MakeGenerator with no perturbations. | 43 // First, try MakeGenerator with no perturbations. |
44 (function(){ | 44 (function(){ |
45 var asyncfn = MakeAsyncFunction(); | 45 var asyncfn = MakeAsyncFunction(); |
46 function callback() {}; | 46 function callback() {}; |
47 var promise = asyncfn(callback); | 47 var promise = asyncfn(callback); |
48 assertPromiseValue('Cat', promise); | 48 assertPromiseValue('Cat', promise); |
49 })(); | 49 })(); |
50 | 50 |
| 51 function ExecuteInDebugContext(f) { |
| 52 var result; |
| 53 var exception = null; |
| 54 Debug.setListener(function(event) { |
| 55 if (event == Debug.DebugEvent.Break) { |
| 56 try { |
| 57 result = f(); |
| 58 } catch (e) { |
| 59 // Rethrow this exception later. |
| 60 exception = e; |
| 61 } |
| 62 } |
| 63 }); |
| 64 debugger; |
| 65 Debug.setListener(null); |
| 66 if (exception !== null) throw exception; |
| 67 return result; |
| 68 } |
| 69 |
51 function patch(fun, from, to) { | 70 function patch(fun, from, to) { |
52 function debug() { | 71 function debug() { |
53 var log = new Array(); | 72 var log = new Array(); |
54 var script = Debug.findScript(fun); | 73 var script = Debug.findScript(fun); |
55 var pos = script.source.indexOf(from); | 74 var pos = script.source.indexOf(from); |
56 print(`pos ${pos}`); | 75 print(`pos ${pos}`); |
57 try { | 76 try { |
58 LiveEdit.TestApi.ApplySingleChunkPatch(script, pos, from.length, to, | 77 LiveEdit.TestApi.ApplySingleChunkPatch(script, pos, from.length, to, |
59 log); | 78 log); |
60 } finally { | 79 } finally { |
61 print("Change log: " + JSON.stringify(log) + "\n"); | 80 print("Change log: " + JSON.stringify(log) + "\n"); |
62 } | 81 } |
63 } | 82 } |
64 %ExecuteInDebugContext(debug); | 83 ExecuteInDebugContext(debug); |
65 } | 84 } |
66 | 85 |
67 // Try to edit a MakeAsyncFunction while it's running, then again while it's | 86 // Try to edit a MakeAsyncFunction while it's running, then again while it's |
68 // stopped. | 87 // stopped. |
69 (function(){ | 88 (function(){ |
70 var asyncfn = MakeAsyncFunction(); | 89 var asyncfn = MakeAsyncFunction(); |
71 | 90 |
72 var patch_attempted = false; | 91 var patch_attempted = false; |
73 function attempt_patch() { | 92 function attempt_patch() { |
74 assertFalse(patch_attempted); | 93 assertFalse(patch_attempted); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 promise = asyncfn(function() { return fun_inside(attempt_fun_patches) }); | 140 promise = asyncfn(function() { return fun_inside(attempt_fun_patches) }); |
122 assertEquals('Cat', | 141 assertEquals('Cat', |
123 fun_outside(function () { | 142 fun_outside(function () { |
124 assertPromiseValue('Capybara', promise); | 143 assertPromiseValue('Capybara', promise); |
125 assertTrue(fun_patch_restarted); | 144 assertTrue(fun_patch_restarted); |
126 assertTrue(fun_inside.toString().includes("'Koala'")); | 145 assertTrue(fun_inside.toString().includes("'Koala'")); |
127 })); | 146 })); |
128 })(); | 147 })(); |
129 | 148 |
130 %RunMicrotasks(); | 149 %RunMicrotasks(); |
OLD | NEW |