summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Debugger-getNewestFrame-generators-01.js
blob: 908bd4f2f38e8bf0ff47999e3463f6a17929babd (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
// Generator/async frames can be created and revived by calling Debugger.getNewestFrame().
//
// Modified copy of Frame-older-generators-01.js.

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

function test(expected, code) {
    let dbg = Debugger(g);
    let hits = 0;
    let genFrame = null;
    g.f = () => {
        hits++;
        let frame = dbg.getNewestFrame();
        if (genFrame === null) {
            genFrame = frame;
        } else {
            assertEq(frame, genFrame);
        }
        assertEq(genFrame.callee.name, expected);
    }

    g.eval(code);
    assertEq(hits, 2);
    dbg.removeDebuggee(g);
}

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