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 above one that uses new.target succeeds. | 6 // Test that live-editing a frame above one that uses new.target succeeds. |
7 | 7 |
8 Debug = debug.Debug | 8 Debug = debug.Debug |
9 var wrapper_calls = 0; | 9 var wrapper_calls = 0; |
10 var construct_calls = 0; | 10 var construct_calls = 0; |
11 var exceptions = 0; | 11 var exceptions = 0; |
12 var results = []; | 12 var results = []; |
13 var replace_again; | 13 var replace_again; |
14 | 14 |
15 eval(` | 15 eval(` |
16 function LogNewTarget(arg) { | 16 function LogNewTarget(arg) { |
17 construct_calls++; | 17 construct_calls++; |
18 results.push(new.target); | 18 results.push(new.target); |
19 } | 19 } |
20 function Wrapper() { | 20 function Wrapper() { |
21 wrapper_calls++; | 21 wrapper_calls++; |
22 ReplaceOnce(); | 22 ReplaceOnce(); |
23 new LogNewTarget(true); | 23 new LogNewTarget(true); |
24 } | 24 } |
25 `); | 25 `); |
26 | 26 |
| 27 function ExecuteInDebugContext(f) { |
| 28 var result; |
| 29 var exception = null; |
| 30 Debug.setListener(function(event) { |
| 31 if (event == Debug.DebugEvent.Break) { |
| 32 try { |
| 33 result = f(); |
| 34 } catch (e) { |
| 35 // Rethrow this exception later. |
| 36 exception = e; |
| 37 } |
| 38 } |
| 39 }); |
| 40 debugger; |
| 41 Debug.setListener(null); |
| 42 if (exception !== null) throw exception; |
| 43 return result; |
| 44 } |
| 45 |
27 function Replace(fun, original, patch) { | 46 function Replace(fun, original, patch) { |
28 %ExecuteInDebugContext(function() { | 47 ExecuteInDebugContext(function() { |
29 var change_log = []; | 48 var change_log = []; |
30 try { | 49 try { |
31 var script = Debug.findScript(fun); | 50 var script = Debug.findScript(fun); |
32 var patch_pos = script.source.indexOf(original); | 51 var patch_pos = script.source.indexOf(original); |
33 Debug.LiveEdit.TestApi.ApplySingleChunkPatch( | 52 Debug.LiveEdit.TestApi.ApplySingleChunkPatch( |
34 script, patch_pos, original.length, patch, change_log); | 53 script, patch_pos, original.length, patch, change_log); |
35 } catch (e) { | 54 } catch (e) { |
36 exceptions++; | 55 exceptions++; |
37 } | 56 } |
38 }); | 57 }); |
(...skipping 24 matching lines...) Expand all Loading... |
63 assertEquals(2, wrapper_calls); | 82 assertEquals(2, wrapper_calls); |
64 assertEquals(0, exceptions); // Replace succeeds | 83 assertEquals(0, exceptions); // Replace succeeds |
65 assertEquals([LogNewTarget, LogNewTarget], results); | 84 assertEquals([LogNewTarget, LogNewTarget], results); |
66 | 85 |
67 replace_again = true; | 86 replace_again = true; |
68 Wrapper(); | 87 Wrapper(); |
69 assertEquals(3, construct_calls); | 88 assertEquals(3, construct_calls); |
70 assertEquals(4, wrapper_calls); // Restarts | 89 assertEquals(4, wrapper_calls); // Restarts |
71 assertEquals(0, exceptions); // Replace succeeds | 90 assertEquals(0, exceptions); // Replace succeeds |
72 assertEquals([LogNewTarget, LogNewTarget, LogNewTarget], results); | 91 assertEquals([LogNewTarget, LogNewTarget, LogNewTarget], results); |
OLD | NEW |