summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/generators/delegating-yield-12.js
blob: 9ed7666e11de1f603e6147e656aa0340a2cb093d (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
// yield* calls @@iterator on the iterable to produce the iterator.

var log = '';

function IteratorWrapper(iterator) {
    return {
        next: function (val) {
            log += 'n';
            return iterator.next(val);
        },

        throw: function (exn) {
            log += 't';
            return iterator.throw(exn);
        }
    };
}

function IterableWrapper(iterable) {
    var ret = {};

    ret[Symbol.iterator] = function () {
        log += 'i';
        return IteratorWrapper(iterable[Symbol.iterator]());
    }

    return ret;
}

function* delegate(iter) { return yield* iter; }

var iter = delegate(IterableWrapper([1, 2, 3]));
assertIteratorNext(iter, 1);
assertIteratorNext(iter, 2);
assertIteratorNext(iter, 3);
assertIteratorDone(iter, undefined);

assertEq(log, 'innnn');

iter = delegate([1, 2, 3]);
assertIteratorNext(iter, 1);
assertIteratorNext(iter, 2);
assertIteratorNext(iter, 3);
assertIteratorDone(iter, undefined);

assertEq(log, 'innnn');

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