apply-native-arguments-object.js (932B)
1 load(libdir + "array-compare.js"); 2 3 const xs = [ 4 // Zero arguments. 5 [], 6 7 // Single argument. 8 [1], 9 10 // Few arguments. Even number of arguments. 11 [1, 2], 12 13 // Few arguments. Odd number of arguments. 14 [1, 2, 3], 15 16 // Many arguments. Even number of arguments. 17 [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 18 19 // Many arguments. Odd number of arguments. 20 [1, 2, 3, 4, 5, 6, 7, 8, 9], 21 ]; 22 23 function escape() { 24 with ({}) ; 25 } 26 27 function f() { 28 // Let |arguments| escape to force the allocation of an arguments object. 29 escape(arguments); 30 31 // FunApply to a native function with an arguments object. 32 return Array.apply(null, arguments); 33 } 34 35 // Don't inline |f| into the top-level script. 36 with ({}) ; 37 38 for (let i = 0; i < 400; ++i) { 39 let x = xs[i % xs.length]; 40 41 // NB: Array(1) creates the array `[,]`. 42 let expected = x.length !== 1 ? x : [,]; 43 44 let result = f.apply(null, x); 45 assertEq(arraysEqual(result, expected), true); 46 }