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.2.1.js
24 ECMA Section: 15.3.2.1 The Function Constructor
25 new Function(p1, p2, ..., pn, body )
27 Description: The last argument specifies the body (executable code)
28 of a function; any preceeding arguments sepcify formal
31 See the text for description of this section.
33 This test examples from the specification.
35 Author: christine@netscape.com
39 var SECTION = "15.3.2.1";
40 var VERSION = "ECMA_1";
42 var TITLE = "The Function Constructor";
44 writeHeaderToLog( SECTION + " "+ TITLE);
46 var MyObject = new Function( "value", "this.value = value; this.valueOf = new Function( 'return this.value' ); this.toString = new Function( 'return String(this.value);' )" );
48 var testcases = getTestCases();
51 function getTestCases() {
52 var array = new Array();
55 var myfunc = new Function();
57 // not going to test toString here since it is implementation dependent.
58 // array[item++] = new TestCase( SECTION, "myfunc.toString()", "function anonymous() { }", myfunc.toString() );
60 myfunc.toString = Object.prototype.toString;
62 array[item++] = new TestCase( SECTION, "myfunc = new Function(); myfunc.toString = Object.prototype.toString; myfunc.toString()",
65 array[item++] = new TestCase( SECTION, "myfunc.length", 0, myfunc.length );
66 array[item++] = new TestCase( SECTION, "myfunc.prototype.toString()", "[object Object]", myfunc.prototype.toString() );
68 array[item++] = new TestCase( SECTION, "myfunc.prototype.constructor", myfunc, myfunc.prototype.constructor );
69 array[item++] = new TestCase( SECTION, "myfunc.arguments", null, myfunc.arguments );
71 array[item++] = new TestCase( SECTION, "var OBJ = new MyObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyObject(true); OBJ.valueOf()") );
72 array[item++] = new TestCase( SECTION, "OBJ.toString()", "true", OBJ.toString() );
73 array[item++] = new TestCase( SECTION, "OBJ.toString = Object.prototype.toString; OBJ.toString()", "[object Object]", eval("OBJ.toString = Object.prototype.toString; OBJ.toString()") );
74 array[item++] = new TestCase( SECTION, "MyObject.toString = Object.prototype.toString; MyObject.toString()", "[object Function]", eval("MyObject.toString = Object.prototype.toString; MyObject.toString()") );
76 array[item++] = new TestCase( SECTION, "MyObject.__proto__ == Function.prototype", true, MyObject.__proto__ == Function.prototype );
77 array[item++] = new TestCase( SECTION, "MyObject.length", 1, MyObject.length );
78 array[item++] = new TestCase( SECTION, "MyObject.prototype.constructor", MyObject, MyObject.prototype.constructor );
79 array[item++] = new TestCase( SECTION, "MyObject.arguments", null, MyObject.arguments );
84 for ( tc=0; tc < testcases.length; tc++ ) {
85 testcases[tc].passed = writeTestCaseResult(
88 testcases[tc].description +" = "+ testcases[tc].actual );
90 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";