js/src/tests/ecma_5/JSON/stringify-replacer-array-edgecase-jsid-elements.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/JSON/stringify-replacer-array-edgecase-jsid-elements.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +// Any copyright is dedicated to the Public Domain.
     1.5 +// http://creativecommons.org/licenses/publicdomain/
     1.6 +
     1.7 +var gTestfile = 'stringify-replacer-array-edgecase-jsid-elements.js';
     1.8 +//-----------------------------------------------------------------------------
     1.9 +var BUGNUMBER = 648471;
    1.10 +var summary =
    1.11 +  "Better/more correct handling for replacer arrays with getter array index " +
    1.12 +  "properties";
    1.13 +
    1.14 +print(BUGNUMBER + ": " + summary);
    1.15 +
    1.16 +/**************
    1.17 + * BEGIN TEST *
    1.18 + **************/
    1.19 +
    1.20 +/* JSID_INT_MIN/MAX copied from jsapi.h. */
    1.21 +
    1.22 +var obj =
    1.23 +  {
    1.24 +    /* [JSID_INT_MIN - 1, JSID_INT_MIN + 1] */
    1.25 +    "-1073741825": -1073741825,
    1.26 +    "-1073741824": -1073741824,
    1.27 +    "-1073741823": -1073741823,
    1.28 +
    1.29 +    "-2.5": -2.5,
    1.30 +    "-1": -1,
    1.31 +
    1.32 +    0: 0,
    1.33 +
    1.34 +    1: 1,
    1.35 +    2.5: 2.5,
    1.36 +
    1.37 +    /* [JSID_INT_MAX - 1, JSID_INT_MAX + 1] */
    1.38 +    1073741822: 1073741822,
    1.39 +    1073741823: 1073741823,
    1.40 +    1073741824: 1073741824,
    1.41 +  };
    1.42 +
    1.43 +for (var s in obj)
    1.44 +{
    1.45 +  var n = obj[s];
    1.46 +  assertEq(+s, n);
    1.47 +  assertEq(JSON.stringify(obj, [n]),
    1.48 +           '{"' + s + '":' + n + '}',
    1.49 +           "Failed to stringify numeric property " + n + "correctly");
    1.50 +  assertEq(JSON.stringify(obj, [s]),
    1.51 +           '{"' + s + '":' + n + '}',
    1.52 +           "Failed to stringify string property " + n + "correctly");
    1.53 +  assertEq(JSON.stringify(obj, [s, ]),
    1.54 +           '{"' + s + '":' + n + '}',
    1.55 +           "Failed to stringify string then number properties ('" + s + "', " + n + ") correctly");
    1.56 +  assertEq(JSON.stringify(obj, [n, s]),
    1.57 +           '{"' + s + '":' + n + '}',
    1.58 +           "Failed to stringify number then string properties (" + n + ", '" + s + "') correctly");
    1.59 +}
    1.60 +
    1.61 +// -0 is tricky, because ToString(-0) === "0", so test it specially.
    1.62 +assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0]),
    1.63 +         '{"0":42}',
    1.64 +         "Failed to stringify numeric property -0 correctly");
    1.65 +assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0"]),
    1.66 +         '{"-0":17}',
    1.67 +         "Failed to stringify string property -0 correctly");
    1.68 +assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0", -0]),
    1.69 +         '{"-0":17,"0":42}',
    1.70 +         "Failed to stringify string then number properties ('-0', -0) correctly");
    1.71 +assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0, "-0"]),
    1.72 +         '{"0":42,"-0":17}',
    1.73 +         "Failed to stringify number then string properties (-0, '-0) correctly");
    1.74 +
    1.75 +/******************************************************************************/
    1.76 +
    1.77 +if (typeof reportCompare === "function")
    1.78 +  reportCompare(true, true);
    1.79 +
    1.80 +print("Tests complete");

mercurial