fun-apply-as-call-native-2.js (1264B)
1 // Function.prototype.apply is inlined as Function.prototype.call when it's 2 // called with less than two arguments. 3 // 4 // Test polymorphic calls. 5 6 function testThisAbsent() { 7 let xs = [Math.min, Math.max]; 8 let ys = [Infinity, -Infinity]; 9 for (let i = 0; i < 200; ++i) { 10 let r = xs[i & 1].apply(); 11 assertEq(r, ys[i & 1]); 12 } 13 } 14 for (let i = 0; i < 2; ++i) testThisAbsent(); 15 16 function test0() { 17 let xs = [Math.min, Math.max]; 18 let ys = [Infinity, -Infinity]; 19 for (let i = 0; i < 200; ++i) { 20 let r = xs[i & 1].apply(null); 21 assertEq(r, ys[i & 1]); 22 } 23 } 24 for (let i = 0; i < 2; ++i) test0(); 25 26 // NOTE: We don't yet inline the case when the second argument is |null|. 27 function test1Null() { 28 let xs = [Math.min, Math.max]; 29 let ys = [Infinity, -Infinity]; 30 for (let i = 0; i < 200; ++i) { 31 let r = xs[i & 1].apply(null, null); 32 assertEq(r, ys[i & 1]); 33 } 34 } 35 for (let i = 0; i < 2; ++i) test1Null(); 36 37 // NOTE: We don't yet inline the case when the second argument is |undefined|. 38 function test1Undefined() { 39 let xs = [Math.min, Math.max]; 40 let ys = [Infinity, -Infinity]; 41 for (let i = 0; i < 200; ++i) { 42 let r = xs[i & 1].apply(null, undefined); 43 assertEq(r, ys[i & 1]); 44 } 45 } 46 for (let i = 0; i < 2; ++i) test1Undefined();