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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 // The iteratee of yield* can be a proxy.
michael@0 2
michael@0 3 function results(results) {
michael@0 4 var i = 0;
michael@0 5 function iterator() {
michael@0 6 return this;
michael@0 7 }
michael@0 8 function next() {
michael@0 9 return results[i++];
michael@0 10 }
michael@0 11 var ret = { next: next }
michael@0 12 ret[std_iterator] = iterator;
michael@0 13 return ret;
michael@0 14 }
michael@0 15
michael@0 16 function* yield_results(expected) {
michael@0 17 return yield* Proxy(results(expected), {});
michael@0 18 }
michael@0 19
michael@0 20 function collect_results(iter) {
michael@0 21 var ret = [];
michael@0 22 var result;
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 // Sanity check.
michael@0 34 assertDeepEq(expected, collect_results(results(expected)));
michael@0 35 assertDeepEq(expected, collect_results(yield_results(expected)));
michael@0 36
michael@0 37 if (typeof reportCompare == "function")
michael@0 38 reportCompare(true, true);

mercurial