]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_2/Statements/try-007.js
JavaScriptCore-576.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma_2 / Statements / try-007.js
1 /**
2 * File Name: try-007.js
3 * ECMA Section:
4 * Description: The try statement
5 *
6 * This test has a for-in statement within a try block.
7 *
8 *
9 * Author: christine@netscape.com
10 * Date: 11 August 1998
11 */
12 var SECTION = "try-007";
13 var VERSION = "ECMA_2";
14 var TITLE = "The try statement: for-in";
15
16 startTest();
17 writeHeaderToLog( SECTION + " "+ TITLE);
18
19 var tc = 0;
20 var testcases = new Array();
21
22 /**
23 * This is the "check" function for test objects that will
24 * throw an exception.
25 */
26 function throwException() {
27 throw EXCEPTION_STRING +": " + this.valueOf();
28 }
29 var EXCEPTION_STRING = "Exception thrown:";
30
31 /**
32 * This is the "check" function for test objects that do not
33 * throw an exception
34 */
35 function noException() {
36 return this.valueOf();
37 }
38
39 /**
40 * Add test cases here
41 */
42 TryForIn( new TryObject( "hello", throwException, true ));
43 TryForIn( new TryObject( "hola", noException, false ));
44
45 /**
46 * Run the test.
47 */
48
49 test();
50
51 /**
52 * This is the object that will be the "this" in a with block.
53 * The check function is either throwExeption() or noException().
54 * See above.
55 *
56 */
57 function TryObject( value, fun, exception ) {
58 this.value = value;
59 this.exception = exception;
60
61 this.check = fun;
62 this.valueOf = function () { return this.value; }
63 }
64
65 /**
66 * This function has a for-in statement within a try block. Test cases
67 * are added after the try-catch-finally statement. Within the for-in
68 * block, call a function that can throw an exception. Verify that any
69 * exceptions are properly caught.
70 */
71
72 function TryForIn( object ) {
73 try {
74 for ( p in object ) {
75 if ( typeof object[p] == "function" ) {
76 result = object[p]();
77 }
78 }
79 } catch ( e ) {
80 result = e;
81 }
82
83 testcases[tc++] = new TestCase(
84 SECTION,
85 "TryForIn( " + object+ " )",
86 (object.exception ? EXCEPTION_STRING +": " + object.value : object.value),
87 result );
88
89 }