OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --expose-debug-as debug --allow-natives-syntax |
| 6 |
| 7 // Test that live-editing a frame above one that uses new.target succeeds. |
| 8 |
| 9 Debug = debug.Debug |
| 10 var wrapper_calls = 0; |
| 11 var construct_calls = 0; |
| 12 var exceptions = 0; |
| 13 var results = []; |
| 14 var replace_again; |
| 15 |
| 16 eval(` |
| 17 function LogNewTarget(arg) { |
| 18 construct_calls++; |
| 19 results.push(new.target); |
| 20 } |
| 21 function Wrapper() { |
| 22 wrapper_calls++; |
| 23 ReplaceOnce(); |
| 24 new LogNewTarget(true); |
| 25 } |
| 26 `); |
| 27 |
| 28 function Replace(fun, original, patch) { |
| 29 %ExecuteInDebugContext(function() { |
| 30 var change_log = []; |
| 31 try { |
| 32 var script = Debug.findScript(fun); |
| 33 var patch_pos = script.source.indexOf(original); |
| 34 Debug.LiveEdit.TestApi.ApplySingleChunkPatch( |
| 35 script, patch_pos, original.length, patch, change_log); |
| 36 } catch (e) { |
| 37 exceptions++; |
| 38 } |
| 39 }); |
| 40 } |
| 41 |
| 42 function ReplaceOnce(x) { |
| 43 if (replace_again) { |
| 44 replace_again = false; |
| 45 Replace(Wrapper, "true", "false"); |
| 46 } |
| 47 } |
| 48 |
| 49 function Revert() { |
| 50 Replace(Wrapper, "false", "true"); |
| 51 } |
| 52 |
| 53 replace_again = true; |
| 54 ReplaceOnce(); |
| 55 Wrapper(); |
| 56 Revert(); |
| 57 assertEquals(1, construct_calls); |
| 58 assertEquals(1, wrapper_calls); |
| 59 assertEquals(0, exceptions); // Replace succeeds |
| 60 assertEquals([LogNewTarget], results); |
| 61 |
| 62 Wrapper(); |
| 63 assertEquals(2, construct_calls); |
| 64 assertEquals(2, wrapper_calls); |
| 65 assertEquals(0, exceptions); // Replace succeeds |
| 66 assertEquals([LogNewTarget, LogNewTarget], results); |
| 67 |
| 68 replace_again = true; |
| 69 Wrapper(); |
| 70 assertEquals(3, construct_calls); |
| 71 assertEquals(4, wrapper_calls); // Restarts |
| 72 assertEquals(0, exceptions); // Replace succeeds |
| 73 assertEquals([LogNewTarget, LogNewTarget, LogNewTarget], results); |
OLD | NEW |