scalar-replace-array-construct-array.js (1236B)
1 // |jit-test| --fast-warmup; --no-threads 2 3 setJitCompilerOption("baseline.warmup.trigger", 0); 4 setJitCompilerOption("ion.warmup.trigger", 100); 5 6 // Prevent GC from cancelling/discarding Ion compilations. 7 gczeal(0); 8 9 // Create a fresh set of functions for each argument count to avoid type pollution. 10 function makeTest(count) { 11 var args = Array(count).fill(0).join(","); 12 13 return Function(` 14 class Base { 15 constructor() { 16 this.count = arguments.length; 17 } 18 } 19 20 class C extends Base { 21 constructor(...args) { 22 // When |C| is inlined into its caller, the number of arguments is fixed and 23 // we can scalar replace the inlined rest array. 24 assertRecoveredOnBailout(args, true); 25 return super(...args); 26 } 27 } 28 29 // |C| must be small enough to be inlined into the test function. 30 assertEq(isSmallFunction(C), true); 31 32 function test() { 33 for (let i = 0; i < 1000; ++i) { 34 let obj = new C(${args}); 35 assertEq(obj.count, ${count}); 36 } 37 } 38 39 return test; 40 `)(); 41 } 42 43 // Limited by gc::CanUseFixedElementsForArray(), see also WarpBuilder::build_Rest(). 44 const maxRestArgs = 14; 45 46 for (let i = 0; i <= maxRestArgs; ++i) { 47 makeTest(i)(); 48 }