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-hijinks.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: var bigOdd = Math.pow(2, 50) + 1; michael@0: michael@0: function two() michael@0: { michael@0: return Math.random() < 0.5 ? 2 : "2"; michael@0: } michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [1, 1]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [1, "1"]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [1, bigOdd % two()]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, ["1", 1]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, ["1", "1"]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, ["1", bigOdd % two()]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), 1]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), "1"]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), bigOdd % two()]), '{"1":1}'); michael@0: michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [1, new String(1)]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [1, new Number(1)]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, ["1", new Number(1)]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, ["1", new String(1)]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), new Number(1)]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [bigOdd % two(), new String(1)]), '{"1":1}'); michael@0: michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [new String(1), new String(1)]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [new String(1), new Number(1)]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [new Number(1), new String(1)]), '{"1":1}'); michael@0: michael@0: assertEq(JSON.stringify({ 1: 1 }, [new Number(1), new Number(1)]), '{"1":1}'); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");