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-array-hijinks.js'; michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 648471; michael@0: var summary = michael@0: "Better/more correct handling for replacer arrays with getter array index " + michael@0: "properties"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var replacer = [0, 1, 2, 3]; michael@0: Object.prototype[3] = 3; michael@0: Object.defineProperty(replacer, 1, { michael@0: get: function() michael@0: { michael@0: Object.defineProperty(replacer, 4, { value: 4 }); michael@0: delete replacer[2]; michael@0: delete replacer[3]; michael@0: replacer[5] = 5; michael@0: return 1; michael@0: } michael@0: }); michael@0: michael@0: var s = michael@0: JSON.stringify({0: { 1: { 3: { 4: { 5: { 2: "omitted" } } } } } }, replacer); michael@0: michael@0: // The replacer array's length is as seen on first query, so property names are michael@0: // accumulated for indexes i ∈ {0, 1, 2, 3}, but index 1 deletes 2 and 3, so 2 michael@0: // isn't seen but 3 is seen as Object.prototype[3]. michael@0: assertEq('{"0":{"1":{"3":{"3":3}},"3":3},"3":3}', s); michael@0: michael@0: michael@0: var replacer = [0, 1, 2, 3]; michael@0: Object.defineProperty(replacer, 0, { michael@0: get: function() michael@0: { michael@0: replacer.length = 0; michael@0: return {}; michael@0: } michael@0: }); michael@0: michael@0: // The replacer.length truncation means only properties on the prototype chain michael@0: // shine through, but it doesn't affect the original bounds of the iteration michael@0: // used to determine property names which will be included in the final string. michael@0: assertEq(JSON.stringify({ 0: 0, 1: 1, 2: 2, 3: 3 }, replacer), michael@0: '{"3":3}'); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");