|
1 // Each resumption of a generator gets a fresh frame, whose onPop handler |
|
2 // fires the next time the generator yields. |
|
3 // This is not the behavior the spec requests, but it's what we do for the |
|
4 // moment, and it's good to check that at least we don't crash. |
|
5 var g = newGlobal(); |
|
6 var dbg = new Debugger(g); |
|
7 var log; |
|
8 |
|
9 var debuggerFrames = []; |
|
10 var poppedFrames = []; |
|
11 dbg.onDebuggerStatement = function handleDebugger(frame) { |
|
12 log += 'd'; |
|
13 assertEq(frame.type, "call"); |
|
14 |
|
15 assertEq(debuggerFrames.indexOf(frame), -1); |
|
16 assertEq(poppedFrames.indexOf(frame), -1); |
|
17 debuggerFrames.push(frame); |
|
18 |
|
19 if (frame.eval('i').return % 3 == 0) { |
|
20 frame.onPop = function handlePop(c) { |
|
21 log += ')' + c.return; |
|
22 assertEq(debuggerFrames.indexOf(this) != -1, true); |
|
23 assertEq(poppedFrames.indexOf(this), -1); |
|
24 poppedFrames.push(this); |
|
25 }; |
|
26 } |
|
27 }; |
|
28 |
|
29 g.eval("function g() { for (var i = 0; i < 10; i++) { debugger; yield i; } }"); |
|
30 log =''; |
|
31 assertEq(g.eval("var t = 0; for (j in g()) t += j; t;"), 45); |
|
32 assertEq(log, "d)0ddd)3ddd)6ddd)9"); |