michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: michael@0: var gTestfile = 'stringify-replacer-array-edgecase-jsid-elements.js'; michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 648471; michael@0: var summary = michael@0: "Better/more correct handling for replacer arrays with getter array index " + michael@0: "properties"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: /* JSID_INT_MIN/MAX copied from jsapi.h. */ michael@0: michael@0: var obj = michael@0: { michael@0: /* [JSID_INT_MIN - 1, JSID_INT_MIN + 1] */ michael@0: "-1073741825": -1073741825, michael@0: "-1073741824": -1073741824, michael@0: "-1073741823": -1073741823, michael@0: michael@0: "-2.5": -2.5, michael@0: "-1": -1, michael@0: michael@0: 0: 0, michael@0: michael@0: 1: 1, michael@0: 2.5: 2.5, michael@0: michael@0: /* [JSID_INT_MAX - 1, JSID_INT_MAX + 1] */ michael@0: 1073741822: 1073741822, michael@0: 1073741823: 1073741823, michael@0: 1073741824: 1073741824, michael@0: }; michael@0: michael@0: for (var s in obj) michael@0: { michael@0: var n = obj[s]; michael@0: assertEq(+s, n); michael@0: assertEq(JSON.stringify(obj, [n]), michael@0: '{"' + s + '":' + n + '}', michael@0: "Failed to stringify numeric property " + n + "correctly"); michael@0: assertEq(JSON.stringify(obj, [s]), michael@0: '{"' + s + '":' + n + '}', michael@0: "Failed to stringify string property " + n + "correctly"); michael@0: assertEq(JSON.stringify(obj, [s, ]), michael@0: '{"' + s + '":' + n + '}', michael@0: "Failed to stringify string then number properties ('" + s + "', " + n + ") correctly"); michael@0: assertEq(JSON.stringify(obj, [n, s]), michael@0: '{"' + s + '":' + n + '}', michael@0: "Failed to stringify number then string properties (" + n + ", '" + s + "') correctly"); michael@0: } michael@0: michael@0: // -0 is tricky, because ToString(-0) === "0", so test it specially. michael@0: assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0]), michael@0: '{"0":42}', michael@0: "Failed to stringify numeric property -0 correctly"); michael@0: assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0"]), michael@0: '{"-0":17}', michael@0: "Failed to stringify string property -0 correctly"); michael@0: assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0", -0]), michael@0: '{"-0":17,"0":42}', michael@0: "Failed to stringify string then number properties ('-0', -0) correctly"); michael@0: assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0, "-0"]), michael@0: '{"0":42,"-0":17}', michael@0: "Failed to stringify number then string properties (-0, '-0) correctly"); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");