michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.3.2.1.js michael@0: ECMA Section: 15.3.2.1 The Function Constructor michael@0: new Function(p1, p2, ..., pn, body ) michael@0: michael@0: Description: The last argument specifies the body (executable code) michael@0: of a function; any preceding arguments sepcify formal michael@0: parameters. michael@0: michael@0: See the text for description of this section. michael@0: michael@0: This test examples from the specification. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 28 october 1997 michael@0: michael@0: */ michael@0: var SECTION = "15.3.2.1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "The Function Constructor"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: var MyObject = new Function( "value", "this.value = value; this.valueOf = new Function( 'return this.value' ); this.toString = new Function( 'return String(this.value);' )" ); michael@0: michael@0: var myfunc = new Function(); michael@0: michael@0: // not going to test toString here since it is implementation dependent. michael@0: // new TestCase( SECTION, "myfunc.toString()", "function anonymous() { }", myfunc.toString() ); michael@0: michael@0: myfunc.toString = Object.prototype.toString; michael@0: michael@0: new TestCase( SECTION, "myfunc = new Function(); myfunc.toString = Object.prototype.toString; myfunc.toString()", michael@0: "[object Function]", michael@0: myfunc.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "myfunc.length", michael@0: 0, michael@0: myfunc.length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "myfunc.prototype.toString()", michael@0: "[object Object]", michael@0: myfunc.prototype.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "myfunc.prototype.constructor", michael@0: myfunc, michael@0: myfunc.prototype.constructor ); michael@0: michael@0: new TestCase( SECTION, michael@0: "myfunc.arguments", michael@0: null, michael@0: myfunc.arguments ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var OBJ = new MyObject(true); OBJ.valueOf()", michael@0: true, michael@0: eval("var OBJ = new MyObject(true); OBJ.valueOf()") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "OBJ.toString()", michael@0: "true", michael@0: OBJ.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "OBJ.toString = Object.prototype.toString; OBJ.toString()", "[object Object]", michael@0: eval("OBJ.toString = Object.prototype.toString; OBJ.toString()") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "MyObject.toString = Object.prototype.toString; MyObject.toString()", michael@0: "[object Function]", michael@0: eval("MyObject.toString = Object.prototype.toString; MyObject.toString()") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "MyObject.length", michael@0: 1, michael@0: MyObject.length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "MyObject.prototype.constructor", michael@0: MyObject, michael@0: MyObject.prototype.constructor ); michael@0: michael@0: new TestCase( SECTION, michael@0: "MyObject.arguments", michael@0: null, michael@0: MyObject.arguments ); michael@0: michael@0: test();