]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/FunctionObjects/15.3.2.1-2.js
JavaScriptCore-466.1.6.tar.gz
[apple/javascriptcore.git] / 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/
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.2.1.js
24 ECMA Section: 15.3.2.1 The Function Constructor
25 new Function(p1, p2, ..., pn, body )
26
27 Description:
28 Author: christine@netscape.com
29 Date: 28 october 1997
30
31 */
32 var SECTION = "15.3.2.1-2";
33 var VERSION = "ECMA_1";
34 startTest();
35 var TITLE = "The Function Constructor";
36
37 writeHeaderToLog( SECTION + " "+ TITLE);
38
39 var testcases = getTestCases();
40 test();
41
42
43 function getTestCases() {
44 var array = new Array();
45 var item = 0;
46
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" );
50
51 myfunc1.toString = Object.prototype.toString;
52 myfunc2.toString = Object.prototype.toString;
53 myfunc3.toString = Object.prototype.toString;
54
55 array[item++] = new TestCase( SECTION, "myfunc1 = new Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
56 "[object Function]",
57 myfunc1.toString() );
58
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() );
61
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",
66 "",
67 eval("var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS") );
68
69 array[item++] = new TestCase( SECTION, "myfunc2 = new Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
70 "[object Function]",
71 myfunc2.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() );
75
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",
80 "",
81 eval("var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS") );
82
83 array[item++] = new TestCase( SECTION, "myfunc3 = new Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
84 "[object Function]",
85 myfunc3.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) );
93
94 array[item++] = new TestCase( SECTION, "var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS",
95 "",
96 eval("var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS") );
97
98 return ( array );
99 }
100 function test() {
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 );
106
107 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
108 }
109 stopTest();
110 return ( testcases );
111 }