Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | // http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 3 | |
michael@0 | 4 | var gTestfile = 'stringify-replacer-with-array-indexes.js'; |
michael@0 | 5 | //----------------------------------------------------------------------------- |
michael@0 | 6 | var BUGNUMBER = 584909; |
michael@0 | 7 | var summary = |
michael@0 | 8 | "Call the replacer function for array elements with stringified indexes"; |
michael@0 | 9 | |
michael@0 | 10 | print(BUGNUMBER + ": " + summary); |
michael@0 | 11 | |
michael@0 | 12 | /************** |
michael@0 | 13 | * BEGIN TEST * |
michael@0 | 14 | **************/ |
michael@0 | 15 | |
michael@0 | 16 | var arr = [0, 1, 2, 3, 4]; |
michael@0 | 17 | |
michael@0 | 18 | var seenTopmost = false; |
michael@0 | 19 | var index = 0; |
michael@0 | 20 | function replacer() |
michael@0 | 21 | { |
michael@0 | 22 | assertEq(arguments.length, 2); |
michael@0 | 23 | |
michael@0 | 24 | var key = arguments[0], value = arguments[1]; |
michael@0 | 25 | |
michael@0 | 26 | // Topmost array: ignore replacer call. |
michael@0 | 27 | if (key === "") |
michael@0 | 28 | { |
michael@0 | 29 | assertEq(seenTopmost, false); |
michael@0 | 30 | seenTopmost = true; |
michael@0 | 31 | return value; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | assertEq(seenTopmost, true); |
michael@0 | 35 | |
michael@0 | 36 | assertEq(typeof key, "string"); |
michael@0 | 37 | assertEq(key === index, false); |
michael@0 | 38 | assertEq(key === index + "", true); |
michael@0 | 39 | |
michael@0 | 40 | assertEq(value, index); |
michael@0 | 41 | |
michael@0 | 42 | index++; |
michael@0 | 43 | |
michael@0 | 44 | assertEq(this, arr); |
michael@0 | 45 | |
michael@0 | 46 | return value; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | assertEq(JSON.stringify(arr, replacer), '[0,1,2,3,4]'); |
michael@0 | 50 | |
michael@0 | 51 | /******************************************************************************/ |
michael@0 | 52 | |
michael@0 | 53 | if (typeof reportCompare === "function") |
michael@0 | 54 | reportCompare(true, true); |
michael@0 | 55 | |
michael@0 | 56 | print("Tests complete"); |