1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/JSON/stringify-replacer-array-boxed-elements.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 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-boxed-elements.js'; 1.8 +//----------------------------------------------------------------------------- 1.9 +var BUGNUMBER = 648471; 1.10 +var summary = "Boxed-string/number objects in replacer arrays"; 1.11 + 1.12 +print(BUGNUMBER + ": " + summary); 1.13 + 1.14 +/************** 1.15 + * BEGIN TEST * 1.16 + **************/ 1.17 + 1.18 +var S = new String(3); 1.19 +var N = new Number(4); 1.20 + 1.21 +assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]), 1.22 + '{"3":3}'); 1.23 +assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]), 1.24 + '{"4":4}'); 1.25 + 1.26 +Number.prototype.toString = function() { return 3; }; 1.27 +assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]), 1.28 + '{"3":3}'); 1.29 + 1.30 +String.prototype.toString = function() { return 4; }; 1.31 +assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]), 1.32 + '{"4":4}'); 1.33 + 1.34 +Number.prototype.toString = function() { return new String(42); }; 1.35 +assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]), 1.36 + '{"4":4}'); 1.37 + 1.38 +String.prototype.toString = function() { return new Number(17); }; 1.39 +assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]), 1.40 + '{"3":3}'); 1.41 + 1.42 +Number.prototype.toString = null; 1.43 +assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]), 1.44 + '{"4":4}'); 1.45 + 1.46 +String.prototype.toString = null; 1.47 +assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]), 1.48 + '{"3":3}'); 1.49 + 1.50 +Number.prototype.valueOf = function() { return 17; }; 1.51 +assertEq(JSON.stringify({ 4: 4, 17: 17 }, [N]), 1.52 + '{"17":17}'); 1.53 + 1.54 +String.prototype.valueOf = function() { return 42; }; 1.55 +assertEq(JSON.stringify({ 3: 3, 42: 42 }, [S]), 1.56 + '{"42":42}'); 1.57 + 1.58 +/******************************************************************************/ 1.59 + 1.60 +if (typeof reportCompare === "function") 1.61 + reportCompare(true, true); 1.62 + 1.63 +print("Tests complete");