js/src/tests/ecma_5/JSON/stringify-replacer-with-array-indexes.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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