]>
git.saurik.com Git - apple/javascriptcore.git/blob - 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/
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.1.1-2.js
24 ECMA Section: 15.3.1.1 The Function Constructor Called as a Function
25 Function(p1, p2, ..., pn, body )
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:
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).
35 Author: christine@netscape.com
39 var SECTION
= "15.3.1.1-2";
40 var VERSION
= "ECMA_1";
42 var TITLE
= "The Function Constructor Called as a Function";
44 writeHeaderToLog( SECTION
+ " "+ TITLE
);
46 var testcases
= getTestCases();
50 function getTestCases() {
51 var array
= new Array();
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" );
58 myfunc1
.toString
= Object
.prototype.toString
;
59 myfunc2
.toString
= Object
.prototype.toString
;
60 myfunc3
.toString
= Object
.prototype.toString
;
62 array
[item
++] = new TestCase( SECTION
, "myfunc1 = Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
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() );
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",
74 eval("var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS") );
76 array
[item
++] = new TestCase( SECTION
, "myfunc2 = Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.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() );
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",
88 eval("var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS") );
90 array
[item
++] = new TestCase( SECTION
, "myfunc3 = Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.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
) );
101 array
[item
++] = new TestCase( SECTION
, "var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS",
103 eval("var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS") );
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
);
114 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
117 return ( testcases
);