OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 var Debug = debug.Debug; | 7 var Debug = debug.Debug; |
8 | 8 |
9 function assertIteratorResult(value, done, result) { | 9 function assertIteratorResult(value, done, result) { |
10 assertEquals({value: value, done: done}, result); | 10 assertEquals({value: value, done: done}, result); |
11 } | 11 } |
12 | 12 |
13 function RunTest(formals_and_body, args, value1, value2) { | 13 function RunTest(formals_and_body, args, value1, value2) { |
14 // A null listener. It isn't important what the listener does. | 14 // A null listener. It isn't important what the listener does. |
15 function listener(event, exec_state, event_data, data) { | 15 function listener(event, exec_state, event_data, data) { |
16 } | 16 } |
17 | 17 |
18 // Create the generator function outside a debugging context. It will probably | 18 // Create the generator function outside a debugging context. It will probably |
19 // be lazily compiled. | 19 // be lazily compiled. |
20 var gen = (function*(){}).constructor.apply(null, formals_and_body); | 20 var gen = (function*(){}).constructor.apply(null, formals_and_body); |
21 | 21 |
22 // Instantiate the generator object. | 22 // Instantiate the generator object. |
23 var obj = gen.apply(null, args); | 23 var obj = gen.apply(null, args); |
24 | 24 |
25 // Advance to the first yield. | 25 // Advance to the first yield. |
26 assertIteratorResult(value1, false, obj.next()); | 26 assertIteratorResult(value1, false, obj.next()); |
27 | 27 |
28 // Add a breakpoint on line 3 (the second yield). | |
29 var bp = Debug.setBreakPoint(gen, 3); | |
30 | |
31 // Enable the debugger, which should force recompilation of the generator | 28 // Enable the debugger, which should force recompilation of the generator |
32 // function and relocation of the suspended generator activation. | 29 // function and relocation of the suspended generator activation. |
33 Debug.setListener(listener); | 30 Debug.setListener(listener); |
34 | 31 |
| 32 // Add a breakpoint on line 3 (the second yield). |
| 33 var bp = Debug.setBreakPoint(gen, 3); |
| 34 |
35 // Check that the generator resumes and suspends properly. | 35 // Check that the generator resumes and suspends properly. |
36 assertIteratorResult(value2, false, obj.next()); | 36 assertIteratorResult(value2, false, obj.next()); |
37 | 37 |
38 // Disable debugger -- should not force recompilation. | 38 // Disable debugger -- should not force recompilation. |
39 Debug.clearBreakPoint(bp); | 39 Debug.clearBreakPoint(bp); |
40 Debug.setListener(null); | 40 Debug.setListener(null); |
41 | 41 |
42 // Run to completion. | 42 // Run to completion. |
43 assertIteratorResult(undefined, true, obj.next()); | 43 assertIteratorResult(undefined, true, obj.next()); |
44 } | 44 } |
45 | 45 |
46 function prog(a, b, c) { | 46 function prog(a, b, c) { |
47 return a + ';\n' + 'yield ' + b + ';\n' + 'yield ' + c; | 47 return a + ';\n' + 'yield ' + b + ';\n' + 'yield ' + c; |
48 } | 48 } |
49 | 49 |
50 // Simple empty local scope. | 50 // Simple empty local scope. |
51 RunTest([prog('', '1', '2')], [], 1, 2); | 51 RunTest([prog('', '1', '2')], [], 1, 2); |
52 | 52 |
53 RunTest([prog('for (;;) break', '1', '2')], [], 1, 2); | 53 RunTest([prog('for (;;) break', '1', '2')], [], 1, 2); |
54 | 54 |
55 RunTest([prog('while (0) foo()', '1', '2')], [], 1, 2); | 55 RunTest([prog('while (0) foo()', '1', '2')], [], 1, 2); |
56 | 56 |
57 RunTest(['a', prog('var x = 3', 'a', 'x')], [1], 1, 3); | 57 RunTest(['a', prog('var x = 3', 'a', 'x')], [1], 1, 3); |
58 | 58 |
59 RunTest(['a', prog('', '1', '2')], [42], 1, 2); | 59 RunTest(['a', prog('', '1', '2')], [42], 1, 2); |
60 | 60 |
61 RunTest(['a', prog('for (;;) break', '1', '2')], [42], 1, 2); | 61 RunTest(['a', prog('for (;;) break', '1', '2')], [42], 1, 2); |
OLD | NEW |