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