summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Frame-onStep-generators-03.js
blob: b9f6f5e5fd0ae774a03d22ae7cea5d9c104f4b5a (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
// Stepping into the `.throw()` method of a generator with a relevant catch block.

load(libdir + "asserts.js");

let g = newGlobal({newCompartment: true});
g.eval(`\
function* z() {         // line 1
    try {               // 2
        yield 1;        // 3
    } catch (exc) {     // 4
        yield 2;        // 5
    }                   // 6
}                       // 7
function f() {          // 8
    let gen = z();      // 9
    gen.next();         // 10
    gen.throw("fit");   // 11
}                       // 12
`);

let log = [];
let previousLine = -1;
let dbg = new Debugger(g);
dbg.onEnterFrame = frame => {
    log.push(frame.callee.name + " in");
    frame.onStep = () => {
        let line = frame.script.getOffsetLocation(frame.offset).lineNumber;
        if (previousLine != line) { // We stepped to a new line.
            log.push(line);
            previousLine = line;
        }
    };
    frame.onPop = completion => {
        log.push(frame.callee.name + " out");
    };
};

g.f();
assertEq(
    log.join(", "),
    "f in, 8, 9, z in, 1, z out, " +
    "9, 10, z in, 1, 2, 3, z out, " +
    "10, 11, z in, 3, 2, 4, 5, z out, " +  // not sure why we hit line 2 here, source notes bug maybe
    "11, 12, f out"
);