michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 668024; michael@0: var summary = michael@0: 'Array.prototype.splice, when it deletes elements, should make sure any ' + michael@0: 'deleted but not visited elements are suppressed from subsequent enumeration'; 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, 5, , 7]; michael@0: michael@0: var seen = []; michael@0: var sawOneBeforeThree = true; michael@0: for (var p in arr) michael@0: { michael@0: if (p === "1") michael@0: { michael@0: // The order of enumeration of properties is unspecified, so technically, michael@0: // it would be kosher to enumerate "1" last, say, such that all properties michael@0: // in the array actually were enumerated, including an index which splice michael@0: // would delete. Don't flag that case as a failure. (SpiderMonkey doesn't michael@0: // do this, and neither do any of the other browser engines, but it is michael@0: // permissible behavior.) michael@0: if (seen.indexOf("3") >= 0) michael@0: { michael@0: sawOneBeforeThree = false; michael@0: break; michael@0: } michael@0: michael@0: arr.splice(2, 3); michael@0: } michael@0: michael@0: seen.push(p); michael@0: } michael@0: michael@0: if (sawOneBeforeThree) michael@0: { michael@0: // ES5 12.6.4 states: michael@0: // michael@0: // If a property that has not yet been visited during enumeration is michael@0: // deleted, then it will not be visited. michael@0: // michael@0: // So if we haven't seen "3" by the time we see "1", the splice call above michael@0: // will delete "3", and therefore we must not see it. michael@0: assertEq(seen.indexOf("3"), -1); michael@0: } michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");