Debian Codegraph @

rhino/testsrc/tests/ecma/FunctionObjects/15.3.1.1-2.js

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