fun-apply-as-call-scripted-2.js (1160B)
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 one() { 7 return 1; 8 } 9 10 function two() { 11 return 2; 12 } 13 14 function testThisAbsent() { 15 let xs = [one, two]; 16 for (let i = 0; i < 200; ++i) { 17 let r = xs[i & 1].apply(); 18 assertEq(r, 1 + (i & 1)); 19 } 20 } 21 for (let i = 0; i < 2; ++i) testThisAbsent(); 22 23 function test0() { 24 let xs = [one, two]; 25 for (let i = 0; i < 200; ++i) { 26 let r = xs[i & 1].apply(null); 27 assertEq(r, 1 + (i & 1)); 28 } 29 } 30 for (let i = 0; i < 2; ++i) test0(); 31 32 // NOTE: We don't yet inline the case when the second argument is |null|. 33 function test1Null() { 34 let xs = [one, two]; 35 for (let i = 0; i < 200; ++i) { 36 let r = xs[i & 1].apply(null, null); 37 assertEq(r, 1 + (i & 1)); 38 } 39 } 40 for (let i = 0; i < 2; ++i) test1Null(); 41 42 // NOTE: We don't yet inline the case when the second argument is |undefined|. 43 function test1Undefined() { 44 let xs = [one, two]; 45 for (let i = 0; i < 200; ++i) { 46 let r = xs[i & 1].apply(null, undefined); 47 assertEq(r, 1 + (i & 1)); 48 } 49 } 50 for (let i = 0; i < 2; ++i) test1Undefined();