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