| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 | 5 |
| 6 var Debug = debug.Debug; | 6 var Debug = debug.Debug; |
| 7 var LiveEdit = Debug.LiveEdit; | 7 var LiveEdit = Debug.LiveEdit; |
| 8 | 8 |
| 9 unique_id = 0; | 9 unique_id = 0; |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // First, try MakeGenerator with no perturbations. | 35 // First, try MakeGenerator with no perturbations. |
| 36 (function(){ | 36 (function(){ |
| 37 var generator = MakeGenerator(); | 37 var generator = MakeGenerator(); |
| 38 function callback() {}; | 38 function callback() {}; |
| 39 var iter = generator(callback); | 39 var iter = generator(callback); |
| 40 assertIteratorResult(undefined, false, iter.next()); | 40 assertIteratorResult(undefined, false, iter.next()); |
| 41 assertIteratorResult("Cat", true, iter.next()); | 41 assertIteratorResult("Cat", true, iter.next()); |
| 42 })(); | 42 })(); |
| 43 | 43 |
| 44 function ExecuteInDebugContext(f) { |
| 45 var result; |
| 46 var exception = null; |
| 47 Debug.setListener(function(event) { |
| 48 if (event == Debug.DebugEvent.Break) { |
| 49 try { |
| 50 result = f(); |
| 51 } catch (e) { |
| 52 // Rethrow this exception later. |
| 53 exception = e; |
| 54 } |
| 55 } |
| 56 }); |
| 57 debugger; |
| 58 Debug.setListener(null); |
| 59 if (exception !== null) throw exception; |
| 60 return result; |
| 61 } |
| 62 |
| 44 function patch(fun, from, to) { | 63 function patch(fun, from, to) { |
| 45 function debug() { | 64 function debug() { |
| 46 var log = new Array(); | 65 var log = new Array(); |
| 47 var script = Debug.findScript(fun); | 66 var script = Debug.findScript(fun); |
| 48 var pos = script.source.indexOf(from); | 67 var pos = script.source.indexOf(from); |
| 49 try { | 68 try { |
| 50 LiveEdit.TestApi.ApplySingleChunkPatch(script, pos, from.length, to, | 69 LiveEdit.TestApi.ApplySingleChunkPatch(script, pos, from.length, to, |
| 51 log); | 70 log); |
| 52 } finally { | 71 } finally { |
| 53 print("Change log: " + JSON.stringify(log) + "\n"); | 72 print("Change log: " + JSON.stringify(log) + "\n"); |
| 54 } | 73 } |
| 55 } | 74 } |
| 56 %ExecuteInDebugContext(debug); | 75 ExecuteInDebugContext(debug); |
| 57 } | 76 } |
| 58 | 77 |
| 59 // Try to edit a MakeGenerator while it's running, then again while it's | 78 // Try to edit a MakeGenerator while it's running, then again while it's |
| 60 // stopped. | 79 // stopped. |
| 61 (function(){ | 80 (function(){ |
| 62 var generator = MakeGenerator(); | 81 var generator = MakeGenerator(); |
| 63 | 82 |
| 64 var gen_patch_attempted = false; | 83 var gen_patch_attempted = false; |
| 65 function attempt_gen_patch() { | 84 function attempt_gen_patch() { |
| 66 assertFalse(gen_patch_attempted); | 85 assertFalse(gen_patch_attempted); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Patching inside a generator activation may succeed. | 128 // Patching inside a generator activation may succeed. |
| 110 patch(fun_inside, "'Cat'", "'Koala'"); | 129 patch(fun_inside, "'Cat'", "'Koala'"); |
| 111 } | 130 } |
| 112 iter = generator(function() { return fun_inside(attempt_fun_patches) }); | 131 iter = generator(function() { return fun_inside(attempt_fun_patches) }); |
| 113 assertEquals('Cat', | 132 assertEquals('Cat', |
| 114 fun_outside(function () { | 133 fun_outside(function () { |
| 115 assertIteratorResult('Koala', false, iter.next()); | 134 assertIteratorResult('Koala', false, iter.next()); |
| 116 assertTrue(fun_patch_restarted); | 135 assertTrue(fun_patch_restarted); |
| 117 })); | 136 })); |
| 118 })(); | 137 })(); |
| OLD | NEW |