1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_2/function/tostring-2.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 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 + This verifies 1.23 + http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99212 1.24 + 1.25 + Author: christine@netscape.com 1.26 + Date: 12 november 1997 1.27 +*/ 1.28 + 1.29 +var SECTION = "tostring-2"; 1.30 +var VERSION = "JS1_2"; 1.31 +var TITLE = "Function.toString()"; 1.32 +var BUGNUMBER="123444"; 1.33 +startTest(); 1.34 + 1.35 +writeHeaderToLog( SECTION + " "+ TITLE); 1.36 + 1.37 +var tab = " "; 1.38 + 1.39 + 1.40 +var equals = new TestFunction( "Equals", "a, b", tab+ "return a == b;" ); 1.41 +function Equals (a, b) { 1.42 + return a == b; 1.43 +} 1.44 + 1.45 +var reallyequals = new TestFunction( "ReallyEquals", "a, b", 1.46 + ( version() <= 120 ) ? tab +"return a == b;" : tab +"return a === b;" ); 1.47 +function ReallyEquals( a, b ) { 1.48 + return a === b; 1.49 +} 1.50 + 1.51 +var doesntequal = new TestFunction( "DoesntEqual", "a, b", tab + "return a != b;" ); 1.52 +function DoesntEqual( a, b ) { 1.53 + return a != b; 1.54 +} 1.55 + 1.56 +var reallydoesntequal = new TestFunction( "ReallyDoesntEqual", "a, b", 1.57 + ( version() <= 120 ) ? tab +"return a != b;" : tab +"return a !== b;" ); 1.58 +function ReallyDoesntEqual( a, b ) { 1.59 + return a !== b; 1.60 +} 1.61 + 1.62 +var testor = new TestFunction( "TestOr", "a", tab+"if (a == null || a == void 0) {\n"+ 1.63 + tab +tab+"return 0;\n"+tab+"} else {\n"+tab+tab+"return a;\n"+tab+"}" ); 1.64 +function TestOr( a ) { 1.65 + if ( a == null || a == void 0 ) 1.66 + return 0; 1.67 + else 1.68 + return a; 1.69 +} 1.70 + 1.71 +var testand = new TestFunction( "TestAnd", "a", tab+"if (a != null && a != void 0) {\n"+ 1.72 + tab+tab+"return a;\n" + tab+ "} else {\n"+tab+tab+"return 0;\n"+tab+"}" ); 1.73 +function TestAnd( a ) { 1.74 + if ( a != null && a != void 0 ) 1.75 + return a; 1.76 + else 1.77 + return 0; 1.78 +} 1.79 + 1.80 +var or = new TestFunction( "Or", "a, b", tab + "return a | b;" ); 1.81 +function Or( a, b ) { 1.82 + return a | b; 1.83 +} 1.84 + 1.85 +var and = new TestFunction( "And", "a, b", tab + "return a & b;" ); 1.86 +function And( a, b ) { 1.87 + return a & b; 1.88 +} 1.89 + 1.90 +var xor = new TestFunction( "XOr", "a, b", tab + "return a ^ b;" ); 1.91 +function XOr( a, b ) { 1.92 + return a ^ b; 1.93 +} 1.94 + 1.95 +new TestCase( SECTION, 1.96 + "Equals.toString()", 1.97 + equals.valueOf(), 1.98 + Equals.toString() ); 1.99 + 1.100 +new TestCase( SECTION, 1.101 + "ReallyEquals.toString()", 1.102 + reallyequals.valueOf(), 1.103 + ReallyEquals.toString() ); 1.104 + 1.105 +new TestCase( SECTION, 1.106 + "DoesntEqual.toString()", 1.107 + doesntequal.valueOf(), 1.108 + DoesntEqual.toString() ); 1.109 + 1.110 +new TestCase( SECTION, 1.111 + "ReallyDoesntEqual.toString()", 1.112 + reallydoesntequal.valueOf(), 1.113 + ReallyDoesntEqual.toString() ); 1.114 + 1.115 +new TestCase( SECTION, 1.116 + "TestOr.toString()", 1.117 + testor.valueOf(), 1.118 + TestOr.toString() ); 1.119 + 1.120 +new TestCase( SECTION, 1.121 + "TestAnd.toString()", 1.122 + testand.valueOf(), 1.123 + TestAnd.toString() ); 1.124 + 1.125 +new TestCase( SECTION, 1.126 + "Or.toString()", 1.127 + or.valueOf(), 1.128 + Or.toString() ); 1.129 + 1.130 +new TestCase( SECTION, 1.131 + "And.toString()", 1.132 + and.valueOf(), 1.133 + And.toString() ); 1.134 + 1.135 +new TestCase( SECTION, 1.136 + "XOr.toString()", 1.137 + xor.valueOf(), 1.138 + XOr.toString() ); 1.139 + 1.140 +test(); 1.141 + 1.142 +function TestFunction( name, args, body ) { 1.143 + this.name = name; 1.144 + this.arguments = args.toString(); 1.145 + this.body = body; 1.146 + 1.147 + /* the format of Function.toString() in JavaScript 1.2 is: 1.148 + function name ( arguments ) { 1.149 + body 1.150 + } 1.151 + */ 1.152 + this.value = "function " + (name ? name : "anonymous" )+ 1.153 + "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}"; 1.154 + 1.155 + this.toString = new Function( "return this.value" ); 1.156 + this.valueOf = new Function( "return this.value" ); 1.157 + return this; 1.158 +}