js/src/tests/ecma/Array/15.4.1.2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Array/15.4.1.2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,128 @@
     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.1.2.js
    1.12 +   ECMA Section:       15.4.1.2 Array(len)
    1.13 +
    1.14 +   Description:        When Array is called as a function rather than as a
    1.15 +   constructor, it creates and initializes a new array
    1.16 +   object.  Thus, the function call Array(...) is
    1.17 +   equivalent to the object creationi new Array(...) with
    1.18 +   the same arguments.
    1.19 +
    1.20 +   An array is created and returned as if by the
    1.21 +   expression new Array(len).
    1.22 +
    1.23 +   Author:             christine@netscape.com
    1.24 +   Date:               7 october 1997
    1.25 +*/
    1.26 +var SECTION = "15.4.1.2";
    1.27 +var VERSION = "ECMA_1";
    1.28 +startTest();
    1.29 +var TITLE   = "Array Constructor Called as a Function:  Array(len)";
    1.30 +
    1.31 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.32 +
    1.33 +new TestCase( SECTION, 
    1.34 +	      "(Array()).length",            
    1.35 +	      0,                             
    1.36 +	      (Array()).length );
    1.37 +
    1.38 +new TestCase( SECTION,
    1.39 +	      "(Array(0)).length",           
    1.40 +	      0,                             
    1.41 +	      (Array(0)).length );
    1.42 +
    1.43 +new TestCase( SECTION,
    1.44 +	      "(Array(1)).length",           
    1.45 +	      1,                             
    1.46 +	      (Array(1)).length );
    1.47 +
    1.48 +new TestCase( SECTION,
    1.49 +	      "(Array(10)).length",          
    1.50 +	      10,                            
    1.51 +	      (Array(10)).length );
    1.52 +
    1.53 +new TestCase( SECTION,
    1.54 +	      "(Array('1')).length",         
    1.55 +	      1,                             
    1.56 +	      (Array('1')).length );
    1.57 +
    1.58 +new TestCase( SECTION,
    1.59 +	      "(Array(1000)).length",        
    1.60 +	      1000,                          
    1.61 +	      (Array(1000)).length );
    1.62 +
    1.63 +new TestCase( SECTION,
    1.64 +	      "(Array('1000')).length",      
    1.65 +	      1,                             
    1.66 +	      (Array('1000')).length );
    1.67 +
    1.68 +new TestCase( SECTION,
    1.69 +	      "(Array(4294967295)).length",  
    1.70 +	      ToUint32(4294967295),          
    1.71 +	      (Array(4294967295)).length );
    1.72 +
    1.73 +new TestCase( SECTION,
    1.74 +	      "(Array(Math.pow(2,31)-1)).length",    
    1.75 +	      ToUint32(Math.pow(2,31)-1),    
    1.76 +	      (Array(Math.pow(2,31)-1)).length );
    1.77 +
    1.78 +new TestCase( SECTION,
    1.79 +	      "(Array(Math.pow(2,31))).length",      
    1.80 +	      ToUint32(Math.pow(2,31)),      
    1.81 +	      (Array(Math.pow(2,31))).length );
    1.82 +
    1.83 +new TestCase( SECTION,
    1.84 +	      "(Array(Math.pow(2,31)+1)).length",    
    1.85 +	      ToUint32(Math.pow(2,31)+1),    
    1.86 +	      (Array(Math.pow(2,31)+1)).length );
    1.87 +
    1.88 +new TestCase( SECTION,
    1.89 +	      "(Array('8589934592')).length",
    1.90 +	      1,                             
    1.91 +	      (Array("8589934592")).length );
    1.92 +
    1.93 +new TestCase( SECTION,
    1.94 +	      "(Array('4294967296')).length",
    1.95 +	      1,                             
    1.96 +	      (Array("4294967296")).length );
    1.97 +
    1.98 +new TestCase( SECTION,
    1.99 +	      "(Array(1073741823)).length",  
   1.100 +	      ToUint32(1073741823),          
   1.101 +	      (Array(1073741823)).length );
   1.102 +
   1.103 +new TestCase( SECTION,
   1.104 +	      "(Array(1073741824)).length",  
   1.105 +	      ToUint32(1073741824),	       
   1.106 +	      (Array(1073741824)).length );
   1.107 +
   1.108 +new TestCase( SECTION,
   1.109 +	      "(Array('a string')).length",  
   1.110 +	      1,                             
   1.111 +	      (Array("a string")).length );
   1.112 +
   1.113 +test();
   1.114 +
   1.115 +function ToUint32( n ) {
   1.116 +  n = Number( n );
   1.117 +  var sign = ( n < 0 ) ? -1 : 1;
   1.118 +
   1.119 +  if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
   1.120 +    return 0;
   1.121 +  }
   1.122 +  n = sign * Math.floor( Math.abs(n) )
   1.123 +
   1.124 +    n = n % Math.pow(2,32);
   1.125 +
   1.126 +  if ( n < 0 ){
   1.127 +    n += Math.pow(2,32);
   1.128 +  }
   1.129 +
   1.130 +  return ( n );
   1.131 +}

mercurial