| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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 // Test that live-editing a frame to introduce new.target fails. | 6 // Test that live-editing a frame to introduce new.target fails. |
| 7 | 7 |
| 8 Debug = debug.Debug | 8 Debug = debug.Debug |
| 9 var calls = 0; | 9 var calls = 0; |
| 10 var exceptions = 0; | 10 var exceptions = 0; |
| 11 var results = []; | 11 var results = []; |
| 12 var replace_again; | 12 var replace_again; |
| 13 | 13 |
| 14 eval(` | 14 eval(` |
| 15 function LogNewTarget() { | 15 function LogNewTarget() { |
| 16 calls++; | 16 calls++; |
| 17 ReplaceOnce(); | 17 ReplaceOnce(); |
| 18 results.push(true); | 18 results.push(true); |
| 19 } | 19 } |
| 20 `); | 20 `); |
| 21 | 21 |
| 22 function ExecuteInDebugContext(f) { |
| 23 var result; |
| 24 var exception = null; |
| 25 Debug.setListener(function(event) { |
| 26 if (event == Debug.DebugEvent.Break) { |
| 27 try { |
| 28 result = f(); |
| 29 } catch (e) { |
| 30 // Rethrow this exception later. |
| 31 exception = e; |
| 32 } |
| 33 } |
| 34 }); |
| 35 debugger; |
| 36 Debug.setListener(null); |
| 37 if (exception !== null) throw exception; |
| 38 return result; |
| 39 } |
| 40 |
| 22 function Replace(fun, original, patch) { | 41 function Replace(fun, original, patch) { |
| 23 %ExecuteInDebugContext(function() { | 42 ExecuteInDebugContext(function() { |
| 24 var change_log = []; | 43 var change_log = []; |
| 25 try { | 44 try { |
| 26 var script = Debug.findScript(fun); | 45 var script = Debug.findScript(fun); |
| 27 var patch_pos = script.source.indexOf(original); | 46 var patch_pos = script.source.indexOf(original); |
| 28 Debug.LiveEdit.TestApi.ApplySingleChunkPatch( | 47 Debug.LiveEdit.TestApi.ApplySingleChunkPatch( |
| 29 script, patch_pos, original.length, patch, change_log); | 48 script, patch_pos, original.length, patch, change_log); |
| 30 } catch (e) { | 49 } catch (e) { |
| 31 assertEquals("BLOCKED_NO_NEW_TARGET_ON_RESTART", | 50 assertEquals("BLOCKED_NO_NEW_TARGET_ON_RESTART", |
| 32 change_log[0].functions_on_stack[0].replace_problem); | 51 change_log[0].functions_on_stack[0].replace_problem); |
| 33 assertInstanceof(e, Debug.LiveEdit.Failure); | 52 assertInstanceof(e, Debug.LiveEdit.Failure); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 53 Revert(); | 72 Revert(); |
| 54 assertEquals(1, calls); | 73 assertEquals(1, calls); |
| 55 assertEquals(0, exceptions); | 74 assertEquals(0, exceptions); |
| 56 assertEquals([LogNewTarget], results); | 75 assertEquals([LogNewTarget], results); |
| 57 | 76 |
| 58 replace_again = true; | 77 replace_again = true; |
| 59 new LogNewTarget(); | 78 new LogNewTarget(); |
| 60 assertEquals(2, calls); // No restarts | 79 assertEquals(2, calls); // No restarts |
| 61 assertEquals(1, exceptions); // Replace failed. | 80 assertEquals(1, exceptions); // Replace failed. |
| 62 assertEquals([LogNewTarget, true], results); | 81 assertEquals([LogNewTarget, true], results); |
| OLD | NEW |