]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/ecma_2/Statements/try-012.js
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma_2 / Statements / try-012.js
CommitLineData
b37bf2e1
A
1/**
2 * File Name: try-012.js
3 * ECMA Section:
4 * Description: The try statement
5 *
6 * This test has a try with no catch, and a finally. This is like try-003,
7 * but throws from a finally block, not the try block.
8 *
9 * Author: christine@netscape.com
10 * Date: 11 August 1998
11 */
12 var SECTION = "try-012";
13 var VERSION = "ECMA_2";
14 var TITLE = "The try statement";
15 var BUGNUMBER="336872";
16
17 startTest();
18 writeHeaderToLog( SECTION + " "+ TITLE);
19
20 var tc = 0;
21 var testcases = new Array();
22
23 // Tests start here.
24
25 TrySomething( "x = \"hi\"", true );
26 TrySomething( "throw \"boo\"", true );
27 TrySomething( "throw 3", true );
28
29 test();
30
31 /**
32 * This function contains a try block with no catch block,
33 * but it does have a finally block. Try to evaluate expressions
34 * that do and do not throw exceptions.
35 *
36 * The productioni TryStatement Block Finally is evaluated as follows:
37 * 1. Evaluate Block
38 * 2. Evaluate Finally
39 * 3. If Result(2).type is normal return result 1 (in the test case, result 1 has
40 * the completion type throw)
41 * 4. return result 2 (does not get hit in this case)
42 *
43 */
44
45 function TrySomething( expression, throwing ) {
46 innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK";
47 if (throwing) {
48 outerCatch = "FAILED: NO EXCEPTION CAUGHT";
49 } else {
50 outerCatch = "PASS";
51 }
52 outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK";
53
54
55 // If the inner finally does not throw an exception, the result
56 // of the try block should be returned. (Type of inner return
57 // value should be throw if finally executes correctly
58
59 try {
60 try {
61 throw 0;
62 } finally {
63 innerFinally = "PASS";
64 eval( expression );
65 }
66 } catch ( e ) {
67 if (throwing) {
68 outerCatch = "PASS";
69 } else {
70 outerCatch = "FAIL: HIT OUTER CATCH BLOCK";
71 }
72 } finally {
73 outerFinally = "PASS";
74 }
75
76
77 testcases[tc++] = new TestCase(
78 SECTION,
79 "eval( " + expression +" ): evaluated inner finally block",
80 "PASS",
81 innerFinally );
82 testcases[tc++] = new TestCase(
83 SECTION,
84 "eval( " + expression +" ): evaluated outer catch block ",
85 "PASS",
86 outerCatch );
87 testcases[tc++] = new TestCase(
88 SECTION,
89 "eval( " + expression +" ): evaluated outer finally block",
90 "PASS",
91 outerFinally );
92 }