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.
1 // Any copyright is dedicated to the Public Domain.
2 // http://creativecommons.org/licenses/publicdomain/
4 var gTestfile = 'stringify-replacer-array-hijinks.js';
5 //-----------------------------------------------------------------------------
6 var BUGNUMBER = 648471;
7 var summary =
8 "Better/more correct handling for replacer arrays with getter array index " +
9 "properties";
11 print(BUGNUMBER + ": " + summary);
13 /**************
14 * BEGIN TEST *
15 **************/
17 var replacer = [0, 1, 2, 3];
18 Object.prototype[3] = 3;
19 Object.defineProperty(replacer, 1, {
20 get: function()
21 {
22 Object.defineProperty(replacer, 4, { value: 4 });
23 delete replacer[2];
24 delete replacer[3];
25 replacer[5] = 5;
26 return 1;
27 }
28 });
30 var s =
31 JSON.stringify({0: { 1: { 3: { 4: { 5: { 2: "omitted" } } } } } }, replacer);
33 // The replacer array's length is as seen on first query, so property names are
34 // accumulated for indexes i ∈ {0, 1, 2, 3}, but index 1 deletes 2 and 3, so 2
35 // isn't seen but 3 is seen as Object.prototype[3].
36 assertEq('{"0":{"1":{"3":{"3":3}},"3":3},"3":3}', s);
39 var replacer = [0, 1, 2, 3];
40 Object.defineProperty(replacer, 0, {
41 get: function()
42 {
43 replacer.length = 0;
44 return {};
45 }
46 });
48 // The replacer.length truncation means only properties on the prototype chain
49 // shine through, but it doesn't affect the original bounds of the iteration
50 // used to determine property names which will be included in the final string.
51 assertEq(JSON.stringify({ 0: 0, 1: 1, 2: 2, 3: 3 }, replacer),
52 '{"3":3}');
54 /******************************************************************************/
56 if (typeof reportCompare === "function")
57 reportCompare(true, true);
59 print("Tests complete");