Debian Codegraph @

rhino/testsrc/tests/ecma/FunctionObjects/15.3.2.1-1.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.2.1-1.js';
7
8 /**
9 File Name: 15.3.2.1.js
10 ECMA Section: 15.3.2.1 The Function Constructor
11 new Function(p1, p2, ..., pn, body )
12
13 Description: The last argument specifies the body (executable code)
14 of a function; any preceeding arguments sepcify formal
15 parameters.
16
17 See the text for description of this section.
18
19 This test examples from the specification.
20
21 Author: [email protected]
22 Date: 28 october 1997
23
24 */
25 var SECTION = "15.3.2.1";
26 var VERSION = "ECMA_1";
27 startTest();
28 var TITLE = "The Function Constructor";
29
30 writeHeaderToLog( SECTION + " "+ TITLE);
31
32 var MyObject = new Function( "value", "this.value = value; this.valueOf = new Function( 'return this.value' ); this.toString = new Function( 'return String(this.value);' )" );
33
34 var myfunc = new Function();
35
36 // not going to test toString here since it is implementation dependent.
37 // new TestCase( SECTION, "myfunc.toString()", "function anonymous() { }", myfunc.toString() );
38
39 myfunc.toString = Object.prototype.toString;
40
41 new TestCase( SECTION, "myfunc = new Function(); myfunc.toString = Object.prototype.toString; myfunc.toString()",
42 "[object Function]",
43 myfunc.toString() );
44
45 new TestCase( SECTION,
46 "myfunc.length",
47 0,
48 myfunc.length );
49
50 new TestCase( SECTION,
51 "myfunc.prototype.toString()",
52 "[object Object]",
53 myfunc.prototype.toString() );
54
55 new TestCase( SECTION,
56 "myfunc.prototype.constructor",
57 myfunc,
58 myfunc.prototype.constructor );
59
60 new TestCase( SECTION,
61 "myfunc.arguments",
62 null,
63 myfunc.arguments );
64
65 new TestCase( SECTION,
66 "var OBJ = new MyObject(true); OBJ.valueOf()",
67 true,
68 eval("var OBJ = new MyObject(true); OBJ.valueOf()") );
69
70 new TestCase( SECTION,
71 "OBJ.toString()",
72 "true",
73 OBJ.toString() );
74
75 new TestCase( SECTION,
76 "OBJ.toString = Object.prototype.toString; OBJ.toString()", "[object Object]",
77 eval("OBJ.toString = Object.prototype.toString; OBJ.toString()") );
78
79 new TestCase( SECTION,
80 "MyObject.toString = Object.prototype.toString; MyObject.toString()",
81 "[object Function]",
82 eval("MyObject.toString = Object.prototype.toString; MyObject.toString()") );
83
84 new TestCase( SECTION,
85 "MyObject.length",
86 1,
87 MyObject.length );
88
89 new TestCase( SECTION,
90 "MyObject.prototype.constructor",
91 MyObject,
92 MyObject.prototype.constructor );
93
94 new TestCase( SECTION,
95 "MyObject.arguments",
96 null,
97 MyObject.arguments );
98
99 test();