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 // Flags: --expose-debug-as debug | 5 // Flags: --expose-debug-as debug |
6 | 6 |
7 function f() { | 7 function f() { |
8 for (var i = 10; i < 14; i++) { // 1 | 8 for (var i = 10; i < 14; i++) { // 1 |
9 i; // 2 | 9 i; // 2 |
10 } | 10 } |
11 } // 3 | 11 } // 3 |
12 | 12 |
13 var state = "conditional"; | 13 var state = "conditional"; |
14 var log = []; | 14 var log = []; |
15 var exception = null; | 15 var exception = null; |
16 | 16 |
17 function listener(event, exec_state, event_data, data) { | 17 function listener(event, exec_state, event_data, data) { |
18 if (event != Debug.DebugEvent.Break) return; | 18 if (event != Debug.DebugEvent.Break) return; |
19 try { | 19 try { |
20 var label = +exec_state.frame(0).sourceLineText().substr(-1); | 20 var label = +exec_state.frame(0).sourceLineText().substr(-1); |
21 log.push(label); | 21 log.push(label); |
22 if (label == 2) log.push(exec_state.frame(0).evaluate("i").value()); | 22 if (label == 2) log.push(exec_state.frame(0).evaluate("i").value()); |
23 exec_state.prepareStep(Debug.StepAction.StepNext, 1); | 23 exec_state.prepareStep(Debug.StepAction.StepNext); |
24 } catch (e) { | 24 } catch (e) { |
25 exception = e; | 25 exception = e; |
26 print("Caught something. " + e + " " + e.stack); | 26 print("Caught something. " + e + " " + e.stack); |
27 }; | 27 }; |
28 }; | 28 }; |
29 | 29 |
30 | 30 |
31 var Debug = debug.Debug; | 31 var Debug = debug.Debug; |
32 Debug.setListener(listener); | 32 Debug.setListener(listener); |
33 | 33 |
34 Debug.setBreakPoint(f, 2, 0, "i == 12"); | 34 Debug.setBreakPoint(f, 2, 0, "i == 12"); |
35 | 35 |
36 f(); | 36 f(); |
37 | 37 |
38 Debug.setListener(null); // 4 | 38 Debug.setListener(null); // 4 |
39 | 39 |
40 assertEquals([2,12,1,1,2,13,1,1,3,4], log); | 40 assertEquals([2,12,1,1,2,13,1,1,3,4], log); |
41 assertNull(exception); | 41 assertNull(exception); |
OLD | NEW |