Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Test that yield* can appear in a loop, and inside yield. |
michael@0 | 2 | |
michael@0 | 3 | function* countdown(n) { |
michael@0 | 4 | while (n > 0) { |
michael@0 | 5 | yield (yield* countdown(--n)); |
michael@0 | 6 | } |
michael@0 | 7 | return 34; |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function collect_results(iter) { |
michael@0 | 11 | var ret = []; |
michael@0 | 12 | var result; |
michael@0 | 13 | do { |
michael@0 | 14 | result = iter.next(); |
michael@0 | 15 | ret.push(result); |
michael@0 | 16 | } while (!result.done); |
michael@0 | 17 | return ret; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | var expected = [ |
michael@0 | 21 | // Only 34 yielded from the "yield" and the last return make it out. |
michael@0 | 22 | // Three yields in countdown(3), two in countdown(2), and one in |
michael@0 | 23 | // countdown(1) (called twice). |
michael@0 | 24 | {value: 34, done: false}, |
michael@0 | 25 | {value: 34, done: false}, |
michael@0 | 26 | {value: 34, done: false}, |
michael@0 | 27 | {value: 34, done: false}, |
michael@0 | 28 | {value: 34, done: false}, |
michael@0 | 29 | {value: 34, done: false}, |
michael@0 | 30 | {value: 34, done: false}, |
michael@0 | 31 | {value: 34, done: true}, // final |
michael@0 | 32 | ]; |
michael@0 | 33 | |
michael@0 | 34 | assertDeepEq(collect_results(countdown(3)), expected); |
michael@0 | 35 | |
michael@0 | 36 | if (typeof reportCompare == "function") |
michael@0 | 37 | reportCompare(true, true); |