~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/lang/js/test/ecma/Array/15.4.1.1.js

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Mozilla Public License Version
 
6
 * 1.1 (the "License"); you may not use this file except in compliance with
 
7
 * the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/MPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is Mozilla Communicator client code, released
 
16
 * March 31, 1998.
 
17
 *
 
18
 * The Initial Developer of the Original Code is
 
19
 * Netscape Communications Corporation.
 
20
 * Portions created by the Initial Developer are Copyright (C) 1998
 
21
 * the Initial Developer. All Rights Reserved.
 
22
 *
 
23
 * Contributor(s):
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the MPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the MPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
/**
 
40
   File Name:          15.4.1.1.js
 
41
   ECMA Section:       15.4.1 Array( item0, item1,... )
 
42
 
 
43
   Description:        When Array is called as a function rather than as a
 
44
   constructor, it creates and initializes a new array
 
45
   object.  Thus, the function call Array(...) is
 
46
   equivalent to the object creation new Array(...) with
 
47
   the same arguments.
 
48
 
 
49
   An array is created and returned as if by the expression
 
50
   new Array( item0, item1, ... ).
 
51
 
 
52
   Author:             christine@netscape.com
 
53
   Date:               7 october 1997
 
54
*/
 
55
var SECTION = "15.4.1.1";
 
56
var VERSION = "ECMA_1";
 
57
startTest();
 
58
var TITLE   = "Array Constructor Called as a Function";
 
59
 
 
60
writeHeaderToLog( SECTION + " "+ TITLE);
 
61
 
 
62
new TestCase( SECTION,  
 
63
              "typeof Array(1,2)",        
 
64
              "object",           
 
65
              typeof Array(1,2) );
 
66
 
 
67
new TestCase( SECTION,  
 
68
              "(Array(1,2)).toString",    
 
69
              Array.prototype.toString,    
 
70
              (Array(1,2)).toString );
 
71
 
 
72
new TestCase( SECTION,
 
73
              "var arr = Array(1,2,3); arr.toString = Object.prototype.toString; arr.toString()",
 
74
              "[object Array]",
 
75
              eval("var arr = Array(1,2,3); arr.toString = Object.prototype.toString; arr.toString()") );
 
76
 
 
77
new TestCase( SECTION,  
 
78
              "(Array(1,2)).length",      
 
79
              2,                  
 
80
              (Array(1,2)).length );
 
81
 
 
82
new TestCase( SECTION,  
 
83
              "var arr = (Array(1,2)); arr[0]",  
 
84
              1,           
 
85
              eval("var arr = (Array(1,2)); arr[0]") );
 
86
 
 
87
new TestCase( SECTION,  
 
88
              "var arr = (Array(1,2)); arr[1]",  
 
89
              2,           
 
90
              eval("var arr = (Array(1,2)); arr[1]") );
 
91
 
 
92
new TestCase( SECTION,  
 
93
              "var arr = (Array(1,2)); String(arr)",  
 
94
              "1,2",  
 
95
              eval("var arr = (Array(1,2)); String(arr)") );
 
96
 
 
97
test();
 
98
 
 
99
function ToUint32( n ) {
 
100
  n = Number( n );
 
101
  if( isNaN(n) || n == 0 || n == Number.POSITIVE_INFINITY ||
 
102
      n == Number.NEGATIVE_INFINITY ) {
 
103
    return 0;
 
104
  }
 
105
  var sign = n < 0 ? -1 : 1;
 
106
 
 
107
  return ( sign * ( n * Math.floor( Math.abs(n) ) ) ) % Math.pow(2, 32);
 
108
}
 
109