js/src/tests/ecma_5/JSON/stringify-replacer-array-edgecase-jsid-elements.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-replacer-array-edgecase-jsid-elements.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 /* JSID_INT_MIN/MAX copied from jsapi.h. */
    19 var obj =
    20   {
    21     /* [JSID_INT_MIN - 1, JSID_INT_MIN + 1] */
    22     "-1073741825": -1073741825,
    23     "-1073741824": -1073741824,
    24     "-1073741823": -1073741823,
    26     "-2.5": -2.5,
    27     "-1": -1,
    29     0: 0,
    31     1: 1,
    32     2.5: 2.5,
    34     /* [JSID_INT_MAX - 1, JSID_INT_MAX + 1] */
    35     1073741822: 1073741822,
    36     1073741823: 1073741823,
    37     1073741824: 1073741824,
    38   };
    40 for (var s in obj)
    41 {
    42   var n = obj[s];
    43   assertEq(+s, n);
    44   assertEq(JSON.stringify(obj, [n]),
    45            '{"' + s + '":' + n + '}',
    46            "Failed to stringify numeric property " + n + "correctly");
    47   assertEq(JSON.stringify(obj, [s]),
    48            '{"' + s + '":' + n + '}',
    49            "Failed to stringify string property " + n + "correctly");
    50   assertEq(JSON.stringify(obj, [s, ]),
    51            '{"' + s + '":' + n + '}',
    52            "Failed to stringify string then number properties ('" + s + "', " + n + ") correctly");
    53   assertEq(JSON.stringify(obj, [n, s]),
    54            '{"' + s + '":' + n + '}',
    55            "Failed to stringify number then string properties (" + n + ", '" + s + "') correctly");
    56 }
    58 // -0 is tricky, because ToString(-0) === "0", so test it specially.
    59 assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0]),
    60          '{"0":42}',
    61          "Failed to stringify numeric property -0 correctly");
    62 assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0"]),
    63          '{"-0":17}',
    64          "Failed to stringify string property -0 correctly");
    65 assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0", -0]),
    66          '{"-0":17,"0":42}',
    67          "Failed to stringify string then number properties ('-0', -0) correctly");
    68 assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0, "-0"]),
    69          '{"0":42,"-0":17}',
    70          "Failed to stringify number then string properties (-0, '-0) correctly");
    72 /******************************************************************************/
    74 if (typeof reportCompare === "function")
    75   reportCompare(true, true);
    77 print("Tests complete");

mercurial