OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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 Debug = new DebugWrapper(); | 5 Debug = debug.Debug |
6 Debug.enable(); | |
7 | 6 |
8 // Simple debug event handler which performs 100 steps and then retrieves | 7 // Simple debug event handler which first time hit will perform 1000 steps and |
9 // the resulting value of "i" in f(). | 8 // second time hit will evaluate and store the value of "i". If requires that |
| 9 // the global property "state" is initially zero. |
| 10 |
| 11 var bp1, bp2; |
10 | 12 |
11 function listener(event, exec_state, event_data, data) { | 13 function listener(event, exec_state, event_data, data) { |
12 if (event == Debug.DebugEvent.Break) { | 14 if (event == Debug.DebugEvent.Break) { |
13 if (step_count > 0) { | 15 if (step_count > 0) { |
14 Debug.stepInto(); | 16 exec_state.prepareStep(Debug.StepAction.StepIn); |
15 step_count--; | 17 step_count--; |
16 } else { | 18 } else { |
17 const frameid = exec_state.frames[0].callFrameId; | 19 result = exec_state.frame().evaluate("i").value(); |
18 result = Debug.evaluate(frameid, "i").value; | 20 // Clear the break point on line 2 if set. |
| 21 if (bp2) { |
| 22 Debug.clearBreakPoint(bp2); |
| 23 } |
19 } | 24 } |
20 } | 25 } |
21 }; | 26 }; |
22 | 27 |
23 // Add the debug event listener. | 28 // Add the debug event listener. |
24 Debug.setListener(listener); | 29 Debug.setListener(listener); |
25 | 30 |
26 // Test debug event for break point. | 31 // Test debug event for break point. |
27 function f() { | 32 function f() { |
28 var i; // Line 1. | 33 var i; // Line 1. |
29 for (i = 0; i < 100; i++) { // Line 2. | 34 for (i = 0; i < 1000; i++) { // Line 2. |
30 x = 1; // Line 3. | 35 x = 1; // Line 3. |
31 } | 36 } |
32 }; | 37 }; |
33 | 38 |
34 // Set a breakpoint on the for statement (line 1). | 39 // Set a breakpoint on the for statement (line 1). |
35 Debug.setBreakPoint(f, 1); | 40 bp1 = Debug.setBreakPoint(f, 1); |
36 | 41 |
37 // Check that performing 100 steps will make i 33. | 42 // Check that performing 1000 steps will make i 333. |
38 let step_count = 100; | 43 var step_count = 1000; |
39 let result = -1; | 44 result = -1; |
40 | |
41 f(); | 45 f(); |
42 | 46 assertEquals(333, result); |
43 assertEquals(33, result); | 47 Debug.setListener(null); |
OLD | NEW |