summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/onDebuggerStatement-async-generator-resumption-01.js
blob: 20a9ecf9646f125d2d0d14cc610a8dc661831d0e (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
51
52
53
54
55
56
57
58
59
60
// A Debugger can {return:} from onDebuggerStatement in an async generator.
// A resolved promise for a {value: _, done: true} object is returned.

load(libdir + "asserts.js");

let g = newGlobal({newCompartment: true});
g.eval(`
    async function* f(x) {
        debugger;  // when==0 to force return here
        await x;
        yield 1;
        debugger;  // when==1 to force return here
    }
`);

let exc = null;
let dbg = new Debugger;
let gw = dbg.addDebuggee(g);
function test(when) {
    let hits = 0;
    let outcome = "FAIL";
    dbg.onDebuggerStatement = frame => {
        if (hits++ == when)
            return {return: "ponies"};
    };

    let iter = g.f(0);

    // At the initial suspend.
    assertEq(hits, 0);
    iter.next().then(result => {
        // At the yield point, unless we already force-returned from the first
        // debugger statement.
        assertEq(hits, 1);
        if (when == 0)
            return result;
        assertEq(result.value, 1);
        assertEq(result.done, false);
        return iter.next();
    }).then(result => {
        // After forced return.
        assertEq(hits, when + 1);
        assertEq(result.value, "ponies");
        assertEq(result.done, true);
        outcome = "pass";
    }).catch(e => {
        // An assertion failed.
        exc = e;
    });

    assertEq(hits, 1);
    drainJobQueue();
    if (exc !== null)
        throw exc;
    assertEq(outcome, "pass");
}

for (let i = 0; i < 2; i++) {
    test(i);
}