arguments-object-load-length.js (1464B)
1 // Test transpiling of LoadArgumentsObjectLengthResult and cover all possible bailout conditions. 2 3 function blackhole() { 4 // Direct eval prevents any compile-time optimisations. 5 eval(""); 6 } 7 8 function testLengthAccess() { 9 blackhole(arguments); // Create an arguments object. 10 11 for (var i = 0; i < 50; ++i) { 12 assertEq(arguments.length, 1); 13 } 14 } 15 for (var i = 0; i < 20; ++i) testLengthAccess(1); 16 17 function markLengthOveriddenIf(args, cond, value) { 18 with ({}) ; // Don't Warp compile to avoid cold code bailouts. 19 if (cond) { 20 args.length = value; 21 } 22 } 23 24 function testBailoutLengthReified() { 25 blackhole(arguments); // Create an arguments object. 26 27 for (var i = 0; i < 50; ++i) { 28 markLengthOveriddenIf(arguments, i === 25, 0); 29 30 var expected = 0 + (i < 25); 31 assertEq(arguments.length, expected); 32 } 33 } 34 for (var i = 0; i < 20; ++i) testBailoutLengthReified(1); 35 36 37 function deleteLengthIf(args, cond) { 38 with ({}) ; // Don't Warp compile to avoid cold code bailouts. 39 if (cond) { 40 delete args.length; 41 } 42 } 43 44 function testBailoutLengthDeleted() { 45 blackhole(arguments); // Create an arguments object. 46 47 // Load expected values from an array to avoid possible cold code bailouts. 48 var values = [1, undefined]; 49 50 for (var i = 0; i < 50; ++i) { 51 deleteLengthIf(arguments, i === 25); 52 53 var expected = values[0 + (i >= 25)]; 54 assertEq(arguments.length, expected); 55 } 56 } 57 for (var i = 0; i < 20; ++i) testBailoutLengthDeleted(1);