|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 * File Name: try-012.js |
|
9 * ECMA Section: |
|
10 * Description: The try statement |
|
11 * |
|
12 * This test has a try with no catch, and a finally. This is like try-003, |
|
13 * but throws from a finally block, not the try block. |
|
14 * |
|
15 * Author: christine@netscape.com |
|
16 * Date: 11 August 1998 |
|
17 */ |
|
18 var SECTION = "try-012"; |
|
19 var VERSION = "ECMA_2"; |
|
20 var TITLE = "The try statement"; |
|
21 var BUGNUMBER="336872"; |
|
22 |
|
23 startTest(); |
|
24 writeHeaderToLog( SECTION + " "+ TITLE); |
|
25 |
|
26 // Tests start here. |
|
27 |
|
28 TrySomething( "x = \"hi\"", true ); |
|
29 TrySomething( "throw \"boo\"", true ); |
|
30 TrySomething( "throw 3", true ); |
|
31 |
|
32 test(); |
|
33 |
|
34 /** |
|
35 * This function contains a try block with no catch block, |
|
36 * but it does have a finally block. Try to evaluate expressions |
|
37 * that do and do not throw exceptions. |
|
38 * |
|
39 * The productioni TryStatement Block Finally is evaluated as follows: |
|
40 * 1. Evaluate Block |
|
41 * 2. Evaluate Finally |
|
42 * 3. If Result(2).type is normal return result 1 (in the test case, result 1 has |
|
43 * the completion type throw) |
|
44 * 4. return result 2 (does not get hit in this case) |
|
45 * |
|
46 */ |
|
47 |
|
48 function TrySomething( expression, throwing ) { |
|
49 innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK"; |
|
50 if (throwing) { |
|
51 outerCatch = "FAILED: NO EXCEPTION CAUGHT"; |
|
52 } else { |
|
53 outerCatch = "PASS"; |
|
54 } |
|
55 outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK"; |
|
56 |
|
57 |
|
58 // If the inner finally does not throw an exception, the result |
|
59 // of the try block should be returned. (Type of inner return |
|
60 // value should be throw if finally executes correctly |
|
61 |
|
62 try { |
|
63 try { |
|
64 throw 0; |
|
65 } finally { |
|
66 innerFinally = "PASS"; |
|
67 eval( expression ); |
|
68 } |
|
69 } catch ( e ) { |
|
70 if (throwing) { |
|
71 outerCatch = "PASS"; |
|
72 } else { |
|
73 outerCatch = "FAIL: HIT OUTER CATCH BLOCK"; |
|
74 } |
|
75 } finally { |
|
76 outerFinally = "PASS"; |
|
77 } |
|
78 |
|
79 |
|
80 new TestCase( |
|
81 SECTION, |
|
82 "eval( " + expression +" ): evaluated inner finally block", |
|
83 "PASS", |
|
84 innerFinally ); |
|
85 new TestCase( |
|
86 SECTION, |
|
87 "eval( " + expression +" ): evaluated outer catch block ", |
|
88 "PASS", |
|
89 outerCatch ); |
|
90 new TestCase( |
|
91 SECTION, |
|
92 "eval( " + expression +" ): evaluated outer finally block", |
|
93 "PASS", |
|
94 outerFinally ); |
|
95 } |