|
1 | 1 | load("test-common.js");
|
2 | 2 |
|
3 | 3 | try {
|
4 |
| - assert(Array.length === 1); |
5 |
| - assert(Array.name === "Array"); |
6 |
| - assert(Array.prototype.length === 0); |
7 |
| - |
8 |
| - assert(typeof Array() === "object"); |
9 |
| - assert(typeof new Array() === "object"); |
10 |
| - |
11 |
| - var a; |
12 |
| - |
13 |
| - a = new Array(5); |
14 |
| - assert(a.length === 5); |
15 |
| - |
16 |
| - a = new Array("5"); |
17 |
| - assert(a.length === 1); |
18 |
| - assert(a[0] === "5"); |
19 |
| - |
20 |
| - a = new Array(1, 2, 3); |
21 |
| - assert(a.length === 3); |
22 |
| - assert(a[0] === 1); |
23 |
| - assert(a[1] === 2); |
24 |
| - assert(a[2] === 3); |
25 |
| - |
26 |
| - a = new Array([1, 2, 3]); |
27 |
| - assert(a.length === 1); |
28 |
| - assert(a[0][0] === 1); |
29 |
| - assert(a[0][1] === 2); |
30 |
| - assert(a[0][2] === 3); |
31 |
| - |
32 |
| - a = new Array(1, 2, 3); |
33 |
| - Object.defineProperty(a, 3, { |
34 |
| - get() { |
35 |
| - return 10; |
36 |
| - }, |
37 |
| - }); |
38 |
| - assert(a.toString() === "1,2,3,10"); |
39 |
| - |
40 |
| - [-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => { |
41 |
| - assertThrowsError( |
42 |
| - () => { |
43 |
| - new Array(value); |
44 |
| - }, |
45 |
| - { |
46 |
| - error: TypeError, |
47 |
| - message: "Invalid array length", |
48 |
| - } |
49 |
| - ); |
50 |
| - }); |
51 |
| - |
52 |
| - console.log("PASS"); |
| 4 | + assert(Array.length === 1); |
| 5 | + assert(Array.name === "Array"); |
| 6 | + assert(Array.prototype.length === 0); |
| 7 | + |
| 8 | + assert(typeof Array() === "object"); |
| 9 | + assert(typeof new Array() === "object"); |
| 10 | + |
| 11 | + var a; |
| 12 | + |
| 13 | + a = new Array(5); |
| 14 | + assert(a.length === 5); |
| 15 | + |
| 16 | + a = new Array("5"); |
| 17 | + assert(a.length === 1); |
| 18 | + assert(a[0] === "5"); |
| 19 | + |
| 20 | + a = new Array(1, 2, 3); |
| 21 | + assert(a.length === 3); |
| 22 | + assert(a[0] === 1); |
| 23 | + assert(a[1] === 2); |
| 24 | + assert(a[2] === 3); |
| 25 | + |
| 26 | + a = new Array([1, 2, 3]); |
| 27 | + assert(a.length === 1); |
| 28 | + assert(a[0][0] === 1); |
| 29 | + assert(a[0][1] === 2); |
| 30 | + assert(a[0][2] === 3); |
| 31 | + |
| 32 | + a = new Array(1, 2, 3); |
| 33 | + Object.defineProperty(a, 3, { |
| 34 | + get() { |
| 35 | + return 10; |
| 36 | + }, |
| 37 | + }); |
| 38 | + assert(a.toString() === "1,2,3,10"); |
| 39 | + |
| 40 | + [-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => { |
| 41 | + assertThrowsError( |
| 42 | + () => { |
| 43 | + new Array(value); |
| 44 | + }, |
| 45 | + { |
| 46 | + error: TypeError, |
| 47 | + message: "Invalid array length", |
| 48 | + } |
| 49 | + ); |
| 50 | + }); |
| 51 | + |
| 52 | + console.log("PASS"); |
53 | 53 | } catch (e) {
|
54 |
| - console.log("FAIL: " + e); |
| 54 | + console.log("FAIL: " + e); |
55 | 55 | }
|
0 commit comments