js/src/tests/js1_6/extensions/regress-312385-01.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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 //-----------------------------------------------------------------------------
     7 var BUGNUMBER = 312385;
     8 var summary = 'Generic methods with null or undefined |this|';
     9 var actual = '';
    10 var expect = true;
    11 var voids = [null, undefined];
    14 function noop() { }
    16 var generics = {
    17   String: [{ quote: [] },
    18 { substring: [] },
    19 { toLowerCase: [] },
    20 { toUpperCase: [] },
    21 { charAt: [] },
    22 { charCodeAt: [] },
    23 { indexOf: [] },
    24 { lastIndexOf: [] },
    25 { toLocaleLowerCase: [] },
    26 { toLocaleUpperCase: [] },
    27 { localeCompare: [] },
    28 { match: [/(?:)/] }, // match(regexp)
    29 { search: [] },
    30 { replace: [] },
    31 { split: [] },
    32 { substr: [] },
    33 { concat: [] },
    34 { slice: [] }],
    36   Array:  [{ join: [] },
    37 { reverse: [] },
    38 { sort: [] },
    39            // { push: [0] },  // push(item1, ...)
    40            // { pop: [] },
    41            // { shift: [] },
    42 { unshift: [] },
    43            // { splice: [0, 0, 1] }, // splice(start, deleteCount, item1, ...)
    44 { concat: [] },
    45 { indexOf: [] },
    46 { lastIndexOf: [] },
    47            // forEach is excluded since it does not return a value...
    48            /* { forEach: [noop] },  // forEach(callback, thisObj) */
    49 { map: [noop] },      // map(callback, thisObj)
    50 { filter: [noop] },   // filter(callback, thisObj)
    51 { some: [noop] },     // some(callback, thisObj)
    52 { every: [noop] }     // every(callback, thisObj)
    53     ]
    54 };
    56 printBugNumber(BUGNUMBER);
    57 printStatus (summary);
    59 var global = this;
    61 for (var c in generics)
    62 {
    63   var methods = generics[c];
    64   for (var i = 0; i < methods.length; i++)
    65   {
    66     var method = methods[i];
    68     for (var methodname in method)
    69     {
    70       for (var v = 0; v < voids.length; v++)
    71       {
    72         var Constructor = global[c]
    74         var argsLen = method[methodname].length;
    75         assertEq(argsLen === 0 || argsLen === 1, true, "not all arities handled");
    77         var generic = Constructor[methodname];
    78         var prototypy = Constructor.prototype[methodname];
    80         assertEq(typeof generic, "function");
    81         assertEq(typeof prototypy, "function");
    83         // GENERIC METHOD TESTING
    85         try
    86         {
    87           switch (method[methodname].length)
    88           {
    89             case 0:
    90               generic(voids[v]);
    91               break;
    93             case 1:
    94               generic(voids[v], method[methodname][0]);
    95               break;
    96           }
    97           throw new Error(c + "." + methodname + " must throw for null or " +
    98                           "undefined first argument");
    99         }
   100         catch (e)
   101         {
   102           assertEq(e instanceof TypeError, true,
   103                    "Didn't get a TypeError for " + c + "." + methodname +
   104                    " called with null or undefined first argument");
   105         }
   108         // PROTOTYPE METHOD TESTING
   110         try
   111         {
   112           prototypy.apply(voids[v], method[methodname][0]);
   113           throw new Error(c + ".prototype." + methodname + " must throw " +
   114                           "for null or undefined this");
   115         }
   116         catch (e)
   117         {
   118           assertEq(e instanceof TypeError, true,
   119                    c + ".prototype." + methodname + "didn't throw a " +
   120                    "TypeError when called with null or undefined this");
   121         }
   122       }
   123     }
   124   }
   125 }
   127 if (typeof reportCompare === "function")
   128   reportCompare(true, true);
   130 print("Tests finished.");

mercurial