spreadcall-not-optimized-dynamic-4a.js (1282B)
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 arguments don't share a common prototype. 18 function test() { 19 class MyArray1 extends Array { } 20 class MyArray2 extends Array { } 21 function maybeInvalidate(rest) { 22 // Use a WithStatement to prevent Ion-inlining. This ensures any 23 // bailouts due to type changes don't occur in this function, but 24 // instead in the caller. 25 with ({}); 26 27 if (i >= 1900) { 28 if (i & 1) 29 rest = new MyArray1(3, 4); 30 else 31 rest = new MyArray2(5, 6); 32 } 33 return rest; 34 } 35 function fn(...rest) { 36 rest = maybeInvalidate(rest); 37 return add(...rest); 38 } 39 for (var i = 0; i < 4000; ++i) { 40 assertEq(fn(1, 2), i < 1900 ? 3 : (i & 1) ? 7 : 11); 41 } 42 } 43 test();