Debian Codegraph @

rhino/testsrc/tests/ecma/Array/15.4.5.2-2.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '15.4.5.2-2.js';
7
8 /**
9 File Name: 15.4.5.2-2.js
10 ECMA Section: Array.length
11 Description:
12 15.4.5.2 length
13 The length property of this Array object is always numerically greater
14 than the name of every property whose name is an array index.
15
16 The length property has the attributes { DontEnum, DontDelete }.
17
18 This test verifies that the Array.length property is not Read Only.
19
20 Author: [email protected]
21 Date: 12 november 1997
22 */
23
24 var SECTION = "15.4.5.2-2";
25 var VERSION = "ECMA_1";
26 startTest();
27 var TITLE = "Array.length";
28
29 writeHeaderToLog( SECTION + " "+ TITLE);
30
31 addCase( new Array(), 0, Math.pow(2,14), Math.pow(2,14) );
32
33 addCase( new Array(), 0, 1, 1 );
34
35 addCase( new Array(Math.pow(2,12)), Math.pow(2,12), 0, 0 );
36 addCase( new Array(Math.pow(2,13)), Math.pow(2,13), Math.pow(2,12), Math.pow(2,12) );
37 addCase( new Array(Math.pow(2,12)), Math.pow(2,12), Math.pow(2,12), Math.pow(2,12) );
38 addCase( new Array(Math.pow(2,14)), Math.pow(2,14), Math.pow(2,12), Math.pow(2,12) )
39
40 // some tests where array is not empty
41 // array is populated with strings
42 for ( var arg = "", i = 0; i < Math.pow(2,12); i++ ) {
43 arg += String(i) + ( i != Math.pow(2,12)-1 ? "," : "" );
44
45 }
46 // print(i +":"+arg);
47
48 var a = eval( "new Array("+arg+")" );
49
50 addCase( a, i, i, i );
51 addCase( a, i, Math.pow(2,12)+i+1, Math.pow(2,12)+i+1, true );
52 addCase( a, Math.pow(2,12)+5, 0, 0, true );
53
54 test();
55
56 function addCase( object, old_len, set_len, new_len, checkitems ) {
57 object.length = set_len;
58
59 new TestCase( SECTION,
60 "array = new Array("+ old_len+"); array.length = " + set_len +
61 "; array.length",
62 new_len,
63 object.length );
64
65 if ( checkitems ) {
66 // verify that items between old and newlen are all undefined
67 if ( new_len < old_len ) {
68 var passed = true;
69 for ( var i = new_len; i < old_len; i++ ) {
70 if ( object[i] != void 0 ) {
71 passed = false;
72 }
73 }
74 new TestCase( SECTION,
75 "verify that array items have been deleted",
76 true,
77 passed );
78 }
79 if ( new_len > old_len ) {
80 var passed = true;
81 for ( var i = old_len; i < new_len; i++ ) {
82 if ( object[i] != void 0 ) {
83 passed = false;
84 }
85 }
86 new TestCase( SECTION,
87 "verify that new items are undefined",
88 true,
89 passed );
90 }
91 }
92
93 }
94