summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/onEnterFrame-async-resumption-07.js
blob: 578d93ff9904c644d416ca9107eed2c56023c303 (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
61
62
// A Debugger can't force-return from the first onEnterFrame for an async generator.

ignoreUnhandledRejections();

let g = newGlobal({newCompartment: true});
g.eval(`async function* f(x) { await x; return "ponies"; }`);

let dbg = new Debugger;
dbg.uncaughtExceptionHook = exc => {}; // ignore errors
let gw = dbg.addDebuggee(g);
let hits = 0;
let resumption = undefined;

dbg.onEnterFrame = frame => {
    dbg.onEnterFrame = undefined;
    assertEq(frame.type, "call");
    assertEq(frame.callee.name, "f");
    frame.onPop = completion => {
        hits++;
    };

    // Try to force-return. It's too early. This results in a call to the
    // uncaughtExceptionHook but is otherwise ignored.
    return {return: "rainbows"};
};
let it = g.f(0);    // onPop #1: the initial yield
assertEq(hits, 1);
let p = it.next();  // onPop #2: await x
assertEq(hits, 2);
drainJobQueue();    // onPop #3: return "ponies", #4: the final yield
assertEq(hits, 4);

let pw = gw.makeDebuggeeValue(p);
assertEq(pw.isPromise, true);
assertEq(pw.promiseState, "fulfilled");
assertEq(pw.promiseValue.getProperty("value").return, "ponies");
assertEq(pw.promiseValue.getProperty("done").return, true);

// ----

g.eval(`async function* f2(x) { await x; return "moar ponies"; }`);

let savedAsyncGen = undefined;
dbg.onEnterFrame = frame => {
    dbg.onEnterFrame = undefined;
    assertEq(frame.type, "call");
    assertEq(frame.callee.name, "f2");
    frame.onPop = completion => {
        if (savedAsyncGen === undefined) {
            savedAsyncGen = completion.return;
        }
    };
};
let it2 = g.f2(123);
let p2 = it2.next();
drainJobQueue();

let pw2 = gw.makeDebuggeeValue(p2);
assertEq(pw2.isPromise, true);
assertEq(pw2.promiseState, "fulfilled");
assertEq(pw2.promiseValue.getProperty("value").return, "moar ponies");
assertEq(pw2.promiseValue.getProperty("done").return, true);