]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* The contents of this file are subject to the Netscape Public |
2 | * License Version 1.1 (the "License"); you may not use this file | |
3 | * except in compliance with the License. You may obtain a copy of | |
4 | * the License at http://www.mozilla.org/NPL/ | |
5 | * | |
6 | * Software distributed under the License is distributed on an "AS | |
7 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
8 | * implied. See the License for the specific language governing | |
9 | * rights and limitations under the License. | |
10 | * | |
11 | * The Original Code is Mozilla Communicator client code, released March | |
12 | * 31, 1998. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Netscape Communications | |
15 | * Corporation. Portions created by Netscape are | |
16 | * Copyright (C) 1998 Netscape Communications Corporation. All | |
17 | * Rights Reserved. | |
18 | * | |
19 | * Contributor(s): | |
20 | * | |
21 | */ | |
22 | /** | |
23 | File Name: 15.4.2.1-1.js | |
24 | ECMA Section: 15.4.2.1 new Array( item0, item1, ... ) | |
25 | Description: This description only applies of the constructor is | |
26 | given two or more arguments. | |
27 | ||
28 | The [[Prototype]] property of the newly constructed | |
29 | object is set to the original Array prototype object, | |
30 | the one that is the initial value of Array.prototype | |
31 | (15.4.3.1). | |
32 | ||
33 | The [[Class]] property of the newly constructed object | |
34 | is set to "Array". | |
35 | ||
36 | The length property of the newly constructed object is | |
37 | set to the number of arguments. | |
38 | ||
39 | The 0 property of the newly constructed object is set | |
40 | to item0... in general, for as many arguments as there | |
41 | are, the k property of the newly constructed object is | |
42 | set to argument k, where the first argument is | |
43 | considered to be argument number 0. | |
44 | ||
45 | This file tests the typeof the newly constructed object. | |
46 | ||
47 | Author: christine@netscape.com | |
48 | Date: 7 october 1997 | |
49 | */ | |
50 | ||
51 | var SECTION = "15.4.2.1-1"; | |
52 | var VERSION = "ECMA_1"; | |
53 | startTest(); | |
54 | var TITLE = "The Array Constructor: new Array( item0, item1, ...)"; | |
55 | ||
56 | writeHeaderToLog( SECTION + " "+ TITLE); | |
57 | ||
58 | var testcases = getTestCases(); | |
59 | test(); | |
60 | ||
61 | ||
62 | function getTestCases() { | |
63 | var array = new Array(); | |
64 | var item = 0; | |
65 | ||
66 | array[item++] = new TestCase( SECTION, "typeof new Array(1,2)", "object", typeof new Array(1,2) ); | |
67 | array[item++] = new TestCase( SECTION, "(new Array(1,2)).toString", Array.prototype.toString, (new Array(1,2)).toString ); | |
68 | array[item++] = new TestCase( SECTION, | |
69 | "var arr = new Array(1,2,3); arr.getClass = Object.prototype.toString; arr.getClass()", | |
70 | "[object Array]", | |
71 | eval("var arr = new Array(1,2,3); arr.getClass = Object.prototype.toString; arr.getClass()") ); | |
72 | ||
73 | array[item++] = new TestCase( SECTION, "(new Array(1,2)).length", 2, (new Array(1,2)).length ); | |
74 | array[item++] = new TestCase( SECTION, "var arr = (new Array(1,2)); arr[0]", 1, eval("var arr = (new Array(1,2)); arr[0]") ); | |
75 | array[item++] = new TestCase( SECTION, "var arr = (new Array(1,2)); arr[1]", 2, eval("var arr = (new Array(1,2)); arr[1]") ); | |
76 | array[item++] = new TestCase( SECTION, "var arr = (new Array(1,2)); String(arr)", "1,2", eval("var arr = (new Array(1,2)); String(arr)") ); | |
77 | ||
78 | return ( array ); | |
79 | } | |
80 | function test() { | |
81 | for ( tc=0; tc < testcases.length; tc++ ) { | |
82 | testcases[tc].passed = writeTestCaseResult( | |
83 | testcases[tc].expect, | |
84 | testcases[tc].actual, | |
85 | testcases[tc].description +" = "+ | |
86 | testcases[tc].actual ); | |
87 | ||
88 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
89 | } | |
90 | stopTest(); | |
91 | return ( testcases ); | |
92 | } |