js/src/tests/ecma_5/Array/reverse-order-of-low-high-accesses.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 = 858677;
michael@0 8 var summary =
michael@0 9 "[].reverse should swap elements low to high using accesses to low " +
michael@0 10 "elements, then accesses to high elements";
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 observed = [];
michael@0 19
michael@0 20 // (0, 7) hits the lowerExists/upperExists case.
michael@0 21 // (1, 6) hits the !lowerExists/upperExists case.
michael@0 22 // (2, 5) hits the lowerExists/!upperExists case.
michael@0 23 // (3, 4) hits the !lowerExists/!upperExists case.
michael@0 24 //
michael@0 25 // It'd be a good idea to have a second version of this test at some point
michael@0 26 // where the "array" being reversed is a proxy, to detect proper ordering of
michael@0 27 // getproperty, hasproperty, setproperty into a hole, and deleteproperty from a
michael@0 28 // non-configurable element. But at present our Array.prototype.reverse
michael@0 29 // implementation probably doesn't conform fully to all this (because our
michael@0 30 // internal MOP is still slightly off), so punt for now.
michael@0 31 var props =
michael@0 32 {
michael@0 33 0: {
michael@0 34 configurable: true,
michael@0 35 get: function() { observed.push("index 0 get"); return "index 0 get"; },
michael@0 36 set: function(v) { observed.push("index 0 set: " + v); }
michael@0 37 },
michael@0 38 /* 1: hole */
michael@0 39 2: {
michael@0 40 configurable: true,
michael@0 41 get: function() { observed.push("index 2 get"); return "index 2 get"; },
michael@0 42 set: function(v) { observed.push("index 2 set: " + v); }
michael@0 43 },
michael@0 44 /* 3: hole */
michael@0 45 /* 4: hole */
michael@0 46 /* 5: hole */
michael@0 47 6: {
michael@0 48 configurable: true,
michael@0 49 get: function() { observed.push("index 6 get"); return "index 6 get"; },
michael@0 50 set: function(v) { observed.push("index 6 set: " + v); }
michael@0 51 },
michael@0 52 7: {
michael@0 53 configurable: true,
michael@0 54 get: function() { observed.push("index 7 get"); return "index 7 get"; },
michael@0 55 set: function(v) { observed.push("index 7 set: " + v); }
michael@0 56 },
michael@0 57 };
michael@0 58
michael@0 59 var arr = Object.defineProperties(new Array(8), props);
michael@0 60
michael@0 61 arr.reverse();
michael@0 62
michael@0 63 var expectedObserved =
michael@0 64 ["index 0 get", "index 7 get", "index 0 set: index 7 get", "index 7 set: index 0 get",
michael@0 65 "index 6 get",
michael@0 66 "index 2 get"
michael@0 67 /* nothing for 3/4 */];
michael@0 68 print(observed);
michael@0 69 // Do this before the assertions below futz even more with |observed|.
michael@0 70 assertEq(observed.length, expectedObserved.length);
michael@0 71 for (var i = 0; i < expectedObserved.length; i++)
michael@0 72 assertEq(observed[i], expectedObserved[i]);
michael@0 73
michael@0 74 assertEq(arr[0], "index 0 get"); // no deletion, setting doesn't overwrite
michael@0 75 assertEq(arr[1], "index 6 get"); // copies result of getter
michael@0 76 assertEq(2 in arr, false); // deleted
michael@0 77 assertEq(3 in arr, false); // never there
michael@0 78 assertEq(4 in arr, false); // never there
michael@0 79 assertEq(arr[5], "index 2 get"); // copies result of getter
michael@0 80 assertEq(6 in arr, false); // deleted
michael@0 81 assertEq(arr[7], "index 7 get"); // no deletion, setter doesn't overwrite
michael@0 82
michael@0 83 /******************************************************************************/
michael@0 84
michael@0 85 if (typeof reportCompare === "function")
michael@0 86 reportCompare(true, true);
michael@0 87
michael@0 88 print("Tests complete");

mercurial