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 = 858677; michael@0: var summary = michael@0: "[].reverse should swap elements low to high using accesses to low " + michael@0: "elements, then accesses to high elements"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var observed = []; michael@0: michael@0: // (0, 7) hits the lowerExists/upperExists case. michael@0: // (1, 6) hits the !lowerExists/upperExists case. michael@0: // (2, 5) hits the lowerExists/!upperExists case. michael@0: // (3, 4) hits the !lowerExists/!upperExists case. michael@0: // michael@0: // It'd be a good idea to have a second version of this test at some point michael@0: // where the "array" being reversed is a proxy, to detect proper ordering of michael@0: // getproperty, hasproperty, setproperty into a hole, and deleteproperty from a michael@0: // non-configurable element. But at present our Array.prototype.reverse michael@0: // implementation probably doesn't conform fully to all this (because our michael@0: // internal MOP is still slightly off), so punt for now. michael@0: var props = michael@0: { michael@0: 0: { michael@0: configurable: true, michael@0: get: function() { observed.push("index 0 get"); return "index 0 get"; }, michael@0: set: function(v) { observed.push("index 0 set: " + v); } michael@0: }, michael@0: /* 1: hole */ michael@0: 2: { michael@0: configurable: true, michael@0: get: function() { observed.push("index 2 get"); return "index 2 get"; }, michael@0: set: function(v) { observed.push("index 2 set: " + v); } michael@0: }, michael@0: /* 3: hole */ michael@0: /* 4: hole */ michael@0: /* 5: hole */ michael@0: 6: { michael@0: configurable: true, michael@0: get: function() { observed.push("index 6 get"); return "index 6 get"; }, michael@0: set: function(v) { observed.push("index 6 set: " + v); } michael@0: }, michael@0: 7: { michael@0: configurable: true, michael@0: get: function() { observed.push("index 7 get"); return "index 7 get"; }, michael@0: set: function(v) { observed.push("index 7 set: " + v); } michael@0: }, michael@0: }; michael@0: michael@0: var arr = Object.defineProperties(new Array(8), props); michael@0: michael@0: arr.reverse(); michael@0: michael@0: var expectedObserved = michael@0: ["index 0 get", "index 7 get", "index 0 set: index 7 get", "index 7 set: index 0 get", michael@0: "index 6 get", michael@0: "index 2 get" michael@0: /* nothing for 3/4 */]; michael@0: print(observed); michael@0: // Do this before the assertions below futz even more with |observed|. michael@0: assertEq(observed.length, expectedObserved.length); michael@0: for (var i = 0; i < expectedObserved.length; i++) michael@0: assertEq(observed[i], expectedObserved[i]); michael@0: michael@0: assertEq(arr[0], "index 0 get"); // no deletion, setting doesn't overwrite michael@0: assertEq(arr[1], "index 6 get"); // copies result of getter michael@0: assertEq(2 in arr, false); // deleted michael@0: assertEq(3 in arr, false); // never there michael@0: assertEq(4 in arr, false); // never there michael@0: assertEq(arr[5], "index 2 get"); // copies result of getter michael@0: assertEq(6 in arr, false); // deleted michael@0: assertEq(arr[7], "index 7 get"); // no deletion, setter doesn't overwrite michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");