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 | // 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); |