tor-browser

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

argumentsList-many.js (1412B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/licenses/publicdomain/ */
      3 
      4 // SKIP test262 export
      5 // Testing unspecified implementation limits.
      6 
      7 // Tests for the argumentList argument to Reflect.apply and Reflect.construct.
      8 // Many arguments can be passed.
      9 var many = 65537;
     10 var args = {length: many, 0: "zero", [many - 1]: "last"};
     11 function testMany(...args) {
     12    for (var i = 0; i < many; i++) {
     13        assertEq(i in args, true);
     14        assertEq(args[i], i === 0 ? "zero" : i === many - 1 ? "last" : undefined);
     15    }
     16    return this;
     17 }
     18 assertEq(Reflect.apply(testMany, "pass", args).toString(), "pass");
     19 assertEq(Reflect.construct(testMany, args) instanceof testMany, true);
     20 assertEq(Reflect.apply(new Proxy(testMany, {}), "pass", args).toString(), "pass");
     21 assertEq(Reflect.construct(new Proxy(testMany, {}), args) instanceof testMany, true);
     22 
     23 // If argumentsList.length is unreasonably huge, we get an error.
     24 // (This is an implementation limit.)
     25 var BOTH = [
     26    Reflect.apply,
     27    // Adapt Reflect.construct to accept the same arguments as Reflect.apply.
     28    (target, thisArgument, argumentList) => Reflect.construct(target, argumentList)
     29 ];
     30 
     31 for (var method of BOTH) {
     32    for (var value of [1e12, 1e240, Infinity]) {
     33        assertThrowsInstanceOf(() => method(count, undefined, {length: value}),
     34                               Error);
     35    }
     36 }
     37 
     38 reportCompare(0, 0);