js/src/tests/ecma_5/Array/splice-suppresses-unvisited-indexes.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:52fc94c424f3
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
4 */
5
6 //-----------------------------------------------------------------------------
7 var BUGNUMBER = 668024;
8 var summary =
9 'Array.prototype.splice, when it deletes elements, should make sure any ' +
10 'deleted but not visited elements are suppressed from subsequent enumeration';
11
12 print(BUGNUMBER + ": " + summary);
13
14 /**************
15 * BEGIN TEST *
16 **************/
17
18 var arr = [0, 1, 2, 3, 4, 5, , 7];
19
20 var seen = [];
21 var sawOneBeforeThree = true;
22 for (var p in arr)
23 {
24 if (p === "1")
25 {
26 // The order of enumeration of properties is unspecified, so technically,
27 // it would be kosher to enumerate "1" last, say, such that all properties
28 // in the array actually were enumerated, including an index which splice
29 // would delete. Don't flag that case as a failure. (SpiderMonkey doesn't
30 // do this, and neither do any of the other browser engines, but it is
31 // permissible behavior.)
32 if (seen.indexOf("3") >= 0)
33 {
34 sawOneBeforeThree = false;
35 break;
36 }
37
38 arr.splice(2, 3);
39 }
40
41 seen.push(p);
42 }
43
44 if (sawOneBeforeThree)
45 {
46 // ES5 12.6.4 states:
47 //
48 // If a property that has not yet been visited during enumeration is
49 // deleted, then it will not be visited.
50 //
51 // So if we haven't seen "3" by the time we see "1", the splice call above
52 // will delete "3", and therefore we must not see it.
53 assertEq(seen.indexOf("3"), -1);
54 }
55
56 /******************************************************************************/
57
58 if (typeof reportCompare === "function")
59 reportCompare(true, true);
60
61 print("Tests complete");

mercurial