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.

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

mercurial