sbarati@apple.com | 99ed479 | 2016-11-12 02:58:11 +0000 | [diff] [blame] | 1 | function assert(b) { |
| 2 | if (!b) |
| 3 | throw new Error("Bad assertion."); |
| 4 | } |
| 5 | function foo(m) { |
| 6 | return [...m]; |
| 7 | } |
| 8 | noInline(foo); |
| 9 | |
| 10 | let map = new Map; |
| 11 | map.set(20, 30); |
| 12 | map.set(40, 50); |
| 13 | |
| 14 | let called = 0; |
| 15 | let customIterator = { |
| 16 | [Symbol.iterator]: function() { |
| 17 | called++; |
| 18 | let count = 0; |
| 19 | return { |
| 20 | next() { |
| 21 | called++; |
| 22 | count++; |
| 23 | if (count === 1) |
| 24 | return {done: false, value: [20, 30]}; |
| 25 | if (count === 2) |
| 26 | return {done: false, value: [40, 50]}; |
| 27 | return {done: true}; |
| 28 | } |
| 29 | }; |
| 30 | } |
| 31 | }; |
| 32 | for (let i = 0; i < 10000; i++) { |
| 33 | for (let o of [customIterator, map]) { |
| 34 | let [[a, b], [c, d]] = foo(o); |
| 35 | assert(a === 20); |
| 36 | assert(b === 30); |
| 37 | assert(c === 40); |
| 38 | assert(d === 50); |
| 39 | } |
| 40 | assert(called === 4); |
| 41 | called = 0; |
| 42 | } |
| 43 | |
| 44 | function bar(m) { |
| 45 | return [...m, ...m]; |
| 46 | } |
| 47 | noInline(bar); |
| 48 | for (let i = 0; i < 10000; i++) { |
| 49 | for (let o of [customIterator, map]) { |
| 50 | let [[a, b], [c, d], [e, f], [g, h]] = bar(o); |
| 51 | assert(a === 20); |
| 52 | assert(b === 30); |
| 53 | assert(c === 40); |
| 54 | assert(d === 50); |
| 55 | assert(e === 20); |
| 56 | assert(f === 30); |
| 57 | assert(g === 40); |
| 58 | assert(h === 50); |
| 59 | } |
| 60 | assert(called === 8); |
| 61 | called = 0; |
| 62 | } |