optimize-get-iterator-4.js (780B)
1 (() => { 2 let iterablesBase = [ 3 [1,2], 4 [1,2,3], 5 [1,2,3], 6 [3,2,1], 7 ]; 8 9 let iterables = []; 10 for (let i = 0; i < 1000; i++) { 11 iterables.push([...iterablesBase[i % iterablesBase.length]]); 12 } 13 14 iterables.push(new Map([[1, 3], [2,4]]).keys()); 15 16 function testDestructuringInitialization(a) { 17 let [x,y] = a; 18 return y; 19 } 20 21 function testDestructuringAssignment(a) { 22 let x, y; 23 [x,y] = a; 24 return y; 25 } 26 27 for (let i = 0; i < iterables.length; i++) { 28 assertEq(testDestructuringInitialization(iterables[i]), 2); 29 } 30 31 // refresh the last iterator 32 iterables[iterables.length - 1] = new Map([[1, 3], [2,4]]).keys(); 33 for (let i = 0; i < iterables.length; i++) { 34 assertEq(testDestructuringAssignment(iterables[i]), 2); 35 } 36 })();