|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 */ |
|
5 |
|
6 //----------------------------------------------------------------------------- |
|
7 var BUGNUMBER = 909602; |
|
8 var summary = |
|
9 "Array.prototype.pop shouldn't touch elements greater than length on " + |
|
10 "non-arrays"; |
|
11 |
|
12 print(BUGNUMBER + ": " + summary); |
|
13 |
|
14 /************** |
|
15 * BEGIN TEST * |
|
16 **************/ |
|
17 |
|
18 function doTest(obj, index) |
|
19 { |
|
20 // print("testing " + JSON.stringify(obj) + " with index " + index); |
|
21 assertEq(Array.prototype.pop.call(obj), undefined); |
|
22 assertEq(index in obj, true); |
|
23 assertEq(obj[index], 42); |
|
24 } |
|
25 |
|
26 // not-super-much-later element |
|
27 |
|
28 // non-zero length |
|
29 function testPop1() |
|
30 { |
|
31 var obj = { length: 2, 3: 42 }; |
|
32 doTest(obj, 3); |
|
33 } |
|
34 for (var i = 0; i < 50; i++) |
|
35 testPop1(); |
|
36 |
|
37 // zero length |
|
38 function testPop2() |
|
39 { |
|
40 var obj = { length: 0, 3: 42 }; |
|
41 doTest(obj, 3); |
|
42 } |
|
43 for (var i = 0; i < 50; i++) |
|
44 testPop2(); |
|
45 |
|
46 // much-later (but dense) element |
|
47 |
|
48 // non-zero length |
|
49 function testPop3() |
|
50 { |
|
51 var obj = { length: 2, 55: 42 }; |
|
52 doTest(obj, 55); |
|
53 } |
|
54 for (var i = 0; i < 50; i++) |
|
55 testPop3(); |
|
56 |
|
57 // zero length |
|
58 function testPop4() |
|
59 { |
|
60 var obj = { length: 0, 55: 42 }; |
|
61 doTest(obj, 55); |
|
62 } |
|
63 for (var i = 0; i < 50; i++) |
|
64 testPop4(); |
|
65 |
|
66 // much much much later (sparse) element |
|
67 |
|
68 // non-zero length |
|
69 function testPop5() |
|
70 { |
|
71 var obj = { length: 2, 65530: 42 }; |
|
72 doTest(obj, 65530); |
|
73 } |
|
74 for (var i = 0; i < 50; i++) |
|
75 testPop5(); |
|
76 |
|
77 // zero length |
|
78 function testPop6() |
|
79 { |
|
80 var obj = { length: 0, 65530: 42 }; |
|
81 doTest(obj, 65530); |
|
82 } |
|
83 for (var i = 0; i < 50; i++) |
|
84 testPop6(); |
|
85 |
|
86 /******************************************************************************/ |
|
87 |
|
88 if (typeof reportCompare === "function") |
|
89 reportCompare(true, true); |
|
90 |
|
91 print("Tests complete"); |