summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Frame-onStep-generator-resumption-03.js
blob: 3b2e8d2b3a65b477d905c73fddaa3aec930257a3 (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
// Don't crash on {return:} from onStep in a generator, before the initial suspend.

// This test tries to force-return from each bytecode instruction in a
// generator, up to the initial suspend.

load(libdir + "asserts.js");

let g = newGlobal({newCompartment: true});
g.values = [1, 2, 3];
g.eval(`function* f(arr=values) { yield* arr; }`);

let dbg = Debugger(g);

function test(ttl) {
    let hits = 0;
    dbg.onEnterFrame = frame => {
        assertEq(frame.callee.name, "f");
        frame.onStep = () => {
            if (--ttl === 0)
                return {return: 123};
        };
    };
    dbg.uncaughtExceptionHook = exc => {
      return {throw: "debugger error: " + exc};
    };

    let val = undefined;
    let caught = undefined;
    try {
        val = g.f();
    } catch (exc) {
        caught = exc;
    }

    if (val === undefined) {
        // Tried to force-return before the initial suspend.
        assertEq(caught, "debugger error: TypeError: can't force return from a generator before the initial yield");
        assertEq(ttl, 0);
        return "pass";
    } else {
        // Reached the initial suspend without forcing a return.
        assertEq(typeof val, "object");
        assertEq(val instanceof g.f, true);
        assertEq(ttl, 1);
        return "done";
    }
}

for (let i = 1; test(i) === "pass"; i++) {}