]>
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.5.2-2.js | |
24 | ECMA Section: Array.length | |
25 | Description: | |
26 | 15.4.5.2 length | |
27 | The length property of this Array object is always numerically greater | |
28 | than the name of every property whose name is an array index. | |
29 | ||
30 | The length property has the attributes { DontEnum, DontDelete }. | |
31 | ||
32 | This test verifies that the Array.length property is not Read Only. | |
33 | ||
34 | Author: christine@netscape.com | |
35 | Date: 12 november 1997 | |
36 | */ | |
37 | ||
38 | var SECTION = "15.4.5.2-2"; | |
39 | var VERSION = "ECMA_1"; | |
40 | startTest(); | |
41 | var TITLE = "Array.length"; | |
42 | ||
43 | writeHeaderToLog( SECTION + " "+ TITLE); | |
44 | ||
45 | var testcases = new Array(); | |
46 | ||
47 | addCase( new Array(), 0, Math.pow(2,14), Math.pow(2,14) ); | |
48 | ||
49 | addCase( new Array(), 0, 1, 1 ); | |
50 | ||
51 | addCase( new Array(Math.pow(2,12)), Math.pow(2,12), 0, 0 ); | |
52 | addCase( new Array(Math.pow(2,13)), Math.pow(2,13), Math.pow(2,12), Math.pow(2,12) ); | |
53 | addCase( new Array(Math.pow(2,12)), Math.pow(2,12), Math.pow(2,12), Math.pow(2,12) ); | |
54 | addCase( new Array(Math.pow(2,14)), Math.pow(2,14), Math.pow(2,12), Math.pow(2,12) ) | |
55 | ||
56 | // some tests where array is not empty | |
57 | // array is populated with strings | |
58 | for ( var arg = "", i = 0; i < Math.pow(2,12); i++ ) { | |
59 | arg += String(i) + ( i != Math.pow(2,12)-1 ? "," : "" ); | |
60 | ||
61 | } | |
62 | // print(i +":"+arg); | |
63 | ||
64 | var a = eval( "new Array("+arg+")" ); | |
65 | ||
66 | addCase( a, i, i, i ); | |
67 | addCase( a, i, Math.pow(2,12)+i+1, Math.pow(2,12)+i+1, true ); | |
68 | addCase( a, Math.pow(2,12)+5, 0, 0, true ); | |
69 | ||
70 | test(); | |
71 | ||
72 | function addCase( object, old_len, set_len, new_len, checkitems ) { | |
73 | object.length = set_len; | |
74 | ||
75 | testcases[testcases.length] = new TestCase( SECTION, | |
76 | "array = new Array("+ old_len+"); array.length = " + set_len + | |
77 | "; array.length", | |
78 | new_len, | |
79 | object.length ); | |
80 | ||
81 | if ( checkitems ) { | |
82 | // verify that items between old and newlen are all undefined | |
83 | if ( new_len < old_len ) { | |
84 | var passed = true; | |
85 | for ( var i = new_len; i < old_len; i++ ) { | |
86 | if ( object[i] != void 0 ) { | |
87 | passed = false; | |
88 | } | |
89 | } | |
90 | testcases[testcases.length] = new TestCase( SECTION, | |
91 | "verify that array items have been deleted", | |
92 | true, | |
93 | passed ); | |
94 | } | |
95 | if ( new_len > old_len ) { | |
96 | var passed = true; | |
97 | for ( var i = old_len; i < new_len; i++ ) { | |
98 | if ( object[i] != void 0 ) { | |
99 | passed = false; | |
100 | } | |
101 | } | |
102 | testcases[testcases.length] = new TestCase( SECTION, | |
103 | "verify that new items are undefined", | |
104 | true, | |
105 | passed ); | |
106 | } | |
107 | } | |
108 | ||
109 | } | |
110 | ||
111 | function test() { | |
112 | for ( tc=0; tc < testcases.length; tc++ ) { | |
113 | testcases[tc].passed = writeTestCaseResult( | |
114 | testcases[tc].expect, | |
115 | testcases[tc].actual, | |
116 | testcases[tc].description +" = "+ | |
117 | testcases[tc].actual ); | |
118 | ||
119 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
120 | } | |
121 | stopTest(); | |
122 | return ( testcases ); | |
123 | } |