michael@0: // Test that yield* can appear in a loop, and inside yield. michael@0: michael@0: function* countdown(n) { michael@0: while (n > 0) { michael@0: yield (yield* countdown(--n)); michael@0: } michael@0: return 34; michael@0: } michael@0: michael@0: function collect_results(iter) { michael@0: var ret = []; michael@0: var result; michael@0: do { michael@0: result = iter.next(); michael@0: ret.push(result); michael@0: } while (!result.done); michael@0: return ret; michael@0: } michael@0: michael@0: var expected = [ michael@0: // Only 34 yielded from the "yield" and the last return make it out. michael@0: // Three yields in countdown(3), two in countdown(2), and one in michael@0: // countdown(1) (called twice). michael@0: {value: 34, done: false}, michael@0: {value: 34, done: false}, michael@0: {value: 34, done: false}, michael@0: {value: 34, done: false}, michael@0: {value: 34, done: false}, michael@0: {value: 34, done: false}, michael@0: {value: 34, done: false}, michael@0: {value: 34, done: true}, // final michael@0: ]; michael@0: michael@0: assertDeepEq(collect_results(countdown(3)), expected); michael@0: michael@0: if (typeof reportCompare == "function") michael@0: reportCompare(true, true);