initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma / FunctionObjects / 15.3.1.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/
5  *
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.
10  *
11  * The Original Code is Mozilla Communicator client code, released March
12  * 31, 1998.
13  *
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
17  * Rights Reserved.
18  *
19  * Contributor(s): 
20  * 
21  */
22 /**
23     File Name:          15.3.1.1-2.js
24     ECMA Section:       15.3.1.1 The Function Constructor Called as a Function
25                         Function(p1, p2, ..., pn, body )
26
27     Description:
28     When the Function function is called with some arguments p1, p2, . . . , pn,
29     body (where n might be 0, that is, there are no "p" arguments, and where body
30     might also not be provided), the following steps are taken:
31
32     1.  Create and return a new Function object exactly if the function constructor
33     had been called with the same arguments (15.3.2.1).
34
35     Author:             christine@netscape.com
36     Date:               28 october 1997
37
38 */
39     var SECTION = "15.3.1.1-2";
40     var VERSION = "ECMA_1";
41     startTest();
42     var TITLE   = "The Function Constructor Called as a Function";
43
44     writeHeaderToLog( SECTION + " "+ TITLE);
45
46     var testcases = getTestCases();
47     test();
48
49
50 function getTestCases() {
51     var array = new Array();
52     var item = 0;
53
54     var myfunc1 =  Function("a","b","c", "return a+b+c" );
55     var myfunc2 =  Function("a, b, c",   "return a+b+c" );
56     var myfunc3 =  Function("a,b", "c",  "return a+b+c" );
57
58     myfunc1.toString = Object.prototype.toString;
59     myfunc2.toString = Object.prototype.toString;
60     myfunc3.toString = Object.prototype.toString;
61
62     array[item++] = new TestCase( SECTION,  "myfunc1 =  Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
63                                             "[object Function]",
64                                             myfunc1.toString() );
65
66     array[item++] = new TestCase( SECTION,  "myfunc1.length",                            3,                      myfunc1.length );
67     array[item++] = new TestCase( SECTION,  "myfunc1.prototype.toString()",              "[object Object]",      myfunc1.prototype.toString() );
68
69     array[item++] = new TestCase( SECTION,  "myfunc1.prototype.constructor",             myfunc1,                myfunc1.prototype.constructor );
70     array[item++] = new TestCase( SECTION,  "myfunc1.arguments",                         null,                   myfunc1.arguments );
71     array[item++] = new TestCase( SECTION,  "myfunc1(1,2,3)",                            6,                      myfunc1(1,2,3) );
72     array[item++] = new TestCase( SECTION,  "var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS",
73                                             "",
74                                             eval("var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS") );
75
76     array[item++] = new TestCase( SECTION,  "myfunc2 =  Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
77                                             "[object Function]",
78                                             myfunc2.toString() );
79     array[item++] = new TestCase( SECTION,  "myfunc2.__proto__",                         Function.prototype,     myfunc2.__proto__ );
80     array[item++] = new TestCase( SECTION,  "myfunc2.length",                            3,                      myfunc2.length );
81     array[item++] = new TestCase( SECTION,  "myfunc2.prototype.toString()",              "[object Object]",      myfunc2.prototype.toString() );
82
83     array[item++] = new TestCase( SECTION,  "myfunc2.prototype.constructor",             myfunc2,                 myfunc2.prototype.constructor );
84     array[item++] = new TestCase( SECTION,  "myfunc2.arguments",                         null,                   myfunc2.arguments );
85     array[item++] = new TestCase( SECTION,  "myfunc2( 1000, 200, 30 )",                 1230,                    myfunc2(1000,200,30) );
86     array[item++] = new TestCase( SECTION,  "var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS",
87                                             "",
88                                             eval("var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS") );
89
90     array[item++] = new TestCase( SECTION,  "myfunc3 =  Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
91                                             "[object Function]",
92                                             myfunc3.toString() );
93     array[item++] = new TestCase( SECTION,  "myfunc3.__proto__",                         Function.prototype,     myfunc3.__proto__ );
94     array[item++] = new TestCase( SECTION,  "myfunc3.length",                            3,                      myfunc3.length );
95     array[item++] = new TestCase( SECTION,  "myfunc3.prototype.toString()",              "[object Object]",      myfunc3.prototype.toString() );
96     array[item++] = new TestCase( SECTION,  "myfunc3.prototype.valueOf() +''",           "[object Object]",      myfunc3.prototype.valueOf() +'' );
97     array[item++] = new TestCase( SECTION,  "myfunc3.prototype.constructor",             myfunc3,                 myfunc3.prototype.constructor );
98     array[item++] = new TestCase( SECTION,  "myfunc3.arguments",                         null,                   myfunc3.arguments );
99     array[item++] = new TestCase( SECTION,  "myfunc3(-100,100,NaN)",                    Number.NaN,              myfunc3(-100,100,NaN) );
100
101     array[item++] = new TestCase( SECTION,  "var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS",
102                                             "",
103                                             eval("var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS") );
104
105     return ( array );
106 }
107 function test() {
108     for ( tc=0; tc < testcases.length; tc++ ) {
109         testcases[tc].passed = writeTestCaseResult(
110                             testcases[tc].expect,
111                             testcases[tc].actual,
112                             testcases[tc].description +" = "+ testcases[tc].actual );
113
114         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
115     }
116     stopTest();
117     return ( testcases );
118 }