summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Frame-older-generators-02.js
blob: f677bf64a8235864d47c363f9e52fd9c26d65e49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Like Frame-older-generators-01.js, but attach the debugger on the fly.
//
// (That is, check that it works even if the debugger never received
// onNewGenerator for the generator, because it wasn't attached at the time.)

let g = newGlobal({newCompartment: true});
g.eval(`
    function f() {
        attach();
        debugger;
    }
    function* gen() {
        f();
        yield 1;
        f();
    }
    async function af() {
        f();
        await 1;
        f();
    }
`);

function test(expected, code) {
    let dbg;
    let hits = 0;
    let genFrame = null;

    g.attach = () => {
        if (dbg === undefined) {
            dbg = Debugger(g);
            dbg.onDebuggerStatement = frame => {
                hits++;
                assertEq(frame.callee.name, "f");
                if (genFrame === null) {
                    genFrame = frame.older;
                } else {
                    assertEq(frame.older, genFrame);
                }
                assertEq(genFrame.callee.name, expected);
            };
        }
    };
    g.eval(code);
    assertEq(hits, 2);
    dbg.removeDebuggee(g);
}

test("gen", "for (var x of gen()) {}");
test("af", "af(); drainJobQueue();");