|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: 15.3.1.1-2.js |
|
9 ECMA Section: 15.3.1.1 The Function Constructor Called as a Function |
|
10 Function(p1, p2, ..., pn, body ) |
|
11 |
|
12 Description: |
|
13 When the Function function is called with some arguments p1, p2, . . . , pn, |
|
14 body (where n might be 0, that is, there are no "p" arguments, and where body |
|
15 might also not be provided), the following steps are taken: |
|
16 |
|
17 1. Create and return a new Function object exactly if the function constructor |
|
18 had been called with the same arguments (15.3.2.1). |
|
19 |
|
20 Author: christine@netscape.com |
|
21 Date: 28 october 1997 |
|
22 |
|
23 */ |
|
24 var SECTION = "15.3.1.1-2"; |
|
25 var VERSION = "ECMA_1"; |
|
26 startTest(); |
|
27 var TITLE = "The Function Constructor Called as a Function"; |
|
28 |
|
29 writeHeaderToLog( SECTION + " "+ TITLE); |
|
30 |
|
31 var myfunc1 = Function("a","b","c", "return a+b+c" ); |
|
32 var myfunc2 = Function("a, b, c", "return a+b+c" ); |
|
33 var myfunc3 = Function("a,b", "c", "return a+b+c" ); |
|
34 |
|
35 myfunc1.toString = Object.prototype.toString; |
|
36 myfunc2.toString = Object.prototype.toString; |
|
37 myfunc3.toString = Object.prototype.toString; |
|
38 |
|
39 new TestCase( SECTION, |
|
40 "myfunc1 = Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()", |
|
41 "[object Function]", |
|
42 myfunc1.toString() ); |
|
43 |
|
44 new TestCase( SECTION, |
|
45 "myfunc1.length", |
|
46 3, |
|
47 myfunc1.length ); |
|
48 |
|
49 new TestCase( SECTION, |
|
50 "myfunc1.prototype.toString()", |
|
51 "[object Object]", |
|
52 myfunc1.prototype.toString() ); |
|
53 |
|
54 new TestCase( SECTION, |
|
55 "myfunc1.prototype.constructor", |
|
56 myfunc1, |
|
57 myfunc1.prototype.constructor ); |
|
58 |
|
59 new TestCase( SECTION, |
|
60 "myfunc1.arguments", |
|
61 null, |
|
62 myfunc1.arguments ); |
|
63 |
|
64 new TestCase( SECTION, |
|
65 "myfunc1(1,2,3)", |
|
66 6, |
|
67 myfunc1(1,2,3) ); |
|
68 |
|
69 new TestCase( SECTION, |
|
70 "var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS", |
|
71 "", |
|
72 eval("var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS") ); |
|
73 |
|
74 new TestCase( SECTION, |
|
75 "myfunc2 = Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()", |
|
76 "[object Function]", |
|
77 myfunc2.toString() ); |
|
78 |
|
79 new TestCase( SECTION, |
|
80 "myfunc2.length", |
|
81 3, |
|
82 myfunc2.length ); |
|
83 |
|
84 new TestCase( SECTION, |
|
85 "myfunc2.prototype.toString()", |
|
86 "[object Object]", |
|
87 myfunc2.prototype.toString() ); |
|
88 |
|
89 new TestCase( SECTION, |
|
90 "myfunc2.prototype.constructor", |
|
91 myfunc2, |
|
92 myfunc2.prototype.constructor ); |
|
93 |
|
94 new TestCase( SECTION, |
|
95 "myfunc2.arguments", |
|
96 null, |
|
97 myfunc2.arguments ); |
|
98 |
|
99 new TestCase( SECTION, |
|
100 "myfunc2( 1000, 200, 30 )", |
|
101 1230, |
|
102 myfunc2(1000,200,30) ); |
|
103 |
|
104 new TestCase( SECTION, |
|
105 "var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS", |
|
106 "", |
|
107 eval("var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS") ); |
|
108 |
|
109 new TestCase( SECTION, |
|
110 "myfunc3 = Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()", |
|
111 "[object Function]", |
|
112 myfunc3.toString() ); |
|
113 |
|
114 new TestCase( SECTION, |
|
115 "myfunc3.length", |
|
116 3, |
|
117 myfunc3.length ); |
|
118 |
|
119 new TestCase( SECTION, |
|
120 "myfunc3.prototype.toString()", |
|
121 "[object Object]", |
|
122 myfunc3.prototype.toString() ); |
|
123 |
|
124 new TestCase( SECTION, |
|
125 "myfunc3.prototype.valueOf() +''", |
|
126 "[object Object]", |
|
127 myfunc3.prototype.valueOf() +'' ); |
|
128 |
|
129 new TestCase( SECTION, |
|
130 "myfunc3.prototype.constructor", |
|
131 myfunc3, |
|
132 myfunc3.prototype.constructor ); |
|
133 |
|
134 new TestCase( SECTION, |
|
135 "myfunc3.arguments", |
|
136 null, |
|
137 myfunc3.arguments ); |
|
138 |
|
139 new TestCase( SECTION, |
|
140 "myfunc3(-100,100,NaN)", |
|
141 Number.NaN, |
|
142 myfunc3(-100,100,NaN) ); |
|
143 |
|
144 new TestCase( SECTION, |
|
145 "var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS", |
|
146 "", |
|
147 eval("var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS") ); |
|
148 |
|
149 test(); |