|
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 Author: christine@netscape.com |
|
20 Date: 12 november 1997 |
|
21 */ |
|
22 |
|
23 var SECTION = "tostring-1"; |
|
24 var VERSION = "JS1_2"; |
|
25 startTest(); |
|
26 var TITLE = "Function.toString()"; |
|
27 |
|
28 writeHeaderToLog( SECTION + " "+ TITLE); |
|
29 |
|
30 var tab = " "; |
|
31 |
|
32 t1 = new TestFunction( "stub", "value", tab + "return value;" ); |
|
33 |
|
34 t2 = new TestFunction( "ToString", "object", tab+"return object + \"\";" ); |
|
35 |
|
36 t3 = new TestFunction( "Add", "a, b, c, d, e", tab +"var s = a + b + c + d + e;\n" + |
|
37 tab + "return s;" ); |
|
38 |
|
39 t4 = new TestFunction( "noop", "value" ); |
|
40 |
|
41 t5 = new TestFunction( "anonymous", "", tab+"return \"hello!\";" ); |
|
42 |
|
43 var f = new Function( "return \"hello!\""); |
|
44 |
|
45 new TestCase( SECTION, |
|
46 "stub.toString()", |
|
47 t1.valueOf(), |
|
48 stub.toString() ); |
|
49 |
|
50 new TestCase( SECTION, |
|
51 "ToString.toString()", |
|
52 t2.valueOf(), |
|
53 ToString.toString() ); |
|
54 |
|
55 new TestCase( SECTION, |
|
56 "Add.toString()", |
|
57 t3.valueOf(), |
|
58 Add.toString() ); |
|
59 |
|
60 new TestCase( SECTION, |
|
61 "noop.toString()", |
|
62 t4.toString(), |
|
63 noop.toString() ); |
|
64 |
|
65 new TestCase( SECTION, |
|
66 "f.toString()", |
|
67 t5.toString(), |
|
68 f.toString() ); |
|
69 test(); |
|
70 |
|
71 function noop( value ) { |
|
72 } |
|
73 function Add( a, b, c, d, e ) { |
|
74 var s = a + b + c + d + e; |
|
75 return s; |
|
76 } |
|
77 function stub( value ) { |
|
78 return value; |
|
79 } |
|
80 function ToString( object ) { |
|
81 return object + ""; |
|
82 } |
|
83 |
|
84 function ToBoolean( value ) { |
|
85 if ( value == 0 || value == NaN || value == false ) { |
|
86 return false; |
|
87 } else { |
|
88 return true; |
|
89 } |
|
90 } |
|
91 |
|
92 function TestFunction( name, args, body ) { |
|
93 if ( name == "anonymous" && version() == 120 ) { |
|
94 name = ""; |
|
95 } |
|
96 |
|
97 this.name = name; |
|
98 this.arguments = args.toString(); |
|
99 this.body = body; |
|
100 |
|
101 /* the format of Function.toString() in JavaScript 1.2 is: |
|
102 function name ( arguments ) { |
|
103 body |
|
104 } |
|
105 */ |
|
106 this.value = "function " + (name ? name : "" )+ |
|
107 "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}"; |
|
108 |
|
109 this.toString = new Function( "return this.value" ); |
|
110 this.valueOf = new Function( "return this.value" ); |
|
111 return this; |
|
112 } |