]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/FunctionObjects/15.3.2.1-2.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.3.2.1.js
24 ECMA Section: 15.3.2.1 The Function Constructor
25 new Function(p1, p2, ..., pn, body )
28 Author: christine@netscape.com
32 var SECTION
= "15.3.2.1-2";
33 var VERSION
= "ECMA_1";
35 var TITLE
= "The Function Constructor";
37 writeHeaderToLog( SECTION
+ " "+ TITLE
);
39 var testcases
= getTestCases();
43 function getTestCases() {
44 var array
= new Array();
47 var myfunc1
= new Function("a","b","c", "return a+b+c" );
48 var myfunc2
= new Function("a, b, c", "return a+b+c" );
49 var myfunc3
= new Function("a,b", "c", "return a+b+c" );
51 myfunc1
.toString
= Object
.prototype.toString
;
52 myfunc2
.toString
= Object
.prototype.toString
;
53 myfunc3
.toString
= Object
.prototype.toString
;
55 array
[item
++] = new TestCase( SECTION
, "myfunc1 = new Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
59 array
[item
++] = new TestCase( SECTION
, "myfunc1.length", 3, myfunc1
.length
);
60 array
[item
++] = new TestCase( SECTION
, "myfunc1.prototype.toString()", "[object Object]", myfunc1
.prototype.toString() );
62 array
[item
++] = new TestCase( SECTION
, "myfunc1.prototype.constructor", myfunc1
, myfunc1
.prototype.constructor );
63 array
[item
++] = new TestCase( SECTION
, "myfunc1.arguments", null, myfunc1
.arguments
);
64 array
[item
++] = new TestCase( SECTION
, "myfunc1(1,2,3)", 6, myfunc1(1,2,3) );
65 array
[item
++] = new TestCase( SECTION
, "var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS",
67 eval("var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS") );
69 array
[item
++] = new TestCase( SECTION
, "myfunc2 = new Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
72 array
[item
++] = new TestCase( SECTION
, "myfunc2.__proto__", Function
.prototype, myfunc2
.__proto__
);
73 array
[item
++] = new TestCase( SECTION
, "myfunc2.length", 3, myfunc2
.length
);
74 array
[item
++] = new TestCase( SECTION
, "myfunc2.prototype.toString()", "[object Object]", myfunc2
.prototype.toString() );
76 array
[item
++] = new TestCase( SECTION
, "myfunc2.prototype.constructor", myfunc2
, myfunc2
.prototype.constructor );
77 array
[item
++] = new TestCase( SECTION
, "myfunc2.arguments", null, myfunc2
.arguments
);
78 array
[item
++] = new TestCase( SECTION
, "myfunc2( 1000, 200, 30 )", 1230, myfunc2(1000,200,30) );
79 array
[item
++] = new TestCase( SECTION
, "var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS",
81 eval("var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS") );
83 array
[item
++] = new TestCase( SECTION
, "myfunc3 = new Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
86 array
[item
++] = new TestCase( SECTION
, "myfunc3.__proto__", Function
.prototype, myfunc3
.__proto__
);
87 array
[item
++] = new TestCase( SECTION
, "myfunc3.length", 3, myfunc3
.length
);
88 array
[item
++] = new TestCase( SECTION
, "myfunc3.prototype.toString()", "[object Object]", myfunc3
.prototype.toString() );
89 array
[item
++] = new TestCase( SECTION
, "myfunc3.prototype.valueOf() +''", "[object Object]", myfunc3
.prototype.valueOf() +'' );
90 array
[item
++] = new TestCase( SECTION
, "myfunc3.prototype.constructor", myfunc3
, myfunc3
.prototype.constructor );
91 array
[item
++] = new TestCase( SECTION
, "myfunc3.arguments", null, myfunc3
.arguments
);
92 array
[item
++] = new TestCase( SECTION
, "myfunc3(-100,100,NaN)", Number
.NaN
, myfunc3(-100,100,NaN
) );
94 array
[item
++] = new TestCase( SECTION
, "var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS",
96 eval("var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS") );
101 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
102 testcases
[tc
].passed
= writeTestCaseResult(
103 testcases
[tc
].expect
,
104 testcases
[tc
].actual
,
105 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
107 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
110 return ( testcases
);