| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'try-007.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
var SECTION = "try-007"; |
| 20 |
var VERSION = "ECMA_2"; |
| 21 |
var TITLE = "The try statement: for-in"; |
| 22 |
|
| 23 |
startTest(); |
| 24 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
function throwException() { |
| 31 |
throw EXCEPTION_STRING +": " + this.valueOf(); |
| 32 |
} |
| 33 |
var EXCEPTION_STRING = "Exception thrown:"; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
function noException() { |
| 40 |
return this.valueOf(); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
TryForIn( new TryObject( "hello", throwException, true )); |
| 47 |
TryForIn( new TryObject( "hola", noException, false )); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
test(); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
function TryObject( value, fun, exception ) { |
| 62 |
this.value = value; |
| 63 |
this.exception = exception; |
| 64 |
|
| 65 |
this.check = fun; |
| 66 |
this.valueOf = function () { return this.value; } |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
function TryForIn( object ) { |
| 77 |
try { |
| 78 |
for ( p in object ) { |
| 79 |
if ( typeof object[p] == "function" ) { |
| 80 |
result = object[p](); |
| 81 |
} |
| 82 |
} |
| 83 |
} catch ( e ) { |
| 84 |
result = e; |
| 85 |
} |
| 86 |
|
| 87 |
new TestCase( |
| 88 |
SECTION, |
| 89 |
"TryForIn( " + object+ " )", |
| 90 |
(object.exception ? EXCEPTION_STRING +": " + object.value : object.value), |
| 91 |
result ); |
| 92 |
|
| 93 |
} |