1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Array/15.4.2.2-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 15.4.2.2-1.js 1.12 + ECMA Section: 15.4.2.2 new Array(len) 1.13 + 1.14 + Description: This description only applies of the constructor is 1.15 + given two or more arguments. 1.16 + 1.17 + The [[Prototype]] property of the newly constructed 1.18 + object is set to the original Array prototype object, 1.19 + the one that is the initial value of Array.prototype(0) 1.20 + (15.4.3.1). 1.21 + 1.22 + The [[Class]] property of the newly constructed object 1.23 + is set to "Array". 1.24 + 1.25 + If the argument len is a number, then the length 1.26 + property of the newly constructed object is set to 1.27 + ToUint32(len). 1.28 + 1.29 + If the argument len is not a number, then the length 1.30 + property of the newly constructed object is set to 1 1.31 + and the 0 property of the newly constructed object is 1.32 + set to len. 1.33 + 1.34 + This file tests cases where len is a number. 1.35 + 1.36 + The cases in this test need to be updated since the 1.37 + ToUint32_t description has changed. 1.38 + 1.39 + Author: christine@netscape.com 1.40 + Date: 7 october 1997 1.41 +*/ 1.42 +var SECTION = "15.4.2.2-1"; 1.43 +var VERSION = "ECMA_1"; 1.44 +startTest(); 1.45 +var TITLE = "The Array Constructor: new Array( len )"; 1.46 + 1.47 +writeHeaderToLog( SECTION + " "+ TITLE); 1.48 + 1.49 +new TestCase( SECTION, 1.50 + "new Array(0)", 1.51 + "", 1.52 + (new Array(0)).toString() ); 1.53 + 1.54 +new TestCase( SECTION, 1.55 + "typeof new Array(0)", 1.56 + "object", 1.57 + (typeof new Array(0)) ); 1.58 + 1.59 +new TestCase( SECTION, 1.60 + "(new Array(0)).length", 1.61 + 0, 1.62 + (new Array(0)).length ); 1.63 + 1.64 +new TestCase( SECTION, 1.65 + "(new Array(0)).toString", 1.66 + Array.prototype.toString, 1.67 + (new Array(0)).toString ); 1.68 + 1.69 +new TestCase( SECTION, 1.70 + "new Array(1)", 1.71 + "", 1.72 + (new Array(1)).toString() ); 1.73 + 1.74 +new TestCase( SECTION, 1.75 + "new Array(1).length", 1.76 + 1, 1.77 + (new Array(1)).length ); 1.78 + 1.79 +new TestCase( SECTION, 1.80 + "(new Array(1)).toString", 1.81 + Array.prototype.toString, 1.82 + (new Array(1)).toString ); 1.83 + 1.84 +new TestCase( SECTION, 1.85 + "(new Array(-0)).length", 1.86 + 0, 1.87 + (new Array(-0)).length ); 1.88 + 1.89 +new TestCase( SECTION, 1.90 + "(new Array(0)).length", 1.91 + 0, 1.92 + (new Array(0)).length ); 1.93 + 1.94 +new TestCase( SECTION, 1.95 + "(new Array(10)).length", 1.96 + 10, 1.97 + (new Array(10)).length ); 1.98 + 1.99 +new TestCase( SECTION, 1.100 + "(new Array('1')).length", 1.101 + 1, 1.102 + (new Array('1')).length ); 1.103 + 1.104 +new TestCase( SECTION, 1.105 + "(new Array(1000)).length", 1.106 + 1000, 1.107 + (new Array(1000)).length ); 1.108 + 1.109 +new TestCase( SECTION, 1.110 + "(new Array('1000')).length", 1.111 + 1, 1.112 + (new Array('1000')).length ); 1.113 + 1.114 +new TestCase( SECTION, 1.115 + "(new Array(4294967295)).length", 1.116 + ToUint32(4294967295), 1.117 + (new Array(4294967295)).length ); 1.118 + 1.119 +new TestCase( SECTION, 1.120 + "(new Array('8589934592')).length", 1.121 + 1, 1.122 + (new Array("8589934592")).length ); 1.123 + 1.124 +new TestCase( SECTION, 1.125 + "(new Array('4294967296')).length", 1.126 + 1, 1.127 + (new Array("4294967296")).length ); 1.128 + 1.129 +new TestCase( SECTION, 1.130 + "(new Array(1073741824)).length", 1.131 + ToUint32(1073741824), 1.132 + (new Array(1073741824)).length ); 1.133 + 1.134 +test(); 1.135 + 1.136 +function ToUint32( n ) { 1.137 + n = Number( n ); 1.138 + var sign = ( n < 0 ) ? -1 : 1; 1.139 + 1.140 + if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) { 1.141 + return 0; 1.142 + } 1.143 + n = sign * Math.floor( Math.abs(n) ) 1.144 + 1.145 + n = n % Math.pow(2,32); 1.146 + 1.147 + if ( n < 0 ){ 1.148 + n += Math.pow(2,32); 1.149 + } 1.150 + 1.151 + return ( n ); 1.152 +}