summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/generators/delegating-yield-9.js
blob: 60c35b94d7a4d7119fa3b4672dfb4590b9f27bf0 (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
// Test that yield* can appear in a loop, and inside yield.

function* countdown(n) {
    while (n > 0) {
        yield (yield* countdown(--n));
    }
    return 34;
}

function collect_results(iter) {
    var ret = [];
    var result;
    do {
        result = iter.next();
        ret.push(result);
    } while (!result.done);
    return ret;
}

var expected = [
    // Only 34 yielded from the "yield" and the last return make it out.
    // Three yields in countdown(3), two in countdown(2), and one in
    // countdown(1) (called twice).
    {value: 34, done: false},
    {value: 34, done: false},
    {value: 34, done: false},
    {value: 34, done: false},
    {value: 34, done: false},
    {value: 34, done: false},
    {value: 34, done: false},
    {value: 34, done: true}, // final
];

assertDeepEq(collect_results(countdown(3)), expected);

if (typeof reportCompare == "function")
    reportCompare(true, true);