| 1 |
// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
|
| 5 |
// test various array methods with sparse arrays |
| 6 |
js> var x = [] |
| 7 |
|
| 8 |
js> x.length = 101 |
| 9 |
101 |
| 10 |
js> x[100] = 1 |
| 11 |
1 |
| 12 |
js> x.length |
| 13 |
101 |
| 14 |
js> 0 in x |
| 15 |
false |
| 16 |
js> x.shift() |
| 17 |
js> x.length |
| 18 |
100 |
| 19 |
js> 0 in x |
| 20 |
false |
| 21 |
js> x |
| 22 |
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 |
| 23 |
js> x.reverse() |
| 24 |
1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
| 25 |
js> x.length |
| 26 |
100 |
| 27 |
js> 10 in x |
| 28 |
false |
| 29 |
js> x.reverse() |
| 30 |
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 |
| 31 |
js> x.length |
| 32 |
100 |
| 33 |
js> 10 in x |
| 34 |
false |
| 35 |
js> x.unshift(2) |
| 36 |
101 |
| 37 |
js> x |
| 38 |
2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 |
| 39 |
js> 10 in x |
| 40 |
false |
| 41 |
js> var r = x.splice(50, 5, 3, 4, 5) |
| 42 |
js> r |
| 43 |
,,,, |
| 44 |
js> r.length |
| 45 |
5 |
| 46 |
js> 3 in r |
| 47 |
false |
| 48 |
js> x.length |
| 49 |
99 |
| 50 |
js> x |
| 51 |
2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3,4,5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 |
| 52 |
js> x[50] |
| 53 |
3 |
| 54 |
js> 10 in x |
| 55 |
false |
| 56 |
js> var s = x.slice(60, 70); |
| 57 |
js> s |
| 58 |
,,,,,,,,, |
| 59 |
js> s.length |
| 60 |
10 |
| 61 |
js> 5 in s |
| 62 |
false |
| 63 |
js> var y = [] |
| 64 |
js> y.length = 100 |
| 65 |
100 |
| 66 |
js> var z = y.concat(x) |
| 67 |
js> z.length |
| 68 |
199 |
| 69 |
js> 30 in z |
| 70 |
false |
| 71 |
js> 130 in z |
| 72 |
false |
| 73 |
|