js/src/tests/ecma_6/Generators/delegating-yield-5.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 a deep yield* chain re-yields received results without
michael@0 2 // re-boxing.
michael@0 3
michael@0 4 function results(results) {
michael@0 5 var i = 0;
michael@0 6 function next() {
michael@0 7 return results[i++];
michael@0 8 }
michael@0 9 var iter = { next: next };
michael@0 10 var ret = {};
michael@0 11 ret[std_iterator] = function () { return iter; }
michael@0 12 return ret;
michael@0 13 }
michael@0 14
michael@0 15 function* yield_results(expected, n) {
michael@0 16 return yield* n ? yield_results(expected, n - 1) : results(expected);
michael@0 17 }
michael@0 18
michael@0 19 function collect_results(iterable) {
michael@0 20 var ret = [];
michael@0 21 var result;
michael@0 22 var iter = iterable[std_iterator]();
michael@0 23 do {
michael@0 24 result = iter.next();
michael@0 25 ret.push(result);
michael@0 26 } while (!result.done);
michael@0 27 return ret;
michael@0 28 }
michael@0 29
michael@0 30 // We have to put a full result for the end, because the return will re-box.
michael@0 31 var expected = [{value: 1}, 13, "foo", {value: 34, done: true}];
michael@0 32
michael@0 33 assertDeepEq(expected, collect_results(results(expected)));
michael@0 34 assertDeepEq(expected, collect_results(yield_results(expected, 20)));
michael@0 35
michael@0 36 if (typeof reportCompare == "function")
michael@0 37 reportCompare(true, true);

mercurial