Sat, 03 Jan 2015 20:18:00 +0100
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 = 885553; |
michael@0 | 8 | var summary = 'Array.prototype.find and Array.prototype.findIndex'; |
michael@0 | 9 | |
michael@0 | 10 | print(BUGNUMBER + ": " + summary); |
michael@0 | 11 | |
michael@0 | 12 | /************** |
michael@0 | 13 | * BEGIN TEST * |
michael@0 | 14 | **************/ |
michael@0 | 15 | |
michael@0 | 16 | function isString(v, index, array) |
michael@0 | 17 | { |
michael@0 | 18 | assertEq(array[index], v); |
michael@0 | 19 | return typeof v == 'string'; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function dumpError(e) |
michael@0 | 23 | { |
michael@0 | 24 | var s = e.name + ': ' + e.message + |
michael@0 | 25 | ' File: ' + e.fileName + |
michael@0 | 26 | ', Line: ' + e.lineNumber + |
michael@0 | 27 | ', Stack: ' + e.stack; |
michael@0 | 28 | return s; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | var expect; |
michael@0 | 32 | var actual; |
michael@0 | 33 | var obj; |
michael@0 | 34 | |
michael@0 | 35 | var strings = ['hello', 'Array', 'WORLD']; |
michael@0 | 36 | var mixed = [0, '1', 2]; |
michael@0 | 37 | var sparsestrings = new Array(); |
michael@0 | 38 | sparsestrings[2] = 'sparse'; |
michael@0 | 39 | var arraylike = {0:0, 1:'string', 2:2, length:3}; |
michael@0 | 40 | // array for which JSObject::isIndexed() holds. |
michael@0 | 41 | var indexedArray = []; |
michael@0 | 42 | Object.defineProperty(indexedArray, 42, { get: function() { return 42; } }); |
michael@0 | 43 | Object.defineProperty(indexedArray, 142, { get: function() { return 'string'; } }); |
michael@0 | 44 | |
michael@0 | 45 | // find and findIndex have 1 required argument |
michael@0 | 46 | |
michael@0 | 47 | expect = 1; |
michael@0 | 48 | actual = Array.prototype.find.length; |
michael@0 | 49 | reportCompare(expect, actual, 'Array.prototype.find.length == 1'); |
michael@0 | 50 | actual = Array.prototype.findIndex.length; |
michael@0 | 51 | reportCompare(expect, actual, 'Array.prototype.findIndex.length == 1'); |
michael@0 | 52 | |
michael@0 | 53 | // throw TypeError if no predicate specified |
michael@0 | 54 | expect = 'TypeError'; |
michael@0 | 55 | try |
michael@0 | 56 | { |
michael@0 | 57 | strings.find(); |
michael@0 | 58 | actual = 'no error'; |
michael@0 | 59 | } |
michael@0 | 60 | catch(e) |
michael@0 | 61 | { |
michael@0 | 62 | actual = e.name; |
michael@0 | 63 | } |
michael@0 | 64 | reportCompare(expect, actual, 'Array.find(undefined) throws TypeError'); |
michael@0 | 65 | try |
michael@0 | 66 | { |
michael@0 | 67 | strings.findIndex(); |
michael@0 | 68 | actual = 'no error'; |
michael@0 | 69 | } |
michael@0 | 70 | catch(e) |
michael@0 | 71 | { |
michael@0 | 72 | actual = e.name; |
michael@0 | 73 | } |
michael@0 | 74 | reportCompare(expect, actual, 'Array.findIndex(undefined) throws TypeError'); |
michael@0 | 75 | |
michael@0 | 76 | // Length gets treated as integer, not uint32 |
michael@0 | 77 | obj = { length: -4294967295, 0: 42 }; |
michael@0 | 78 | expected = undefined; |
michael@0 | 79 | actual = Array.prototype.find.call(obj, () => true); |
michael@0 | 80 | reportCompare(expected, actual, 'find correctly treats "length" as an integer'); |
michael@0 | 81 | expected = -1 |
michael@0 | 82 | actual = Array.prototype.findIndex.call(obj, () => true); |
michael@0 | 83 | reportCompare(expected, actual, 'findIndex correctly treats "length" as an integer'); |
michael@0 | 84 | |
michael@0 | 85 | // test find and findIndex results |
michael@0 | 86 | try |
michael@0 | 87 | { |
michael@0 | 88 | expect = 'hello'; |
michael@0 | 89 | actual = strings.find(isString); |
michael@0 | 90 | } |
michael@0 | 91 | catch(e) |
michael@0 | 92 | { |
michael@0 | 93 | actual = dumpError(e); |
michael@0 | 94 | } |
michael@0 | 95 | reportCompare(expect, actual, 'strings: find finds first string element'); |
michael@0 | 96 | |
michael@0 | 97 | try |
michael@0 | 98 | { |
michael@0 | 99 | expect = 0; |
michael@0 | 100 | actual = strings.findIndex(isString); |
michael@0 | 101 | } |
michael@0 | 102 | catch(e) |
michael@0 | 103 | { |
michael@0 | 104 | actual = dumpError(e); |
michael@0 | 105 | } |
michael@0 | 106 | reportCompare(expect, actual, 'strings: findIndex finds first string element'); |
michael@0 | 107 | |
michael@0 | 108 | try |
michael@0 | 109 | { |
michael@0 | 110 | expect = '1'; |
michael@0 | 111 | actual = mixed.find(isString); |
michael@0 | 112 | } |
michael@0 | 113 | catch(e) |
michael@0 | 114 | { |
michael@0 | 115 | actual = dumpError(e); |
michael@0 | 116 | } |
michael@0 | 117 | reportCompare(expect, actual, 'mixed: find finds first string element'); |
michael@0 | 118 | |
michael@0 | 119 | try |
michael@0 | 120 | { |
michael@0 | 121 | expect = 1; |
michael@0 | 122 | actual = mixed.findIndex(isString); |
michael@0 | 123 | } |
michael@0 | 124 | catch(e) |
michael@0 | 125 | { |
michael@0 | 126 | actual = dumpError(e); |
michael@0 | 127 | } |
michael@0 | 128 | reportCompare(expect, actual, 'mixed: findIndex finds first string element'); |
michael@0 | 129 | |
michael@0 | 130 | try |
michael@0 | 131 | { |
michael@0 | 132 | expect = 'sparse'; |
michael@0 | 133 | actual = sparsestrings.find(isString); |
michael@0 | 134 | } |
michael@0 | 135 | catch(e) |
michael@0 | 136 | { |
michael@0 | 137 | actual = dumpError(e); |
michael@0 | 138 | } |
michael@0 | 139 | reportCompare(expect, actual, 'sparsestrings: find finds first string element'); |
michael@0 | 140 | |
michael@0 | 141 | try |
michael@0 | 142 | { |
michael@0 | 143 | expect = 2; |
michael@0 | 144 | actual = sparsestrings.findIndex(isString); |
michael@0 | 145 | } |
michael@0 | 146 | catch(e) |
michael@0 | 147 | { |
michael@0 | 148 | actual = dumpError(e); |
michael@0 | 149 | } |
michael@0 | 150 | reportCompare(expect, actual, 'sparsestrings: findIndex finds first string element'); |
michael@0 | 151 | |
michael@0 | 152 | try |
michael@0 | 153 | { |
michael@0 | 154 | expect = 'string'; |
michael@0 | 155 | actual = [].find.call(arraylike, isString); |
michael@0 | 156 | } |
michael@0 | 157 | catch(e) |
michael@0 | 158 | { |
michael@0 | 159 | actual = dumpError(e); |
michael@0 | 160 | } |
michael@0 | 161 | reportCompare(expect, actual, 'arraylike: find finds first string element'); |
michael@0 | 162 | |
michael@0 | 163 | try |
michael@0 | 164 | { |
michael@0 | 165 | expect = 1; |
michael@0 | 166 | actual = [].findIndex.call(arraylike, isString); |
michael@0 | 167 | } |
michael@0 | 168 | catch(e) |
michael@0 | 169 | { |
michael@0 | 170 | actual = dumpError(e); |
michael@0 | 171 | } |
michael@0 | 172 | reportCompare(expect, actual, 'arraylike: findIndex finds first string element'); |
michael@0 | 173 | |
michael@0 | 174 | try |
michael@0 | 175 | { |
michael@0 | 176 | expect = 1; |
michael@0 | 177 | actual = 0; |
michael@0 | 178 | Array.prototype.find.call({get 0(){ actual++ }, length: 1}, ()=>true); |
michael@0 | 179 | } |
michael@0 | 180 | catch(e) |
michael@0 | 181 | { |
michael@0 | 182 | actual = dumpError(e); |
michael@0 | 183 | } |
michael@0 | 184 | reportCompare(expect, actual, 'arraylike with getter: getter only called once'); |
michael@0 | 185 | |
michael@0 | 186 | try |
michael@0 | 187 | { |
michael@0 | 188 | expect = 'string'; |
michael@0 | 189 | actual = [].find.call(indexedArray, isString); |
michael@0 | 190 | } |
michael@0 | 191 | catch(e) |
michael@0 | 192 | { |
michael@0 | 193 | actual = dumpError(e); |
michael@0 | 194 | } |
michael@0 | 195 | reportCompare(expect, actual, 'indexedArray: find finds first string element'); |
michael@0 | 196 | |
michael@0 | 197 | try |
michael@0 | 198 | { |
michael@0 | 199 | expect = 142; |
michael@0 | 200 | actual = [].findIndex.call(indexedArray, isString); |
michael@0 | 201 | } |
michael@0 | 202 | catch(e) |
michael@0 | 203 | { |
michael@0 | 204 | actual = dumpError(e); |
michael@0 | 205 | } |
michael@0 | 206 | reportCompare(expect, actual, 'indexedArray: findIndex finds first string element'); |