summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/onDebuggerStatement-generator-resumption-01.js
blob: c4e1ade96e822bb91c9197ab59a1493bb1d00220 (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
// A Debugger can {return:} from onDebuggerStatement in a generator.

load(libdir + "asserts.js");

let g = newGlobal({newCompartment: true});
g.eval(`
    function* f1() {
        debugger;
        yield 1;
    }

    function* f2() {
        yield 1;
        debugger;
        yield 2;
    }
`);

let dbg = Debugger(g);
dbg.onDebuggerStatement = frame => ({return: "Ronja"});

let genObj = g.f1();
assertDeepEq(genObj.next(), {value: "Ronja", done: true});
// Forced return closes the generator. Closed generators behave like this:
assertDeepEq(genObj.next(), {value: undefined, done: true});

// It works the same after resuming from a yield.
genObj = g.f2();
assertDeepEq(genObj.next(), {value: 1, done: false});
assertDeepEq(genObj.next(), {value: "Ronja", done: true});
assertDeepEq(genObj.next(), {value: undefined, done: true});  // closed