OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax --expose-debug-as debug |
| 6 |
| 7 var Debug = debug.Debug; |
| 8 |
| 9 var changed = false; |
| 10 |
| 11 function listenerSetJToResult( |
| 12 event, exec_state, event_data, data) { |
| 13 |
| 14 if (event == Debug.DebugEvent.Break) { |
| 15 var scope = exec_state.frame(1).scope(0); |
| 16 var newval = "result"; |
| 17 try { |
| 18 scope.setVariableValue("j", newval); |
| 19 changed = true; |
| 20 } catch(e) { |
| 21 changed = false; |
| 22 } |
| 23 } |
| 24 } |
| 25 |
| 26 Debug.setListener(listenerSetJToResult); |
| 27 |
| 28 function g() { debugger; } |
| 29 %NeverOptimizeFunction(g); |
| 30 |
| 31 function ChangeSmiConstantAndOsr() { |
| 32 var j = 1; |
| 33 for (var i = 0; i < 4; i++) { |
| 34 if (i == 2) { |
| 35 %OptimizeOsr(); |
| 36 g(); |
| 37 } |
| 38 } |
| 39 return j; |
| 40 } |
| 41 var r1 = ChangeSmiConstantAndOsr(); |
| 42 if (changed) { |
| 43 assertEquals("result", r1); |
| 44 } else { |
| 45 assertEquals(1, r1); |
| 46 } |
| 47 |
| 48 function ChangeFloatConstantAndOsr() { |
| 49 var j = 0.1; |
| 50 for (var i = 0; i < 4; i++) { |
| 51 if (i == 2) { |
| 52 %OptimizeOsr(); |
| 53 g(); |
| 54 } |
| 55 } |
| 56 return j; |
| 57 } |
| 58 var r2 = ChangeFloatConstantAndOsr(); |
| 59 if (changed) { |
| 60 assertEquals("result", r2); |
| 61 } else { |
| 62 assertEquals(0.1, r2); |
| 63 } |
| 64 |
| 65 function ChangeFloatVarAndOsr() { |
| 66 var j = 0.1; |
| 67 for (var i = 0; i < 4; i++) { |
| 68 j = j + 0.1; |
| 69 if (i == 2) { |
| 70 %OptimizeOsr(); |
| 71 g(); |
| 72 } |
| 73 } |
| 74 return j; |
| 75 } |
| 76 var r3 = ChangeFloatVarAndOsr(); |
| 77 if (changed) { |
| 78 assertEquals("result0.1", r3); |
| 79 } else { |
| 80 assertEquals(0.5, r3); |
| 81 } |
| 82 |
| 83 var counter = 0; |
| 84 var o = { toString : function() { counter++; return 100; } }; |
| 85 |
| 86 function listenerSetJToObject( |
| 87 event, exec_state, event_data, data) { |
| 88 if (event == Debug.DebugEvent.Break) { |
| 89 var scope = exec_state.frame(1).scope(0); |
| 90 try { |
| 91 scope.setVariableValue("j", o); |
| 92 changed = true; |
| 93 } catch(e) { |
| 94 changed = false; |
| 95 } |
| 96 } |
| 97 } |
| 98 |
| 99 Debug.setListener(listenerSetJToObject); |
| 100 |
| 101 function ChangeIntVarAndOsr() { |
| 102 var j = 1; |
| 103 for (var i = 0; i < 4; i++) { |
| 104 j = j + 1|0; |
| 105 if (i == 2) { |
| 106 %OptimizeOsr(); |
| 107 g(); |
| 108 } |
| 109 } |
| 110 return j; |
| 111 } |
| 112 |
| 113 var r4 = ChangeIntVarAndOsr(); |
| 114 if (changed) { |
| 115 assertEquals(101, r4); |
| 116 assertEquals(1, counter); |
| 117 } else { |
| 118 assertEquals(5, r4); |
| 119 } |
OLD | NEW |