Debian Codegraph @

js/src/jit-test/tests/debug/Frame-older-generators-02.js

raw
1 // Like Frame-older-generators-01.js, but attach the debugger on the fly.
2 //
3 // (That is, check that it works even if the debugger never received
4 // onNewGenerator for the generator, because it wasn't attached at the time.)
5
6 let g = newGlobal({newCompartment: true});
7 g.eval(`
8 function f() {
9 attach();
10 debugger;
11 }
12 function* gen() {
13 f();
14 yield 1;
15 f();
16 }
17 async function af() {
18 f();
19 await 1;
20 f();
21 }
22 `);
23
24 function test(expected, code) {
25 let dbg;
26 let hits = 0;
27 let genFrame = null;
28
29 g.attach = () => {
30 if (dbg === undefined) {
31 dbg = Debugger(g);
32 dbg.onDebuggerStatement = frame => {
33 hits++;
34 assertEq(frame.callee.name, "f");
35 if (genFrame === null) {
36 genFrame = frame.older;
37 } else {
38 assertEq(frame.older, genFrame);
39 }
40 assertEq(genFrame.callee.name, expected);
41 };
42 }
43 };
44 g.eval(code);
45 assertEq(hits, 2);
46 dbg.removeDebuggee(g);
47 }
48
49 test("gen", "for (var x of gen()) {}");
50 test("af", "af(); drainJobQueue();");