| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'tostring-1.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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 |
|
| 102 |
|
| 103 |
|
| 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 |
} |