tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

apply-native-spreadcall-arguments.js (786B)


      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 f() {
     24  // SpreadCall to a native function with frame arguments.
     25  return Array(...arguments);
     26 }
     27 
     28 // Don't inline |f| into the top-level script.
     29 with ({}) ;
     30 
     31 for (let i = 0; i < 400; ++i) {
     32  let x = xs[i % xs.length];
     33 
     34  // NB: Array(1) creates the array `[,]`.
     35  let expected = x.length !== 1 ? x : [,];
     36 
     37  let result = f.apply(null, x);
     38  assertEq(arraysEqual(result, expected), true);
     39 }