michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: michael@0: var gTestfile = 'stringify-replacer-with-array-indexes.js'; michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 584909; michael@0: var summary = michael@0: "Call the replacer function for array elements with stringified indexes"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var arr = [0, 1, 2, 3, 4]; michael@0: michael@0: var seenTopmost = false; michael@0: var index = 0; michael@0: function replacer() michael@0: { michael@0: assertEq(arguments.length, 2); michael@0: michael@0: var key = arguments[0], value = arguments[1]; michael@0: michael@0: // Topmost array: ignore replacer call. michael@0: if (key === "") michael@0: { michael@0: assertEq(seenTopmost, false); michael@0: seenTopmost = true; michael@0: return value; michael@0: } michael@0: michael@0: assertEq(seenTopmost, true); michael@0: michael@0: assertEq(typeof key, "string"); michael@0: assertEq(key === index, false); michael@0: assertEq(key === index + "", true); michael@0: michael@0: assertEq(value, index); michael@0: michael@0: index++; michael@0: michael@0: assertEq(this, arr); michael@0: michael@0: return value; michael@0: } michael@0: michael@0: assertEq(JSON.stringify(arr, replacer), '[0,1,2,3,4]'); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");