js/src/tests/ecma_5/JSON/stringify-gap.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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

mercurial