1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_2/function/tostring-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +// |reftest| skip -- obsolete test 1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +/** 1.12 + File Name: tostring-1.js 1.13 + Section: Function.toString 1.14 + Description: 1.15 + 1.16 + Since the behavior of Function.toString() is implementation-dependent, 1.17 + toString tests for function are not in the ECMA suite. 1.18 + 1.19 + Currently, an attempt to parse the toString output for some functions 1.20 + and verify that the result is something reasonable. 1.21 + 1.22 + Author: christine@netscape.com 1.23 + Date: 12 november 1997 1.24 +*/ 1.25 + 1.26 +var SECTION = "tostring-1"; 1.27 +var VERSION = "JS1_2"; 1.28 +startTest(); 1.29 +var TITLE = "Function.toString()"; 1.30 + 1.31 +writeHeaderToLog( SECTION + " "+ TITLE); 1.32 + 1.33 +var tab = " "; 1.34 + 1.35 +t1 = new TestFunction( "stub", "value", tab + "return value;" ); 1.36 + 1.37 +t2 = new TestFunction( "ToString", "object", tab+"return object + \"\";" ); 1.38 + 1.39 +t3 = new TestFunction( "Add", "a, b, c, d, e", tab +"var s = a + b + c + d + e;\n" + 1.40 + tab + "return s;" ); 1.41 + 1.42 +t4 = new TestFunction( "noop", "value" ); 1.43 + 1.44 +t5 = new TestFunction( "anonymous", "", tab+"return \"hello!\";" ); 1.45 + 1.46 +var f = new Function( "return \"hello!\""); 1.47 + 1.48 +new TestCase( SECTION, 1.49 + "stub.toString()", 1.50 + t1.valueOf(), 1.51 + stub.toString() ); 1.52 + 1.53 +new TestCase( SECTION, 1.54 + "ToString.toString()", 1.55 + t2.valueOf(), 1.56 + ToString.toString() ); 1.57 + 1.58 +new TestCase( SECTION, 1.59 + "Add.toString()", 1.60 + t3.valueOf(), 1.61 + Add.toString() ); 1.62 + 1.63 +new TestCase( SECTION, 1.64 + "noop.toString()", 1.65 + t4.toString(), 1.66 + noop.toString() ); 1.67 + 1.68 +new TestCase( SECTION, 1.69 + "f.toString()", 1.70 + t5.toString(), 1.71 + f.toString() ); 1.72 +test(); 1.73 + 1.74 +function noop( value ) { 1.75 +} 1.76 +function Add( a, b, c, d, e ) { 1.77 + var s = a + b + c + d + e; 1.78 + return s; 1.79 +} 1.80 +function stub( value ) { 1.81 + return value; 1.82 +} 1.83 +function ToString( object ) { 1.84 + return object + ""; 1.85 +} 1.86 + 1.87 +function ToBoolean( value ) { 1.88 + if ( value == 0 || value == NaN || value == false ) { 1.89 + return false; 1.90 + } else { 1.91 + return true; 1.92 + } 1.93 +} 1.94 + 1.95 +function TestFunction( name, args, body ) { 1.96 + if ( name == "anonymous" && version() == 120 ) { 1.97 + name = ""; 1.98 + } 1.99 + 1.100 + this.name = name; 1.101 + this.arguments = args.toString(); 1.102 + this.body = body; 1.103 + 1.104 + /* the format of Function.toString() in JavaScript 1.2 is: 1.105 + function name ( arguments ) { 1.106 + body 1.107 + } 1.108 + */ 1.109 + this.value = "function " + (name ? name : "" )+ 1.110 + "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}"; 1.111 + 1.112 + this.toString = new Function( "return this.value" ); 1.113 + this.valueOf = new Function( "return this.value" ); 1.114 + return this; 1.115 +}