summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/onEnterFrame-async-resumption-02.js
blob: 15986741be05975bc612eb237b83d94775c10eeb (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
// A Debugger can {throw:} from onEnterFrame in an async function.
// The resulting promise (if any) is rejected with the thrown error value.

load(libdir + "asserts.js");

let g = newGlobal({newCompartment: true});
g.eval(`
    async function f() { await 1; }
    var err = new TypeError("object too hairy");
`);

let dbg = new Debugger;
let gw = dbg.addDebuggee(g);
let errw = gw.makeDebuggeeValue(g.err);

// Repeat the test for each onEnterFrame event.
// It fires up to two times:
// - when the async function g.f is called;
// - when we resume after the await to run to the end.
for (let when = 0; when < 2; when++) {
    let hits = 0;
    dbg.onEnterFrame = frame => {
        return hits++ < when ? undefined : {throw: errw};
    };

    let result = undefined;
    g.f()
        .then(value => { result = {returned: value}; })
        .catch(err => { result = {threw: err}; });

    drainJobQueue();

    assertEq(hits, when + 1);
    assertDeepEq(result, {threw: g.err});
}