michael@0: // |reftest| skip -- obsolete test 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: tostring-1.js michael@0: Section: Function.toString michael@0: Description: michael@0: michael@0: Since the behavior of Function.toString() is implementation-dependent, michael@0: toString tests for function are not in the ECMA suite. michael@0: michael@0: Currently, an attempt to parse the toString output for some functions michael@0: and verify that the result is something reasonable. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: michael@0: var SECTION = "tostring-1"; michael@0: var VERSION = "JS1_2"; michael@0: startTest(); michael@0: var TITLE = "Function.toString()"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: var tab = " "; michael@0: michael@0: t1 = new TestFunction( "stub", "value", tab + "return value;" ); michael@0: michael@0: t2 = new TestFunction( "ToString", "object", tab+"return object + \"\";" ); michael@0: michael@0: t3 = new TestFunction( "Add", "a, b, c, d, e", tab +"var s = a + b + c + d + e;\n" + michael@0: tab + "return s;" ); michael@0: michael@0: t4 = new TestFunction( "noop", "value" ); michael@0: michael@0: t5 = new TestFunction( "anonymous", "", tab+"return \"hello!\";" ); michael@0: michael@0: var f = new Function( "return \"hello!\""); michael@0: michael@0: new TestCase( SECTION, michael@0: "stub.toString()", michael@0: t1.valueOf(), michael@0: stub.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "ToString.toString()", michael@0: t2.valueOf(), michael@0: ToString.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Add.toString()", michael@0: t3.valueOf(), michael@0: Add.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "noop.toString()", michael@0: t4.toString(), michael@0: noop.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "f.toString()", michael@0: t5.toString(), michael@0: f.toString() ); michael@0: test(); michael@0: michael@0: function noop( value ) { michael@0: } michael@0: function Add( a, b, c, d, e ) { michael@0: var s = a + b + c + d + e; michael@0: return s; michael@0: } michael@0: function stub( value ) { michael@0: return value; michael@0: } michael@0: function ToString( object ) { michael@0: return object + ""; michael@0: } michael@0: michael@0: function ToBoolean( value ) { michael@0: if ( value == 0 || value == NaN || value == false ) { michael@0: return false; michael@0: } else { michael@0: return true; michael@0: } michael@0: } michael@0: michael@0: function TestFunction( name, args, body ) { michael@0: if ( name == "anonymous" && version() == 120 ) { michael@0: name = ""; michael@0: } michael@0: michael@0: this.name = name; michael@0: this.arguments = args.toString(); michael@0: this.body = body; michael@0: michael@0: /* the format of Function.toString() in JavaScript 1.2 is: michael@0: function name ( arguments ) { michael@0: body michael@0: } michael@0: */ michael@0: this.value = "function " + (name ? name : "" )+ michael@0: "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}"; michael@0: michael@0: this.toString = new Function( "return this.value" ); michael@0: this.valueOf = new Function( "return this.value" ); michael@0: return this; michael@0: }