js/src/jit-test/tests/basic/spread-call-funapply.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 load(libdir + "asserts.js");
     2 load(libdir + "eqArrayHelper.js");
     3 load(libdir + "iteration.js");
     5 function checkCommon(f) {
     6   assertEqArray(f.apply(null, ...[[1, 2, 3]]), [1, 2, 3]);
     7   assertEqArray(f.apply(...[null], [1, 2, 3]), [1, 2, 3]);
     8   assertEqArray(f.apply(...[null], ...[[1, 2, 3]]), [1, 2, 3]);
     9   assertEqArray(f.apply(...[null, [1, 2, 3]]), [1, 2, 3]);
    11   // other iterable objects
    12   assertEqArray(f.apply(...Set([null, [1, 2, 3]])), [1, 2, 3]);
    13   assertEqArray(f.apply(...[null, [1, 2, 3]][std_iterator]()), [1, 2, 3]);
    14   let itr = {};
    15   itr[std_iterator] = function() {
    16       return {
    17           i: 0,
    18           next: function() {
    19               this.i++;
    20               if (this.i == 1)
    21                   return { value: null, done: false };
    22               else if (this.i == 2)
    23                   return { value: [1, 2, 3], done: false };
    24               else
    25                   return { value: undefined, done: true };
    26           }
    27       };
    28   };
    29   assertEqArray(f.apply(...itr), [1, 2, 3]);
    30   function* gen() {
    31       yield null;
    32       yield [1, 2, 3];
    33   }
    34   assertEqArray(f.apply(...gen()), [1, 2, 3]);
    36   let a;
    37   assertEqArray(f.apply(null, ...a=[[1, 2, 3]]), [1, 2, 3]);
    39   // According to the draft spec, null and undefined are to be treated as empty
    40   // arrays. However, they are not iterable. If the spec is not changed to be in
    41   // terms of iterables, these tests should be fixed.
    42   //assertEqArray(f.apply(null, ...null, [1, 2, 3]), [1, 2, 3]);
    43   //assertEqArray(f.apply(null, ...undefined, [1, 2, 3]), [1, 2, 3]);
    44   assertThrowsInstanceOf(() => f.apply(null, ...null, [1, 2, 3]), TypeError);
    45   assertThrowsInstanceOf(() => f.apply(null, ...undefined, [1, 2, 3]), TypeError);
    46 }
    48 function checkNormal(f) {
    49   checkCommon(f);
    51   assertEqArray(f.apply(null, ...[[]]), [undefined, undefined, undefined]);
    52   assertEqArray(f.apply(null, ...[[1]]), [1, undefined, undefined]);
    53   assertEqArray(f.apply(null, ...[[1, 2]]), [1, 2, undefined]);
    54   assertEqArray(f.apply(null, ...[[1, 2, 3, 4]]), [1, 2, 3]);
    56   assertEqArray(f.apply(null, ...[[undefined]]), [undefined, undefined, undefined]);
    57 }
    59 checkNormal(function(a, b, c) [a, b, c]);
    60 checkNormal((a, b, c) => [a, b, c]);
    62 function checkDefault(f) {
    63   checkCommon(f);
    65   assertEqArray(f.apply(null, ...[[]]), [-1, -2, -3]);
    66   assertEqArray(f.apply(null, ...[[1]]), [1, -2, -3]);
    67   assertEqArray(f.apply(null, ...[[1, 2]]), [1, 2, -3]);
    68   assertEqArray(f.apply(null, ...[[1, 2, 3, 4]]), [1, 2, 3]);
    70   assertEqArray(f.apply(null, ...[[undefined]]), [-1, -2, -3]);
    71 }
    73 checkDefault(function(a = -1, b = -2, c = -3) [a, b, c]);
    74 checkDefault((a = -1, b = -2, c = -3) => [a, b, c]);
    76 function checkRest(f) {
    77   checkCommon(f);
    79   assertEqArray(f.apply(null, ...[[]]), []);
    80   assertEqArray(f.apply(null, ...[[1]]), [1]);
    81   assertEqArray(f.apply(null, ...[[1, 2]]), [1, 2]);
    82   assertEqArray(f.apply(null, ...[[1, 2, 3, 4]]), [1, 2, 3, 4]);
    84   assertEqArray(f.apply(null, ...[[undefined]]), [undefined]);
    86   // other iterable objects
    87   assertEqArray(f.apply(null, ...Map([[["a", "A"], ["b", "B"]]])).map(([k, v]) => k + v), ["aA", "bB"]);
    88 }
    90 checkRest(function(...x) x);
    91 checkRest((...x) => x);

mercurial