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 each yield* loop just checks "done", and "value" is only |
michael@0 | 2 | // fetched once at the end. |
michael@0 | 3 | |
michael@0 | 4 | var log = ""; |
michael@0 | 5 | |
michael@0 | 6 | function collect_results(iter) { |
michael@0 | 7 | var ret = []; |
michael@0 | 8 | var result; |
michael@0 | 9 | do { |
michael@0 | 10 | result = iter.next(); |
michael@0 | 11 | ret.push(result); |
michael@0 | 12 | } while (!result.done); |
michael@0 | 13 | return ret; |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | function Iter(val, count) { |
michael@0 | 17 | function next() { |
michael@0 | 18 | log += 'n'; |
michael@0 | 19 | return { |
michael@0 | 20 | get done() { log += "d"; return count-- == 0; }, |
michael@0 | 21 | get value() { log += "v"; return val; } |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function iterator() { |
michael@0 | 26 | log += 'i'; |
michael@0 | 27 | return this; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | this.next = next; |
michael@0 | 31 | this[std_iterator] = iterator; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function* delegate(iter) { return yield* iter; } |
michael@0 | 35 | |
michael@0 | 36 | var inner = new Iter(42, 5); |
michael@0 | 37 | var outer = delegate(inner); |
michael@0 | 38 | |
michael@0 | 39 | // Five values, and one terminal value. |
michael@0 | 40 | outer.next(); |
michael@0 | 41 | outer.next(); |
michael@0 | 42 | outer.next(); |
michael@0 | 43 | outer.next(); |
michael@0 | 44 | outer.next(); |
michael@0 | 45 | outer.next(); |
michael@0 | 46 | |
michael@0 | 47 | assertEq(log, "indndndndndndv"); |
michael@0 | 48 | |
michael@0 | 49 | // Outer's dead, man. Outer's dead. |
michael@0 | 50 | assertDeepEq(outer.next(), {value: undefined, done: true}); |
michael@0 | 51 | |
michael@0 | 52 | // No more checking the iterator. |
michael@0 | 53 | assertEq(log, "indndndndndndv"); |
michael@0 | 54 | |
michael@0 | 55 | if (typeof reportCompare == "function") |
michael@0 | 56 | reportCompare(true, true); |