js/src/tests/ecma_6/Generators/delegating-yield-12.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 // yield* calls @@iterator on the iterable to produce the iterator.
michael@0 2
michael@0 3 var log = '';
michael@0 4
michael@0 5 function IteratorWrapper(iterator) {
michael@0 6 return {
michael@0 7 next: function (val) {
michael@0 8 log += 'n';
michael@0 9 return iterator.next(val);
michael@0 10 },
michael@0 11
michael@0 12 throw: function (exn) {
michael@0 13 log += 't';
michael@0 14 return iterator.throw(exn);
michael@0 15 }
michael@0 16 };
michael@0 17 }
michael@0 18
michael@0 19 function IterableWrapper(iterable) {
michael@0 20 var ret = {};
michael@0 21
michael@0 22 ret[std_iterator] = function () {
michael@0 23 log += 'i';
michael@0 24 return IteratorWrapper(iterable[std_iterator]());
michael@0 25 }
michael@0 26
michael@0 27 return ret;
michael@0 28 }
michael@0 29
michael@0 30 function* delegate(iter) { return yield* iter; }
michael@0 31
michael@0 32 var iter = delegate(IterableWrapper([1, 2, 3]));
michael@0 33 assertIteratorNext(iter, 1);
michael@0 34 assertIteratorNext(iter, 2);
michael@0 35 assertIteratorNext(iter, 3);
michael@0 36 assertIteratorDone(iter, undefined);
michael@0 37
michael@0 38 assertEq(log, 'innnn');
michael@0 39
michael@0 40 iter = delegate([1, 2, 3]);
michael@0 41 assertIteratorNext(iter, 1);
michael@0 42 assertIteratorNext(iter, 2);
michael@0 43 assertIteratorNext(iter, 3);
michael@0 44 assertIteratorDone(iter, undefined);
michael@0 45
michael@0 46 assertEq(log, 'innnn');
michael@0 47
michael@0 48 if (typeof reportCompare == "function")
michael@0 49 reportCompare(true, true);

mercurial