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 | * |
michael@0 | 8 | * Date: 25 Mar 2002 |
michael@0 | 9 | * SUMMARY: Array.prototype.sort() should not (re-)define .length |
michael@0 | 10 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=130451 |
michael@0 | 11 | * |
michael@0 | 12 | * From the ECMA-262 Edition 3 Final spec: |
michael@0 | 13 | * |
michael@0 | 14 | * NOTE: The sort function is intentionally generic; it does not require that |
michael@0 | 15 | * its |this| value be an Array object. Therefore, it can be transferred to |
michael@0 | 16 | * other kinds of objects for use as a method. Whether the sort function can |
michael@0 | 17 | * be applied successfully to a host object is implementation-dependent. |
michael@0 | 18 | * |
michael@0 | 19 | * The interesting parts of this testcase are the contrasting expectations for |
michael@0 | 20 | * Brendan's test below, when applied to Array objects vs. non-Array objects. |
michael@0 | 21 | * |
michael@0 | 22 | */ |
michael@0 | 23 | //----------------------------------------------------------------------------- |
michael@0 | 24 | var UBound = 0; |
michael@0 | 25 | var BUGNUMBER = 130451; |
michael@0 | 26 | var summary = 'Array.prototype.sort() should not (re-)define .length'; |
michael@0 | 27 | var status = ''; |
michael@0 | 28 | var statusitems = []; |
michael@0 | 29 | var actual = ''; |
michael@0 | 30 | var actualvalues = []; |
michael@0 | 31 | var expect= ''; |
michael@0 | 32 | var expectedvalues = []; |
michael@0 | 33 | var arr = []; |
michael@0 | 34 | var cmp = new Function(); |
michael@0 | 35 | |
michael@0 | 36 | |
michael@0 | 37 | /* |
michael@0 | 38 | * First: test Array.prototype.sort() on Array objects |
michael@0 | 39 | */ |
michael@0 | 40 | status = inSection(1); |
michael@0 | 41 | arr = [0,1,2,3]; |
michael@0 | 42 | cmp = function(x,y) {return x-y;}; |
michael@0 | 43 | actual = arr.sort(cmp).length; |
michael@0 | 44 | expect = 4; |
michael@0 | 45 | addThis(); |
michael@0 | 46 | |
michael@0 | 47 | status = inSection(2); |
michael@0 | 48 | arr = [0,1,2,3]; |
michael@0 | 49 | cmp = function(x,y) {return y-x;}; |
michael@0 | 50 | actual = arr.sort(cmp).length; |
michael@0 | 51 | expect = 4; |
michael@0 | 52 | addThis(); |
michael@0 | 53 | |
michael@0 | 54 | status = inSection(3); |
michael@0 | 55 | arr = [0,1,2,3]; |
michael@0 | 56 | cmp = function(x,y) {return x-y;}; |
michael@0 | 57 | arr.length = 1; |
michael@0 | 58 | actual = arr.sort(cmp).length; |
michael@0 | 59 | expect = 1; |
michael@0 | 60 | addThis(); |
michael@0 | 61 | |
michael@0 | 62 | /* |
michael@0 | 63 | * This test is by Brendan. Setting arr.length to |
michael@0 | 64 | * 2 and then 4 should cause elements to be deleted. |
michael@0 | 65 | */ |
michael@0 | 66 | arr = [0,1,2,3]; |
michael@0 | 67 | cmp = function(x,y) {return x-y;}; |
michael@0 | 68 | arr.sort(cmp); |
michael@0 | 69 | |
michael@0 | 70 | status = inSection(4); |
michael@0 | 71 | actual = arr.join(); |
michael@0 | 72 | expect = '0,1,2,3'; |
michael@0 | 73 | addThis(); |
michael@0 | 74 | |
michael@0 | 75 | status = inSection(5); |
michael@0 | 76 | actual = arr.length; |
michael@0 | 77 | expect = 4; |
michael@0 | 78 | addThis(); |
michael@0 | 79 | |
michael@0 | 80 | status = inSection(6); |
michael@0 | 81 | arr.length = 2; |
michael@0 | 82 | actual = arr.join(); |
michael@0 | 83 | expect = '0,1'; |
michael@0 | 84 | addThis(); |
michael@0 | 85 | |
michael@0 | 86 | status = inSection(7); |
michael@0 | 87 | arr.length = 4; |
michael@0 | 88 | actual = arr.join(); |
michael@0 | 89 | expect = '0,1,,'; //<---- see how 2,3 have been lost |
michael@0 | 90 | addThis(); |
michael@0 | 91 | |
michael@0 | 92 | |
michael@0 | 93 | |
michael@0 | 94 | /* |
michael@0 | 95 | * Now test Array.prototype.sort() on non-Array objects |
michael@0 | 96 | */ |
michael@0 | 97 | status = inSection(8); |
michael@0 | 98 | var obj = new Object(); |
michael@0 | 99 | obj.sort = Array.prototype.sort; |
michael@0 | 100 | obj.length = 4; |
michael@0 | 101 | obj[0] = 0; |
michael@0 | 102 | obj[1] = 1; |
michael@0 | 103 | obj[2] = 2; |
michael@0 | 104 | obj[3] = 3; |
michael@0 | 105 | cmp = function(x,y) {return x-y;}; |
michael@0 | 106 | actual = obj.sort(cmp).length; |
michael@0 | 107 | expect = 4; |
michael@0 | 108 | addThis(); |
michael@0 | 109 | |
michael@0 | 110 | |
michael@0 | 111 | /* |
michael@0 | 112 | * Here again is Brendan's test. Unlike the array case |
michael@0 | 113 | * above, the setting of obj.length to 2 and then 4 |
michael@0 | 114 | * should NOT cause elements to be deleted |
michael@0 | 115 | */ |
michael@0 | 116 | obj = new Object(); |
michael@0 | 117 | obj.sort = Array.prototype.sort; |
michael@0 | 118 | obj.length = 4; |
michael@0 | 119 | obj[0] = 3; |
michael@0 | 120 | obj[1] = 2; |
michael@0 | 121 | obj[2] = 1; |
michael@0 | 122 | obj[3] = 0; |
michael@0 | 123 | cmp = function(x,y) {return x-y;}; |
michael@0 | 124 | obj.sort(cmp); //<---- this is what triggered the buggy behavior below |
michael@0 | 125 | obj.join = Array.prototype.join; |
michael@0 | 126 | |
michael@0 | 127 | status = inSection(9); |
michael@0 | 128 | actual = obj.join(); |
michael@0 | 129 | expect = '0,1,2,3'; |
michael@0 | 130 | addThis(); |
michael@0 | 131 | |
michael@0 | 132 | status = inSection(10); |
michael@0 | 133 | actual = obj.length; |
michael@0 | 134 | expect = 4; |
michael@0 | 135 | addThis(); |
michael@0 | 136 | |
michael@0 | 137 | status = inSection(11); |
michael@0 | 138 | obj.length = 2; |
michael@0 | 139 | actual = obj.join(); |
michael@0 | 140 | expect = '0,1'; |
michael@0 | 141 | addThis(); |
michael@0 | 142 | |
michael@0 | 143 | /* |
michael@0 | 144 | * Before this bug was fixed, |actual| held the value '0,1,,' |
michael@0 | 145 | * as in the Array-object case at top. This bug only occurred |
michael@0 | 146 | * if Array.prototype.sort() had been applied to |obj|, |
michael@0 | 147 | * as we have done higher up. |
michael@0 | 148 | */ |
michael@0 | 149 | status = inSection(12); |
michael@0 | 150 | obj.length = 4; |
michael@0 | 151 | actual = obj.join(); |
michael@0 | 152 | expect = '0,1,2,3'; |
michael@0 | 153 | addThis(); |
michael@0 | 154 | |
michael@0 | 155 | |
michael@0 | 156 | |
michael@0 | 157 | |
michael@0 | 158 | //----------------------------------------------------------------------------- |
michael@0 | 159 | test(); |
michael@0 | 160 | //----------------------------------------------------------------------------- |
michael@0 | 161 | |
michael@0 | 162 | |
michael@0 | 163 | |
michael@0 | 164 | function addThis() |
michael@0 | 165 | { |
michael@0 | 166 | statusitems[UBound] = status; |
michael@0 | 167 | actualvalues[UBound] = actual; |
michael@0 | 168 | expectedvalues[UBound] = expect; |
michael@0 | 169 | UBound++; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | |
michael@0 | 173 | function test() |
michael@0 | 174 | { |
michael@0 | 175 | enterFunc('test'); |
michael@0 | 176 | printBugNumber(BUGNUMBER); |
michael@0 | 177 | printStatus(summary); |
michael@0 | 178 | |
michael@0 | 179 | for (var i=0; i<UBound; i++) |
michael@0 | 180 | { |
michael@0 | 181 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | exitFunc ('test'); |
michael@0 | 185 | } |