js/src/tests/ecma_5/JSON/stringify-replacer-with-array-indexes.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-with-array-indexes.js';
     5 //-----------------------------------------------------------------------------
     6 var BUGNUMBER = 584909;
     7 var summary =
     8   "Call the replacer function for array elements with stringified indexes";
    10 print(BUGNUMBER + ": " + summary);
    12 /**************
    13  * BEGIN TEST *
    14  **************/
    16 var arr = [0, 1, 2, 3, 4];
    18 var seenTopmost = false;
    19 var index = 0;
    20 function replacer()
    21 {
    22   assertEq(arguments.length, 2);
    24   var key = arguments[0], value = arguments[1];
    26   // Topmost array: ignore replacer call.
    27   if (key === "")
    28   {
    29     assertEq(seenTopmost, false);
    30     seenTopmost = true;
    31     return value;
    32   }
    34   assertEq(seenTopmost, true);
    36   assertEq(typeof key, "string");
    37   assertEq(key === index, false);
    38   assertEq(key === index + "", true);
    40   assertEq(value, index);
    42   index++;
    44   assertEq(this, arr);
    46   return value;
    47 }
    49 assertEq(JSON.stringify(arr, replacer), '[0,1,2,3,4]');
    51 /******************************************************************************/
    53 if (typeof reportCompare === "function")
    54   reportCompare(true, true);
    56 print("Tests complete");

mercurial