|
1 // |reftest| skip -- obsolete test |
|
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 |
|
8 /** |
|
9 File Name: tostring-1.js |
|
10 Section: Function.toString |
|
11 Description: |
|
12 |
|
13 Since the behavior of Function.toString() is implementation-dependent, |
|
14 toString tests for function are not in the ECMA suite. |
|
15 |
|
16 Currently, an attempt to parse the toString output for some functions |
|
17 and verify that the result is something reasonable. |
|
18 |
|
19 This verifies |
|
20 http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99212 |
|
21 |
|
22 Author: christine@netscape.com |
|
23 Date: 12 november 1997 |
|
24 */ |
|
25 |
|
26 var SECTION = "tostring-2"; |
|
27 var VERSION = "JS1_2"; |
|
28 var TITLE = "Function.toString()"; |
|
29 var BUGNUMBER="123444"; |
|
30 startTest(); |
|
31 |
|
32 writeHeaderToLog( SECTION + " "+ TITLE); |
|
33 |
|
34 var tab = " "; |
|
35 |
|
36 |
|
37 var equals = new TestFunction( "Equals", "a, b", tab+ "return a == b;" ); |
|
38 function Equals (a, b) { |
|
39 return a == b; |
|
40 } |
|
41 |
|
42 var reallyequals = new TestFunction( "ReallyEquals", "a, b", |
|
43 ( version() <= 120 ) ? tab +"return a == b;" : tab +"return a === b;" ); |
|
44 function ReallyEquals( a, b ) { |
|
45 return a === b; |
|
46 } |
|
47 |
|
48 var doesntequal = new TestFunction( "DoesntEqual", "a, b", tab + "return a != b;" ); |
|
49 function DoesntEqual( a, b ) { |
|
50 return a != b; |
|
51 } |
|
52 |
|
53 var reallydoesntequal = new TestFunction( "ReallyDoesntEqual", "a, b", |
|
54 ( version() <= 120 ) ? tab +"return a != b;" : tab +"return a !== b;" ); |
|
55 function ReallyDoesntEqual( a, b ) { |
|
56 return a !== b; |
|
57 } |
|
58 |
|
59 var testor = new TestFunction( "TestOr", "a", tab+"if (a == null || a == void 0) {\n"+ |
|
60 tab +tab+"return 0;\n"+tab+"} else {\n"+tab+tab+"return a;\n"+tab+"}" ); |
|
61 function TestOr( a ) { |
|
62 if ( a == null || a == void 0 ) |
|
63 return 0; |
|
64 else |
|
65 return a; |
|
66 } |
|
67 |
|
68 var testand = new TestFunction( "TestAnd", "a", tab+"if (a != null && a != void 0) {\n"+ |
|
69 tab+tab+"return a;\n" + tab+ "} else {\n"+tab+tab+"return 0;\n"+tab+"}" ); |
|
70 function TestAnd( a ) { |
|
71 if ( a != null && a != void 0 ) |
|
72 return a; |
|
73 else |
|
74 return 0; |
|
75 } |
|
76 |
|
77 var or = new TestFunction( "Or", "a, b", tab + "return a | b;" ); |
|
78 function Or( a, b ) { |
|
79 return a | b; |
|
80 } |
|
81 |
|
82 var and = new TestFunction( "And", "a, b", tab + "return a & b;" ); |
|
83 function And( a, b ) { |
|
84 return a & b; |
|
85 } |
|
86 |
|
87 var xor = new TestFunction( "XOr", "a, b", tab + "return a ^ b;" ); |
|
88 function XOr( a, b ) { |
|
89 return a ^ b; |
|
90 } |
|
91 |
|
92 new TestCase( SECTION, |
|
93 "Equals.toString()", |
|
94 equals.valueOf(), |
|
95 Equals.toString() ); |
|
96 |
|
97 new TestCase( SECTION, |
|
98 "ReallyEquals.toString()", |
|
99 reallyequals.valueOf(), |
|
100 ReallyEquals.toString() ); |
|
101 |
|
102 new TestCase( SECTION, |
|
103 "DoesntEqual.toString()", |
|
104 doesntequal.valueOf(), |
|
105 DoesntEqual.toString() ); |
|
106 |
|
107 new TestCase( SECTION, |
|
108 "ReallyDoesntEqual.toString()", |
|
109 reallydoesntequal.valueOf(), |
|
110 ReallyDoesntEqual.toString() ); |
|
111 |
|
112 new TestCase( SECTION, |
|
113 "TestOr.toString()", |
|
114 testor.valueOf(), |
|
115 TestOr.toString() ); |
|
116 |
|
117 new TestCase( SECTION, |
|
118 "TestAnd.toString()", |
|
119 testand.valueOf(), |
|
120 TestAnd.toString() ); |
|
121 |
|
122 new TestCase( SECTION, |
|
123 "Or.toString()", |
|
124 or.valueOf(), |
|
125 Or.toString() ); |
|
126 |
|
127 new TestCase( SECTION, |
|
128 "And.toString()", |
|
129 and.valueOf(), |
|
130 And.toString() ); |
|
131 |
|
132 new TestCase( SECTION, |
|
133 "XOr.toString()", |
|
134 xor.valueOf(), |
|
135 XOr.toString() ); |
|
136 |
|
137 test(); |
|
138 |
|
139 function TestFunction( name, args, body ) { |
|
140 this.name = name; |
|
141 this.arguments = args.toString(); |
|
142 this.body = body; |
|
143 |
|
144 /* the format of Function.toString() in JavaScript 1.2 is: |
|
145 function name ( arguments ) { |
|
146 body |
|
147 } |
|
148 */ |
|
149 this.value = "function " + (name ? name : "anonymous" )+ |
|
150 "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}"; |
|
151 |
|
152 this.toString = new Function( "return this.value" ); |
|
153 this.valueOf = new Function( "return this.value" ); |
|
154 return this; |
|
155 } |