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