js/src/tests/ecma/Array/15.4.1.1.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.1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     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.1.js
    1.12 +   ECMA Section:       15.4.1 Array( item0, item1,... )
    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 creation new Array(...) with
    1.18 +   the same arguments.
    1.19 +
    1.20 +   An array is created and returned as if by the expression
    1.21 +   new Array( item0, item1, ... ).
    1.22 +
    1.23 +   Author:             christine@netscape.com
    1.24 +   Date:               7 october 1997
    1.25 +*/
    1.26 +var SECTION = "15.4.1.1";
    1.27 +var VERSION = "ECMA_1";
    1.28 +startTest();
    1.29 +var TITLE   = "Array Constructor Called as a Function";
    1.30 +
    1.31 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.32 +
    1.33 +new TestCase( SECTION,
    1.34 +	      "typeof Array(1,2)",       
    1.35 +	      "object",          
    1.36 +	      typeof Array(1,2) );
    1.37 +
    1.38 +new TestCase( SECTION,
    1.39 +	      "(Array(1,2)).toString",   
    1.40 +	      Array.prototype.toString,   
    1.41 +	      (Array(1,2)).toString );
    1.42 +
    1.43 +new TestCase( SECTION,
    1.44 +	      "var arr = Array(1,2,3); arr.toString = Object.prototype.toString; arr.toString()",
    1.45 +	      "[object Array]",
    1.46 +	      eval("var arr = Array(1,2,3); arr.toString = Object.prototype.toString; arr.toString()") );
    1.47 +
    1.48 +new TestCase( SECTION,
    1.49 +	      "(Array(1,2)).length",     
    1.50 +	      2,                 
    1.51 +	      (Array(1,2)).length );
    1.52 +
    1.53 +new TestCase( SECTION,
    1.54 +	      "var arr = (Array(1,2)); arr[0]", 
    1.55 +	      1,          
    1.56 +	      eval("var arr = (Array(1,2)); arr[0]") );
    1.57 +
    1.58 +new TestCase( SECTION,
    1.59 +	      "var arr = (Array(1,2)); arr[1]", 
    1.60 +	      2,          
    1.61 +	      eval("var arr = (Array(1,2)); arr[1]") );
    1.62 +
    1.63 +new TestCase( SECTION,
    1.64 +	      "var arr = (Array(1,2)); String(arr)", 
    1.65 +	      "1,2", 
    1.66 +	      eval("var arr = (Array(1,2)); String(arr)") );
    1.67 +
    1.68 +test();
    1.69 +
    1.70 +function ToUint32( n ) {
    1.71 +  n = Number( n );
    1.72 +  if( isNaN(n) || n == 0 || n == Number.POSITIVE_INFINITY ||
    1.73 +      n == Number.NEGATIVE_INFINITY ) {
    1.74 +    return 0;
    1.75 +  }
    1.76 +  var sign = n < 0 ? -1 : 1;
    1.77 +
    1.78 +  return ( sign * ( n * Math.floor( Math.abs(n) ) ) ) % Math.pow(2, 32);
    1.79 +}
    1.80 +

mercurial