]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/ObjectObjects/15.2.2.1.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: 15.2.2.1.js
24 ECMA Section: 15.2.2.1 The Object Constructor: new Object( value )
26 1.If the type of the value is not Object, go to step 4.
27 2.If the value is a native ECMAScript object, do not create a new object; simply return value.
28 3.If the value is a host object, then actions are taken and a result is returned in an
29 implementation-dependent manner that may depend on the host object.
30 4.If the type of the value is String, return ToObject(value).
31 5.If the type of the value is Boolean, return ToObject(value).
32 6.If the type of the value is Number, return ToObject(value).
33 7.(The type of the value must be Null or Undefined.) Create a new native ECMAScript object.
34 The [[Prototype]] property of the newly constructed object is set to the Object prototype object.
35 The [[Class]] property of the newly constructed object is set to "Object".
36 The newly constructed object has no [[Value]] property.
37 Return the newly created native object.
39 Description: This does not test cases where the object is a host object.
40 Author: christine@netscape.com
44 var SECTION
= "15.2.2.1";
45 var VERSION
= "ECMA_1";
47 var TITLE
= "new Object( value )";
49 writeHeaderToLog( SECTION
+ " "+ TITLE
);
51 var testcases
= getTestCases();
54 function getTestCases() {
55 var array
= new Array();
58 array
[item
++] = new TestCase( SECTION
, "typeof new Object(null)", "object", typeof new Object(null) );
59 array
[item
++] = new TestCase( SECTION
, "MYOB = new Object(null); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Object]", eval("MYOB = new Object(null); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
61 array
[item
++] = new TestCase( SECTION
, "typeof new Object(void 0)", "object", typeof new Object(void 0) );
62 array
[item
++] = new TestCase( SECTION
, "MYOB = new Object(new Object(void 0)); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Object]", eval("MYOB = new Object(new Object(void 0)); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
64 array
[item
++] = new TestCase( SECTION
, "typeof new Object('string')", "object", typeof new Object('string') );
65 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object('string'); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object String]", eval("MYOB = new Object('string'); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
66 array
[item
++] = new TestCase( SECTION
, "(new Object('string').valueOf()", "string", (new Object('string')).valueOf() );
68 array
[item
++] = new TestCase( SECTION
, "typeof new Object('')", "object", typeof new Object('') );
69 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(''); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object String]", eval("MYOB = new Object(''); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
70 array
[item
++] = new TestCase( SECTION
, "(new Object('').valueOf()", "", (new Object('')).valueOf() );
72 array
[item
++] = new TestCase( SECTION
, "typeof new Object(Number.NaN)", "object", typeof new Object(Number
.NaN
) );
73 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(Number.NaN); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(Number.NaN); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
74 array
[item
++] = new TestCase( SECTION
, "(new Object(Number.NaN).valueOf()", Number
.NaN
, (new Object(Number
.NaN
)).valueOf() );
76 array
[item
++] = new TestCase( SECTION
, "typeof new Object(0)", "object", typeof new Object(0) );
77 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(0); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(0); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
78 array
[item
++] = new TestCase( SECTION
, "(new Object(0).valueOf()", 0, (new Object(0)).valueOf() );
80 array
[item
++] = new TestCase( SECTION
, "typeof new Object(-0)", "object", typeof new Object(-0) );
81 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(-0); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(-0); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
82 array
[item
++] = new TestCase( SECTION
, "(new Object(-0).valueOf()", -0, (new Object(-0)).valueOf() );
84 array
[item
++] = new TestCase( SECTION
, "typeof new Object(1)", "object", typeof new Object(1) );
85 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(1); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(1); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
86 array
[item
++] = new TestCase( SECTION
, "(new Object(1).valueOf()", 1, (new Object(1)).valueOf() );
88 array
[item
++] = new TestCase( SECTION
, "typeof new Object(-1)", "object", typeof new Object(-1) );
89 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(-1); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(-1); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
90 array
[item
++] = new TestCase( SECTION
, "(new Object(-1).valueOf()", -1, (new Object(-1)).valueOf() );
92 array
[item
++] = new TestCase( SECTION
, "typeof new Object(true)", "object", typeof new Object(true) );
93 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(true); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Boolean]", eval("MYOB = new Object(true); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
94 array
[item
++] = new TestCase( SECTION
, "(new Object(true).valueOf()", true, (new Object(true)).valueOf() );
96 array
[item
++] = new TestCase( SECTION
, "typeof new Object(false)", "object", typeof new Object(false) );
97 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(false); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Boolean]", eval("MYOB = new Object(false); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
98 array
[item
++] = new TestCase( SECTION
, "(new Object(false).valueOf()", false, (new Object(false)).valueOf() );
100 array
[item
++] = new TestCase( SECTION
, "typeof new Object(Boolean())", "object", typeof new Object(Boolean()) );
101 array
[item
++] = new TestCase( SECTION
, "MYOB = (new Object(Boolean()); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Boolean]", eval("MYOB = new Object(Boolean()); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
102 array
[item
++] = new TestCase( SECTION
, "(new Object(Boolean()).valueOf()", Boolean(), (new Object(Boolean())).valueOf() );
106 var myobject
= new Object( "my new object" );
107 var myarray
= new Array();
108 var myboolean
= new Boolean();
109 var mynumber
= new Number();
110 var mystring
= new String();
111 var myobject
= new Object();
112 var myfunction
= new Function( "x", "return x");
115 array
[item
++] = new TestCase( SECTION
, "myglobal = new Object( this )", myglobal
, new Object(this) );
116 array
[item
++] = new TestCase( SECTION
, "myobject = new Object('my new object'); new Object(myobject)", myobject
, new Object(myobject
) );
117 array
[item
++] = new TestCase( SECTION
, "myarray = new Array(); new Object(myarray)", myarray
, new Object(myarray
) );
118 array
[item
++] = new TestCase( SECTION
, "myboolean = new Boolean(); new Object(myboolean)", myboolean
, new Object(myboolean
) );
119 array
[item
++] = new TestCase( SECTION
, "mynumber = new Number(); new Object(mynumber)", mynumber
, new Object(mynumber
) );
120 array
[item
++] = new TestCase( SECTION
, "mystring = new String9); new Object(mystring)", mystring
, new Object(mystring
) );
121 array
[item
++] = new TestCase( SECTION
, "myobject = new Object(); new Object(mynobject)", myobject
, new Object(myobject
) );
122 array
[item
++] = new TestCase( SECTION
, "myfunction = new Function(); new Object(myfunction)", myfunction
, new Object(myfunction
) );
123 array
[item
++] = new TestCase( SECTION
, "mymath = Math; new Object(mymath)", mymath
, new Object(mymath
) );
128 for (tc
= 0 ; tc
< testcases
.length
; tc
++ ) {
129 testcases
[tc
].passed
= writeTestCaseResult(
130 testcases
[tc
].expect
,
131 testcases
[tc
].actual
,
132 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
133 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
138 return ( testcases
);