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-boxed-elements.js'; michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 648471; michael@0: var summary = "Boxed-string/number objects in replacer arrays"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var S = new String(3); michael@0: var N = new Number(4); michael@0: michael@0: assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]), michael@0: '{"3":3}'); michael@0: assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]), michael@0: '{"4":4}'); michael@0: michael@0: Number.prototype.toString = function() { return 3; }; michael@0: assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]), michael@0: '{"3":3}'); michael@0: michael@0: String.prototype.toString = function() { return 4; }; michael@0: assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]), michael@0: '{"4":4}'); michael@0: michael@0: Number.prototype.toString = function() { return new String(42); }; michael@0: assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]), michael@0: '{"4":4}'); michael@0: michael@0: String.prototype.toString = function() { return new Number(17); }; michael@0: assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]), michael@0: '{"3":3}'); michael@0: michael@0: Number.prototype.toString = null; michael@0: assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]), michael@0: '{"4":4}'); michael@0: michael@0: String.prototype.toString = null; michael@0: assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]), michael@0: '{"3":3}'); michael@0: michael@0: Number.prototype.valueOf = function() { return 17; }; michael@0: assertEq(JSON.stringify({ 4: 4, 17: 17 }, [N]), michael@0: '{"17":17}'); michael@0: michael@0: String.prototype.valueOf = function() { return 42; }; michael@0: assertEq(JSON.stringify({ 3: 3, 42: 42 }, [S]), michael@0: '{"42":42}'); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");