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 const Debug = new DebugWrapper(); |
| 6 Debug.enable(); |
| 7 |
| 8 // Tests how debugger can step over not necessarily in the top frame. |
| 9 |
| 10 // Simple 3 functions, that protocol their execution state in global |
| 11 // variable state. |
| 12 var state; |
| 13 |
| 14 function f() { |
| 15 var a = 1978; |
| 16 for (state[2] = 0; state[2] < 3; state[2]++) { |
| 17 void String(a); |
| 18 } |
| 19 } |
| 20 function g() { |
| 21 for (state[1] = 0; state[1] < 3; state[1]++) { |
| 22 f(); |
| 23 } |
| 24 } |
| 25 function h() { |
| 26 state = [-1, -1, -1]; |
| 27 for (state[0] = 0; state[0] < 3; state[0]++) { |
| 28 g(); |
| 29 } |
| 30 } |
| 31 |
| 32 function TestCase(expected_final_state) { |
| 33 var listener_exception = null; |
| 34 var state_snapshot; |
| 35 var listener_state; |
| 36 var bp; |
| 37 |
| 38 function listener(event, exec_state, event_data, data) { |
| 39 const location = exec_state.frames[0].location |
| 40 print("Here (" + event + "/" + listener_state + "): " + |
| 41 location.lineNumber + ":" + location.columnNumber); |
| 42 try { |
| 43 if (event == Debug.DebugEvent.Break) { |
| 44 if (listener_state == 0) { |
| 45 Debug.clearBreakPoint(bp); |
| 46 Debug.stepOver(); |
| 47 listener_state = 1; |
| 48 } else if (listener_state == 1) { |
| 49 state_snapshot = String(state); |
| 50 print("State: " + state_snapshot); |
| 51 Debug.setListener(null); |
| 52 listener_state = 2; |
| 53 } |
| 54 } |
| 55 } catch (e) { |
| 56 listener_exception = e; |
| 57 } |
| 58 } |
| 59 |
| 60 |
| 61 // Add the debug event listener. |
| 62 listener_state = 0; |
| 63 Debug.setListener(listener); |
| 64 bp = Debug.setBreakPoint(f, 1); |
| 65 |
| 66 h(); |
| 67 Debug.setListener(null); |
| 68 if (listener_exception !== null) { |
| 69 print("Exception caught: " + listener_exception); |
| 70 assertUnreachable(); |
| 71 } |
| 72 |
| 73 assertEquals(expected_final_state, state_snapshot); |
| 74 } |
| 75 |
| 76 |
| 77 // Warm-up -- make sure all is compiled and ready for breakpoint. |
| 78 h(); |
| 79 |
| 80 TestCase("0,0,-1"); |
OLD | NEW |