js/src/tests/ecma/Array/15.4.2.2-1.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     7 /**
     8    File Name:          15.4.2.2-1.js
     9    ECMA Section:       15.4.2.2 new Array(len)
    11    Description:        This description only applies of the constructor is
    12    given two or more arguments.
    14    The [[Prototype]] property of the newly constructed
    15    object is set to the original Array prototype object,
    16    the one that is the initial value of Array.prototype(0)
    17    (15.4.3.1).
    19    The [[Class]] property of the newly constructed object
    20    is set to "Array".
    22    If the argument len is a number, then the length
    23    property  of the newly constructed object is set to
    24    ToUint32(len).
    26    If the argument len is not a number, then the length
    27    property of the newly constructed object is set to 1
    28    and the 0 property of the newly constructed object is
    29    set to len.
    31    This file tests cases where len is a number.
    33    The cases in this test need to be updated since the
    34    ToUint32_t description has changed.
    36    Author:             christine@netscape.com
    37    Date:               7 october 1997
    38 */
    39 var SECTION = "15.4.2.2-1";
    40 var VERSION = "ECMA_1";
    41 startTest();
    42 var TITLE   = "The Array Constructor:  new Array( len )";
    44 writeHeaderToLog( SECTION + " "+ TITLE);
    46 new TestCase( SECTION,
    47 	      "new Array(0)",            
    48 	      "",                
    49 	      (new Array(0)).toString() );
    51 new TestCase( SECTION,
    52 	      "typeof new Array(0)",     
    53 	      "object",          
    54 	      (typeof new Array(0)) );
    56 new TestCase( SECTION,
    57 	      "(new Array(0)).length",   
    58 	      0,                 
    59 	      (new Array(0)).length );
    61 new TestCase( SECTION,
    62 	      "(new Array(0)).toString",
    63 	      Array.prototype.toString,   
    64 	      (new Array(0)).toString );
    66 new TestCase( SECTION,  
    67 	      "new Array(1)",           
    68 	      "",                
    69 	      (new Array(1)).toString() );
    71 new TestCase( SECTION,  
    72 	      "new Array(1).length",    
    73 	      1,                 
    74 	      (new Array(1)).length );
    76 new TestCase( SECTION,  
    77 	      "(new Array(1)).toString",
    78 	      Array.prototype.toString,  
    79 	      (new Array(1)).toString );
    81 new TestCase( SECTION,
    82 	      "(new Array(-0)).length",                      
    83 	      0, 
    84 	      (new Array(-0)).length );
    86 new TestCase( SECTION,
    87 	      "(new Array(0)).length",                       
    88 	      0, 
    89 	      (new Array(0)).length );
    91 new TestCase( SECTION,
    92 	      "(new Array(10)).length",          
    93 	      10,        
    94 	      (new Array(10)).length );
    96 new TestCase( SECTION,
    97 	      "(new Array('1')).length",         
    98 	      1,         
    99 	      (new Array('1')).length );
   101 new TestCase( SECTION,
   102 	      "(new Array(1000)).length",        
   103 	      1000,      
   104 	      (new Array(1000)).length );
   106 new TestCase( SECTION,
   107 	      "(new Array('1000')).length",      
   108 	      1,         
   109 	      (new Array('1000')).length );
   111 new TestCase( SECTION,
   112 	      "(new Array(4294967295)).length",  
   113 	      ToUint32(4294967295),  
   114 	      (new Array(4294967295)).length );
   116 new TestCase( SECTION,
   117 	      "(new Array('8589934592')).length",
   118 	      1,                     
   119 	      (new Array("8589934592")).length );
   121 new TestCase( SECTION,
   122 	      "(new Array('4294967296')).length",
   123 	      1,                     
   124 	      (new Array("4294967296")).length );
   126 new TestCase( SECTION,
   127 	      "(new Array(1073741824)).length",  
   128 	      ToUint32(1073741824),
   129 	      (new Array(1073741824)).length );
   131 test();
   133 function ToUint32( n ) {
   134   n = Number( n );
   135   var sign = ( n < 0 ) ? -1 : 1;
   137   if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
   138     return 0;
   139   }
   140   n = sign * Math.floor( Math.abs(n) )
   142     n = n % Math.pow(2,32);
   144   if ( n < 0 ){
   145     n += Math.pow(2,32);
   146   }
   148   return ( n );
   149 }

mercurial