spreadcall-not-optimized-dynamic-3.js (1154B)
1 // Tests when JSOP_OPTIMIZE_SPREADCALL no longer apply after the initial Ion 2 // compilation. 3 4 // JSOP_OPTIMIZE_SPREADCALL can be optimised when the following conditions 5 // are fulfilled: 6 // (1) the argument is an array 7 // (2) the array has no hole 8 // (3) array[@@iterator] is not modified 9 // (4) the array's prototype is Array.prototype 10 // (5) Array.prototype[@@iterator] is not modified 11 // (6) %ArrayIteratorPrototype%.next is not modified 12 13 function add(a, b) { 14 return a + b; 15 } 16 17 // The rest argument has an own @@iterator property. 18 function test() { 19 function MyIter() { 20 return [3, 4][Symbol.iterator](); 21 } 22 function maybeInvalidate(rest) { 23 // Use a WithStatement to prevent Ion-inlining. This ensures any 24 // bailouts due to type changes don't occur in this function, but 25 // instead in the caller. 26 with ({}); 27 28 if (i >= 1900) { 29 rest[Symbol.iterator] = MyIter; 30 } 31 } 32 function fn(...rest) { 33 maybeInvalidate(rest); 34 return add(...rest); 35 } 36 for (var i = 0; i < 4000; ++i) { 37 assertEq(fn(1, 2), i < 1900 ? 3 : 7); 38 } 39 } 40 test();