inlinable-native-accessor-1.js (2529B)
1 // Test calling an inlinable native accessor property as a normal function. 2 3 // Set.prototype.size is an inlinable getter accessor. 4 var SetSize = Object.getOwnPropertyDescriptor(Set.prototype, "size").get; 5 6 // Install "size" getter as a normal method on Set.prototype. 7 Set.prototype.getSize = SetSize; 8 9 var sets = [ 10 new Set(), 11 new Set([1, 2, 3]), 12 ]; 13 14 // Call inlinable accessor as normal method. 15 function testInlinableAccessorAsMethod() { 16 for (var i = 0; i < 100; ++i) { 17 var set = sets[i & 1]; 18 assertEq(set.getSize(), set.size); 19 } 20 } 21 testInlinableAccessorAsMethod(); 22 23 // Call inlinable accessor as through FunCall. 24 function testInlinableAccessorWithFunCall() { 25 for (var i = 0; i < 100; ++i) { 26 var set = sets[i & 1]; 27 assertEq(SetSize.call(set), set.size); 28 } 29 } 30 testInlinableAccessorWithFunCall(); 31 32 // Call inlinable accessor as through FunApply. 33 function testInlinableAccessorWithFunApply() { 34 for (var i = 0; i < 100; ++i) { 35 var set = sets[i & 1]; 36 assertEq(SetSize.apply(set), set.size); 37 } 38 } 39 testInlinableAccessorWithFunApply(); 40 41 // Call inlinable accessor as through bound FunCall. 42 function testInlinableAccessorWithBoundFunCall() { 43 var callSetSize = Function.prototype.call.bind(SetSize); 44 45 for (var i = 0; i < 100; ++i) { 46 var set = sets[i & 1]; 47 assertEq(callSetSize(set), set.size); 48 } 49 } 50 testInlinableAccessorWithBoundFunCall(); 51 52 // Call inlinable accessor as through bound FunCall. 53 function testInlinableAccessorWithBoundFunApply() { 54 var applySetSize = Function.prototype.apply.bind(SetSize); 55 56 for (var i = 0; i < 100; ++i) { 57 var set = sets[i & 1]; 58 assertEq(applySetSize(set), set.size); 59 } 60 } 61 testInlinableAccessorWithBoundFunApply(); 62 63 // Call inlinable accessor as bound function. 64 function testBoundInlinableAccessor() { 65 var boundSetSize = SetSize.bind(sets[0]); 66 67 for (var i = 0; i < 100; ++i) { 68 assertEq(boundSetSize(), sets[0].size); 69 } 70 } 71 testBoundInlinableAccessor(); 72 73 // Call inlinable accessor as bound function through FunCall. 74 function testBoundInlinableAccessorWithFunCall() { 75 var boundSetSize = SetSize.bind(sets[0]); 76 77 for (var i = 0; i < 100; ++i) { 78 assertEq(boundSetSize.call(), sets[0].size); 79 } 80 } 81 testBoundInlinableAccessorWithFunCall(); 82 83 // Call inlinable accessor as bound function through FunApply. 84 function testBoundInlinableAccessorWithFunApply() { 85 var boundSetSize = SetSize.bind(sets[0]); 86 87 for (var i = 0; i < 100; ++i) { 88 assertEq(boundSetSize.apply(), sets[0].size); 89 } 90 } 91 testInlinableAccessorWithBoundFunApply();