tor-browser

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

call-generic-args.js (798B)


      1 // Test that the generic call trampoline passes arguments correctly.
      2 
      3 function foo(f) {
      4  return f(1);
      5 }
      6 
      7 with ({}) {}
      8 
      9 function f1() { return arguments; }
     10 function f2(x) { return [x]; }
     11 function f3(x,y) { return [x,y]; }
     12 function f4(x,y,z) { return [x,y,z]; }
     13 
     14 let f5 = f4.bind({});
     15 let f6 = f4.bind({}, 2);
     16 let f7 = f4.bind({}, 2, 3);
     17 
     18 function assertArrayEq(a,b) {
     19  assertEq(a.length, b.length);
     20  for (var i = 0; i < a.length; i++) {
     21    assertEq(a[i], b[i]);
     22  }
     23 }
     24 
     25 for (var i = 0; i < 500; i++) {
     26  assertArrayEq(foo(f1), [1]);
     27  assertArrayEq(foo(f2), [1]);
     28  assertArrayEq(foo(f3), [1, undefined]);
     29  assertArrayEq(foo(f4), [1, undefined, undefined]);
     30  assertArrayEq(foo(f5), [1, undefined, undefined]);
     31  assertArrayEq(foo(f6), [2, 1, undefined]);
     32  assertArrayEq(foo(f7), [2, 3, 1]);
     33 }