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 = 'parse-reviver-array-delete.js';
5 //-----------------------------------------------------------------------------
6 var BUGNUMBER = 999999;
7 var summary = "JSON.parse with a reviver which elides array elements";
9 print(BUGNUMBER + ": " + summary);
11 /**************
12 * BEGIN TEST *
13 **************/
15 /*
16 * The reviver deletes all properties from the to-be-returned array. Thus
17 * stringification reveals properties on the prototype chain -- but there are
18 * none, so this result is unsurprising.
19 */
20 assertEq(JSON.parse('[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]',
21 function revive(k, v)
22 {
23 if (k === "")
24 return v;
25 return undefined;
26 }) + "",
27 ",,,,,,,,,,,,,,,,,,,");
29 /*
30 * Now let's try a reviver that deletes every property but a mega-huge one.
31 */
32 var str = "[";
33 var expected = "";
34 var expected2 = "";
35 for (var i = 0; i < 2048; i++)
36 {
37 str += "1,";
38 if (i === 2047)
39 {
40 expected += "1";
41 expected2 += "1";
42 }
43 if (i === 3)
44 expected2 += "17";
45 expected += ",";
46 expected2 += ",";
47 }
48 str += "1]";
50 assertEq(JSON.parse(str,
51 function reviver(k, v)
52 {
53 if (k === "" || k === "2047")
54 return v;
55 return undefined;
56 }) + "",
57 expected);
60 Array.prototype[3] = 17;
62 /* Now, with a property on the prototype chain, it'll show through. */
63 assertEq(JSON.parse('[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]',
64 function revive(k, v)
65 {
66 if (k === "")
67 return v;
68 return undefined;
69 }) + "",
70 ",,,17,,,,,,,,,,,,,,,,");
73 /* And here too. */
74 assertEq(JSON.parse(str,
75 function reviver(k, v)
76 {
77 if (k === "" || k === "2047")
78 return v;
79 return undefined;
80 }) + "",
81 expected2);
84 /******************************************************************************/
86 if (typeof reportCompare === "function")
87 reportCompare(true, true);
89 print("Tests complete");