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.js
24 ECMA Section: 15.3.1.1 The Function Constructor Called as a Function
27 When the Function function is called with some arguments p1, p2, . . . , pn, body
28 (where n might be 0, that is, there are no "p" arguments, and where body might
29 also not be provided), the following steps are taken:
31 1. Create and return a new Function object exactly if the function constructor had
32 been called with the same arguments (15.3.2.1).
34 Author: christine@netscape.com
38 var SECTION = "15.3.1.1-1";
39 var VERSION = "ECMA_1";
41 var TITLE = "The Function Constructor Called as a Function";
43 writeHeaderToLog( SECTION + " "+ TITLE);
45 var MyObject = Function( "value", "this.value = value; this.valueOf = Function( 'return this.value' ); this.toString = Function( 'return String(this.value);' )" );
47 var testcases = getTestCases();
50 function getTestCases() {
51 var array = new Array();
54 var myfunc = Function();
55 myfunc.toString = Object.prototype.toString;
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;
61 array[item++] = new TestCase( SECTION,
62 "myfunc = 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() );
67 array[item++] = new TestCase( SECTION, "myfunc.prototype.constructor", myfunc, myfunc.prototype.constructor );
68 array[item++] = new TestCase( SECTION, "myfunc.arguments", null, myfunc.arguments );
69 array[item++] = new TestCase( SECTION, "var OBJ = new MyObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyObject(true); OBJ.valueOf()") );
70 array[item++] = new TestCase( SECTION, "OBJ.toString()", "true", OBJ.toString() );
71 array[item++] = new TestCase( SECTION, "OBJ.toString = Object.prototype.toString; OBJ.toString()", "[object Object]", eval("OBJ.toString = Object.prototype.toString; OBJ.toString()") );
72 array[item++] = new TestCase( SECTION, "MyObject.toString = Object.prototype.toString; MyObject.toString()", "[object Function]", eval("MyObject.toString = Object.prototype.toString; MyObject.toString()") );
73 array[item++] = new TestCase( SECTION, "MyObject.__proto__ == Function.prototype", true, MyObject.__proto__ == Function.prototype );
74 array[item++] = new TestCase( SECTION, "MyObject.length", 1, MyObject.length );
75 array[item++] = new TestCase( SECTION, "MyObject.prototype.constructor", MyObject, MyObject.prototype.constructor );
76 array[item++] = new TestCase( SECTION, "MyObject.arguments", null, MyObject.arguments );
80 for ( tc=0; tc < testcases.length; tc++ ) {
81 testcases[tc].passed = writeTestCaseResult(
84 testcases[tc].description +" = "+ testcases[tc].actual );
86 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";