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 | // Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | // http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 3 | |
michael@0 | 4 | //----------------------------------------------------------------------------- |
michael@0 | 5 | var BUGNUMBER = 715821; |
michael@0 | 6 | var summary = "Implement __define[GS]etter__ using Object.defineProperty"; |
michael@0 | 7 | |
michael@0 | 8 | print(BUGNUMBER + ": " + summary); |
michael@0 | 9 | |
michael@0 | 10 | /************* |
michael@0 | 11 | * UTILITIES * |
michael@0 | 12 | *************/ |
michael@0 | 13 | |
michael@0 | 14 | function s(desc) |
michael@0 | 15 | { |
michael@0 | 16 | if (typeof desc === "undefined") |
michael@0 | 17 | return "<undefined>"; |
michael@0 | 18 | assertEq(typeof desc, "object"); |
michael@0 | 19 | assertEq(desc !== null, true); |
michael@0 | 20 | |
michael@0 | 21 | var str = "<enumerable: <" + desc.enumerable + ">, " + |
michael@0 | 22 | " configurable: <" + desc.configurable + ">,"; |
michael@0 | 23 | |
michael@0 | 24 | if (desc.hasOwnProperty("value")) |
michael@0 | 25 | { |
michael@0 | 26 | return str + |
michael@0 | 27 | " value: <" + desc.value + ">," + |
michael@0 | 28 | " writable: <" + desc.writable + ">>"; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | return str + |
michael@0 | 32 | " get: <" + desc.get + ">," + |
michael@0 | 33 | " set: <" + desc.set + ">>"; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function checkField(field, desc, expected) |
michael@0 | 37 | { |
michael@0 | 38 | var present = desc.hasOwnProperty(field); |
michael@0 | 39 | assertEq(present, expected.hasOwnProperty(field), |
michael@0 | 40 | field + " presence mismatch (got " + s(desc) + ", expected " + s(expected) + ")"); |
michael@0 | 41 | if (present) |
michael@0 | 42 | { |
michael@0 | 43 | assertEq(desc[field], expected[field], |
michael@0 | 44 | field + " value mismatch (got " + s(desc) + ", expected " + s(expected) + ")"); |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function check(obj, prop, expected) |
michael@0 | 49 | { |
michael@0 | 50 | var desc = Object.getOwnPropertyDescriptor(obj, prop); |
michael@0 | 51 | assertEq(typeof desc, typeof expected, |
michael@0 | 52 | "type mismatch (got " + s(desc) + ", expected " + s(expected) + ")"); |
michael@0 | 53 | |
michael@0 | 54 | assertEq(desc.hasOwnProperty("get"), desc.hasOwnProperty("set"), |
michael@0 | 55 | "bad descriptor: " + s(desc)); |
michael@0 | 56 | assertEq(desc.hasOwnProperty("value"), desc.hasOwnProperty("writable"), |
michael@0 | 57 | "bad descriptor: " + s(desc)); |
michael@0 | 58 | |
michael@0 | 59 | assertEq(desc.hasOwnProperty("get"), !desc.hasOwnProperty("value"), |
michael@0 | 60 | "bad descriptor: " + s(desc)); |
michael@0 | 61 | |
michael@0 | 62 | checkField("get", desc, expected); |
michael@0 | 63 | checkField("set", desc, expected); |
michael@0 | 64 | checkField("value", desc, expected); |
michael@0 | 65 | checkField("writable", desc, expected); |
michael@0 | 66 | checkField("enumerable", desc, expected); |
michael@0 | 67 | checkField("configurable", desc, expected); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function expectTypeError(f) |
michael@0 | 71 | { |
michael@0 | 72 | try |
michael@0 | 73 | { |
michael@0 | 74 | f(); |
michael@0 | 75 | throw new Error("no error thrown"); |
michael@0 | 76 | } |
michael@0 | 77 | catch (e) |
michael@0 | 78 | { |
michael@0 | 79 | assertEq(e instanceof TypeError, true, |
michael@0 | 80 | "wrong error thrown: got " + e + ", not a TypeError"); |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | /************** |
michael@0 | 85 | * BEGIN TEST * |
michael@0 | 86 | **************/ |
michael@0 | 87 | |
michael@0 | 88 | // Adding a new getter, overwriting an existing one |
michael@0 | 89 | |
michael@0 | 90 | function g1() { } |
michael@0 | 91 | var gobj = {}; |
michael@0 | 92 | gobj.__defineGetter__("foo", g1); |
michael@0 | 93 | check(gobj, "foo", { get: g1, set: undefined, enumerable: true, configurable: true }); |
michael@0 | 94 | |
michael@0 | 95 | function g2() { } |
michael@0 | 96 | gobj.__defineGetter__("foo", g2); |
michael@0 | 97 | check(gobj, "foo", { get: g2, set: undefined, enumerable: true, configurable: true }); |
michael@0 | 98 | |
michael@0 | 99 | /******************************************************************************/ |
michael@0 | 100 | |
michael@0 | 101 | // Adding a new setter, overwriting an existing one |
michael@0 | 102 | |
michael@0 | 103 | function s1() { } |
michael@0 | 104 | var sobj = {}; |
michael@0 | 105 | sobj.__defineSetter__("bar", s1); |
michael@0 | 106 | check(sobj, "bar", { get: undefined, set: s1, enumerable: true, configurable: true }); |
michael@0 | 107 | |
michael@0 | 108 | function s2() { } |
michael@0 | 109 | sobj.__defineSetter__("bar", s2); |
michael@0 | 110 | check(sobj, "bar", { get: undefined, set: s2, enumerable: true, configurable: true }); |
michael@0 | 111 | |
michael@0 | 112 | /******************************************************************************/ |
michael@0 | 113 | |
michael@0 | 114 | // Adding a new getter, then adding a setter |
michael@0 | 115 | // Changing an existing accessor's enumerability, then "null"-changing the accessor |
michael@0 | 116 | // Changing an accessor's configurability, then "null"-changing and real-changing the accessor |
michael@0 | 117 | |
michael@0 | 118 | function g3() { } |
michael@0 | 119 | var gsobj = {}; |
michael@0 | 120 | gsobj.__defineGetter__("baz", g3); |
michael@0 | 121 | check(gsobj, "baz", { get: g3, set: undefined, enumerable: true, configurable: true }); |
michael@0 | 122 | |
michael@0 | 123 | function s3() { } |
michael@0 | 124 | gsobj.__defineSetter__("baz", s3); |
michael@0 | 125 | check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: true }); |
michael@0 | 126 | |
michael@0 | 127 | Object.defineProperty(gsobj, "baz", { enumerable: false }); |
michael@0 | 128 | check(gsobj, "baz", { get: g3, set: s3, enumerable: false, configurable: true }); |
michael@0 | 129 | |
michael@0 | 130 | gsobj.__defineGetter__("baz", g3); |
michael@0 | 131 | check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: true }); |
michael@0 | 132 | |
michael@0 | 133 | Object.defineProperty(gsobj, "baz", { enumerable: false }); |
michael@0 | 134 | check(gsobj, "baz", { get: g3, set: s3, enumerable: false, configurable: true }); |
michael@0 | 135 | |
michael@0 | 136 | gsobj.__defineSetter__("baz", s3); |
michael@0 | 137 | check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: true }); |
michael@0 | 138 | |
michael@0 | 139 | Object.defineProperty(gsobj, "baz", { configurable: false }); |
michael@0 | 140 | expectTypeError(function() { gsobj.__defineSetter__("baz", s2); }); |
michael@0 | 141 | expectTypeError(function() { gsobj.__defineSetter__("baz", s3); }); |
michael@0 | 142 | check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: false }); |
michael@0 | 143 | |
michael@0 | 144 | /******************************************************************************/ |
michael@0 | 145 | |
michael@0 | 146 | // Adding a new setter, then adding a getter |
michael@0 | 147 | // Changing an existing accessor's enumerability, then "null"-changing the accessor |
michael@0 | 148 | // Changing an accessor's configurability, then "null"-changing and real-changing the accessor |
michael@0 | 149 | |
michael@0 | 150 | function s4() { } |
michael@0 | 151 | var sgobj = {}; |
michael@0 | 152 | sgobj.__defineSetter__("baz", s4); |
michael@0 | 153 | check(sgobj, "baz", { get: undefined, set: s4, enumerable: true, configurable: true }); |
michael@0 | 154 | |
michael@0 | 155 | function g4() { } |
michael@0 | 156 | sgobj.__defineGetter__("baz", g4); |
michael@0 | 157 | check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: true }); |
michael@0 | 158 | |
michael@0 | 159 | Object.defineProperty(sgobj, "baz", { enumerable: false }); |
michael@0 | 160 | check(sgobj, "baz", { get: g4, set: s4, enumerable: false, configurable: true }); |
michael@0 | 161 | |
michael@0 | 162 | sgobj.__defineSetter__("baz", s4); |
michael@0 | 163 | check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: true }); |
michael@0 | 164 | |
michael@0 | 165 | Object.defineProperty(sgobj, "baz", { enumerable: false }); |
michael@0 | 166 | check(sgobj, "baz", { get: g4, set: s4, enumerable: false, configurable: true }); |
michael@0 | 167 | |
michael@0 | 168 | sgobj.__defineSetter__("baz", s4); |
michael@0 | 169 | check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: true }); |
michael@0 | 170 | |
michael@0 | 171 | Object.defineProperty(sgobj, "baz", { configurable: false }); |
michael@0 | 172 | expectTypeError(function() { sgobj.__defineGetter__("baz", g3); }); |
michael@0 | 173 | expectTypeError(function() { sgobj.__defineSetter__("baz", s4); }); |
michael@0 | 174 | check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: false }); |
michael@0 | 175 | |
michael@0 | 176 | /******************************************************************************/ |
michael@0 | 177 | |
michael@0 | 178 | // Adding a getter over a writable data property |
michael@0 | 179 | |
michael@0 | 180 | function g5() { } |
michael@0 | 181 | var gover = { quux: 17 }; |
michael@0 | 182 | check(gover, "quux", { value: 17, writable: true, enumerable: true, configurable: true }); |
michael@0 | 183 | |
michael@0 | 184 | gover.__defineGetter__("quux", g5); |
michael@0 | 185 | check(gover, "quux", { get: g5, set: undefined, enumerable: true, configurable: true }); |
michael@0 | 186 | |
michael@0 | 187 | /******************************************************************************/ |
michael@0 | 188 | |
michael@0 | 189 | // Adding a setter over a writable data property |
michael@0 | 190 | |
michael@0 | 191 | function s5() { } |
michael@0 | 192 | var sover = { quux: 17 }; |
michael@0 | 193 | check(sover, "quux", { value: 17, writable: true, enumerable: true, configurable: true }); |
michael@0 | 194 | |
michael@0 | 195 | sover.__defineSetter__("quux", s5); |
michael@0 | 196 | check(sover, "quux", { get: undefined, set: s5, enumerable: true, configurable: true }); |
michael@0 | 197 | |
michael@0 | 198 | /******************************************************************************/ |
michael@0 | 199 | |
michael@0 | 200 | // Adding a getter over a non-writable data property |
michael@0 | 201 | |
michael@0 | 202 | function g6() { } |
michael@0 | 203 | var gnover = { eit: 17 }; |
michael@0 | 204 | check(gnover, "eit", { value: 17, writable: true, enumerable: true, configurable: true }); |
michael@0 | 205 | Object.defineProperty(gnover, "eit", { writable: false }); |
michael@0 | 206 | check(gnover, "eit", { value: 17, writable: false, enumerable: true, configurable: true }); |
michael@0 | 207 | |
michael@0 | 208 | gnover.__defineGetter__("eit", g6); |
michael@0 | 209 | check(gnover, "eit", { get: g6, set: undefined, enumerable: true, configurable: true }); |
michael@0 | 210 | |
michael@0 | 211 | /******************************************************************************/ |
michael@0 | 212 | |
michael@0 | 213 | // Adding a setter over a non-writable data property |
michael@0 | 214 | |
michael@0 | 215 | function s6() { } |
michael@0 | 216 | var snover = { eit: 17 }; |
michael@0 | 217 | check(snover, "eit", { value: 17, writable: true, enumerable: true, configurable: true }); |
michael@0 | 218 | Object.defineProperty(snover, "eit", { writable: false }); |
michael@0 | 219 | check(snover, "eit", { value: 17, writable: false, enumerable: true, configurable: true }); |
michael@0 | 220 | |
michael@0 | 221 | snover.__defineSetter__("eit", s6); |
michael@0 | 222 | check(snover, "eit", { get: undefined, set: s6, enumerable: true, configurable: true }); |
michael@0 | 223 | |
michael@0 | 224 | /******************************************************************************/ |
michael@0 | 225 | |
michael@0 | 226 | // Adding a getter over a non-configurable, writable data property |
michael@0 | 227 | |
michael@0 | 228 | function g7() { } |
michael@0 | 229 | var gncover = { moo: 17 }; |
michael@0 | 230 | check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurable: true }); |
michael@0 | 231 | Object.defineProperty(gncover, "moo", { configurable: false }); |
michael@0 | 232 | check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false }); |
michael@0 | 233 | |
michael@0 | 234 | expectTypeError(function() { gncover.__defineGetter__("moo", g7); }); |
michael@0 | 235 | check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false }); |
michael@0 | 236 | |
michael@0 | 237 | /******************************************************************************/ |
michael@0 | 238 | |
michael@0 | 239 | // Adding a setter over a non-configurable, writable data property |
michael@0 | 240 | |
michael@0 | 241 | function s7() { } |
michael@0 | 242 | var sncover = { moo: 17 }; |
michael@0 | 243 | check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurable: true }); |
michael@0 | 244 | Object.defineProperty(sncover, "moo", { configurable: false }); |
michael@0 | 245 | check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false }); |
michael@0 | 246 | |
michael@0 | 247 | expectTypeError(function() { sncover.__defineSetter__("moo", s7); }); |
michael@0 | 248 | check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false }); |
michael@0 | 249 | |
michael@0 | 250 | /******************************************************************************/ |
michael@0 | 251 | |
michael@0 | 252 | // Adding a getter over a non-configurable, non-writable data property |
michael@0 | 253 | |
michael@0 | 254 | function g8() { } |
michael@0 | 255 | var gncwover = { fwoosh: 17 }; |
michael@0 | 256 | check(gncwover, "fwoosh", { value: 17, writable: true, enumerable: true, configurable: true }); |
michael@0 | 257 | Object.defineProperty(gncwover, "fwoosh", { writable: false, configurable: false }); |
michael@0 | 258 | check(gncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false }); |
michael@0 | 259 | |
michael@0 | 260 | expectTypeError(function() { gncwover.__defineGetter__("fwoosh", g7); }); |
michael@0 | 261 | check(gncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false }); |
michael@0 | 262 | |
michael@0 | 263 | /******************************************************************************/ |
michael@0 | 264 | |
michael@0 | 265 | // Adding a setter over a non-configurable, non-writable data property |
michael@0 | 266 | |
michael@0 | 267 | function s8() { } |
michael@0 | 268 | var sncwover = { fwoosh: 17 }; |
michael@0 | 269 | check(sncwover, "fwoosh", { value: 17, writable: true, enumerable: true, configurable: true }); |
michael@0 | 270 | Object.defineProperty(sncwover, "fwoosh", { writable: false, configurable: false }); |
michael@0 | 271 | check(sncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false }); |
michael@0 | 272 | |
michael@0 | 273 | expectTypeError(function() { sncwover.__defineSetter__("fwoosh", s7); }); |
michael@0 | 274 | check(sncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false }); |
michael@0 | 275 | |
michael@0 | 276 | /******************************************************************************/ |
michael@0 | 277 | |
michael@0 | 278 | if (typeof reportCompare === "function") |
michael@0 | 279 | reportCompare(true, true); |
michael@0 | 280 | |
michael@0 | 281 | print("Tests complete"); |