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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Any copyright is dedicated to the Public Domain.
     2 // http://creativecommons.org/licenses/publicdomain/
     4 var gTestfile = 'stringify-replacer-array-boxed-elements.js';
     5 //-----------------------------------------------------------------------------
     6 var BUGNUMBER = 648471;
     7 var summary = "Boxed-string/number objects in replacer arrays";
     9 print(BUGNUMBER + ": " + summary);
    11 /**************
    12  * BEGIN TEST *
    13  **************/
    15 var S = new String(3);
    16 var N = new Number(4);
    18 assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]),
    19          '{"3":3}');
    20 assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]),
    21          '{"4":4}');
    23 Number.prototype.toString = function() { return 3; };
    24 assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]),
    25          '{"3":3}');
    27 String.prototype.toString = function() { return 4; };
    28 assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]),
    29          '{"4":4}');
    31 Number.prototype.toString = function() { return new String(42); };
    32 assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]),
    33          '{"4":4}');
    35 String.prototype.toString = function() { return new Number(17); };
    36 assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]),
    37          '{"3":3}');
    39 Number.prototype.toString = null;
    40 assertEq(JSON.stringify({ 3: 3, 4: 4 }, [N]),
    41          '{"4":4}');
    43 String.prototype.toString = null;
    44 assertEq(JSON.stringify({ 3: 3, 4: 4 }, [S]),
    45          '{"3":3}');
    47 Number.prototype.valueOf = function() { return 17; };
    48 assertEq(JSON.stringify({ 4: 4, 17: 17 }, [N]),
    49          '{"17":17}');
    51 String.prototype.valueOf = function() { return 42; };
    52 assertEq(JSON.stringify({ 3: 3, 42: 42 }, [S]),
    53          '{"42":42}');
    55 /******************************************************************************/
    57 if (typeof reportCompare === "function")
    58   reportCompare(true, true);
    60 print("Tests complete");

mercurial