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 // Ported from dom/src/json/test/unit/test_reviver.js
3 function doubler(k, v)
4 {
5 assertEq(typeof k, "string");
7 if (typeof v == "number")
8 return 2 * v;
10 return v;
11 }
13 var x = JSON.parse('{"a":5,"b":6}', doubler);
14 assertEq(x.hasOwnProperty('a'), true);
15 assertEq(x.hasOwnProperty('b'), true);
16 assertEq(x.a, 10);
17 assertEq(x.b, 12);
19 x = JSON.parse('[3, 4, 5]', doubler);
20 assertEq(x[0], 6);
21 assertEq(x[1], 8);
22 assertEq(x[2], 10);
24 // make sure reviver isn't called after a failed parse
25 var called = false;
26 function dontCallMe(k, v)
27 {
28 called = true;
29 }
31 try
32 {
33 JSON.parse('{{{{{{{}}}}', dontCallMe);
34 throw new Error("didn't throw?");
35 }
36 catch (e)
37 {
38 assertEq(e instanceof SyntaxError, true, "wrong exception: " + e);
39 }
40 assertEq(called, false);
42 /******************************************************************************/
44 if (typeof reportCompare === "function")
45 reportCompare(true, true);
47 print("Tests complete");