1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/Array/splice-suppresses-unvisited-indexes.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 668024; 1.11 +var summary = 1.12 + 'Array.prototype.splice, when it deletes elements, should make sure any ' + 1.13 + 'deleted but not visited elements are suppressed from subsequent enumeration'; 1.14 + 1.15 +print(BUGNUMBER + ": " + summary); 1.16 + 1.17 +/************** 1.18 + * BEGIN TEST * 1.19 + **************/ 1.20 + 1.21 +var arr = [0, 1, 2, 3, 4, 5, , 7]; 1.22 + 1.23 +var seen = []; 1.24 +var sawOneBeforeThree = true; 1.25 +for (var p in arr) 1.26 +{ 1.27 + if (p === "1") 1.28 + { 1.29 + // The order of enumeration of properties is unspecified, so technically, 1.30 + // it would be kosher to enumerate "1" last, say, such that all properties 1.31 + // in the array actually were enumerated, including an index which splice 1.32 + // would delete. Don't flag that case as a failure. (SpiderMonkey doesn't 1.33 + // do this, and neither do any of the other browser engines, but it is 1.34 + // permissible behavior.) 1.35 + if (seen.indexOf("3") >= 0) 1.36 + { 1.37 + sawOneBeforeThree = false; 1.38 + break; 1.39 + } 1.40 + 1.41 + arr.splice(2, 3); 1.42 + } 1.43 + 1.44 + seen.push(p); 1.45 +} 1.46 + 1.47 +if (sawOneBeforeThree) 1.48 +{ 1.49 + // ES5 12.6.4 states: 1.50 + // 1.51 + // If a property that has not yet been visited during enumeration is 1.52 + // deleted, then it will not be visited. 1.53 + // 1.54 + // So if we haven't seen "3" by the time we see "1", the splice call above 1.55 + // will delete "3", and therefore we must not see it. 1.56 + assertEq(seen.indexOf("3"), -1); 1.57 +} 1.58 + 1.59 +/******************************************************************************/ 1.60 + 1.61 +if (typeof reportCompare === "function") 1.62 + reportCompare(true, true); 1.63 + 1.64 +print("Tests complete");