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/ 5 * 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. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 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 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22 /** 23 File Name: 15.3.1.1.js 24 ECMA Section: 15.3.1.1 The Function Constructor Called as a Function 25 26 Description: 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: 30 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). 33 34 Author: christine (at) netscape.com 35 Date: 28 october 1997 36 37 */ 38 var SECTION = "15.3.1.1-1"; 39 var VERSION = "ECMA_1"; 40 startTest(); 41 var TITLE = "The Function Constructor Called as a Function"; 42 43 writeHeaderToLog( SECTION + " "+ TITLE); 44 45 var MyObject = Function( "value", "this.value = value; this.valueOf = Function( 'return this.value' ); this.toString = Function( 'return String(this.value);' )" ); 46 47 var testcases = getTestCases(); 48 test(); 49 50 function getTestCases() { 51 var array = new Array(); 52 var item = 0; 53 54 var myfunc = Function(); 55 myfunc.toString = Object.prototype.toString; 56 57 // not going to test toString here since it is implementation dependent. 58 // array[item++] = new TestCase( SECTION, "myfunc.toString()", "function anonymous() { }", myfunc.toString() ); 59 60 myfunc.toString = Object.prototype.toString; 61 array[item++] = new TestCase( SECTION, 62 "myfunc = Function(); myfunc.toString = Object.prototype.toString; myfunc.toString()", 63 "[object Function]", 64 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 ); 77 return ( array ); 78 } 79 function test() { 80 for ( tc=0; tc < testcases.length; tc++ ) { 81 testcases[tc].passed = writeTestCaseResult( 82 testcases[tc].expect, 83 testcases[tc].actual, 84 testcases[tc].description +" = "+ testcases[tc].actual ); 85 86 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 87 } 88 stopTest(); 89 return ( testcases ); 90 } 91