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 | var gTestfile = 'stringify-gap.js'; |
michael@0 | 5 | //----------------------------------------------------------------------------- |
michael@0 | 6 | var BUGNUMBER = 584909; |
michael@0 | 7 | var summary = |
michael@0 | 8 | "JSON.stringify(_1, _2, numberGreaterThanOne) produces wrong output"; |
michael@0 | 9 | |
michael@0 | 10 | print(BUGNUMBER + ": " + summary); |
michael@0 | 11 | |
michael@0 | 12 | /************** |
michael@0 | 13 | * BEGIN TEST * |
michael@0 | 14 | **************/ |
michael@0 | 15 | |
michael@0 | 16 | var LF = "\n"; |
michael@0 | 17 | var GAP = " "; |
michael@0 | 18 | |
michael@0 | 19 | var obj = { a: { b: [1, 2], c: { d: 3, e: 4 }, f: [], g: {}, h: [5], i: { j: 6 } } }; |
michael@0 | 20 | |
michael@0 | 21 | var expected = |
michael@0 | 22 | '{\n' + |
michael@0 | 23 | ' "a": {\n' + |
michael@0 | 24 | ' "b": [\n' + |
michael@0 | 25 | ' 1,\n' + |
michael@0 | 26 | ' 2\n' + |
michael@0 | 27 | ' ],\n' + |
michael@0 | 28 | ' "c": {\n' + |
michael@0 | 29 | ' "d": 3,\n' + |
michael@0 | 30 | ' "e": 4\n' + |
michael@0 | 31 | ' },\n' + |
michael@0 | 32 | ' "f": [],\n' + |
michael@0 | 33 | ' "g": {},\n' + |
michael@0 | 34 | ' "h": [\n' + |
michael@0 | 35 | ' 5\n' + |
michael@0 | 36 | ' ],\n' + |
michael@0 | 37 | ' "i": {\n' + |
michael@0 | 38 | ' "j": 6\n' + |
michael@0 | 39 | ' }\n' + |
michael@0 | 40 | ' }\n' + |
michael@0 | 41 | '}'; |
michael@0 | 42 | |
michael@0 | 43 | assertEq(JSON.stringify(obj, null, 3), expected); |
michael@0 | 44 | assertEq(JSON.stringify(obj, null, " "), expected); |
michael@0 | 45 | |
michael@0 | 46 | obj = [1, 2, 3]; |
michael@0 | 47 | |
michael@0 | 48 | String.prototype.toString = function() { return "--"; }; |
michael@0 | 49 | |
michael@0 | 50 | assertEq(JSON.stringify(obj, null, new String(" ")), "[\n--1,\n--2,\n--3\n]"); |
michael@0 | 51 | |
michael@0 | 52 | Number.prototype.valueOf = function() { return 0; }; |
michael@0 | 53 | |
michael@0 | 54 | assertEq(JSON.stringify(obj, null, new Number(3)), "[1,2,3]"); |
michael@0 | 55 | |
michael@0 | 56 | /******************************************************************************/ |
michael@0 | 57 | |
michael@0 | 58 | if (typeof reportCompare === "function") |
michael@0 | 59 | reportCompare(true, true); |
michael@0 | 60 | |
michael@0 | 61 | print("All tests passed!"); |