|
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-003.js |
|
9 * ECMA Section: |
|
10 * Description: The try statement |
|
11 * |
|
12 * This test has a try with no catch, and a finally. |
|
13 * |
|
14 * Author: christine@netscape.com |
|
15 * Date: 11 August 1998 |
|
16 */ |
|
17 var SECTION = "try-003"; |
|
18 var VERSION = "ECMA_2"; |
|
19 var TITLE = "The try statement"; |
|
20 var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=313585"; |
|
21 |
|
22 startTest(); |
|
23 writeHeaderToLog( SECTION + " "+ TITLE); |
|
24 |
|
25 // Tests start here. |
|
26 |
|
27 TrySomething( "x = \"hi\"", false ); |
|
28 TrySomething( "throw \"boo\"", true ); |
|
29 TrySomething( "throw 3", true ); |
|
30 |
|
31 test(); |
|
32 |
|
33 /** |
|
34 * This function contains a try block with no catch block, |
|
35 * but it does have a finally block. Try to evaluate expressions |
|
36 * that do and do not throw exceptions. |
|
37 */ |
|
38 |
|
39 function TrySomething( expression, throwing ) { |
|
40 innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK"; |
|
41 if (throwing) { |
|
42 outerCatch = "FAILED: NO EXCEPTION CAUGHT"; |
|
43 } else { |
|
44 outerCatch = "PASS"; |
|
45 } |
|
46 outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK"; |
|
47 |
|
48 try { |
|
49 try { |
|
50 eval( expression ); |
|
51 } finally { |
|
52 innerFinally = "PASS"; |
|
53 } |
|
54 } catch ( e ) { |
|
55 if (throwing) { |
|
56 outerCatch = "PASS"; |
|
57 } else { |
|
58 outerCatch = "FAIL: HIT OUTER CATCH BLOCK"; |
|
59 } |
|
60 } finally { |
|
61 outerFinally = "PASS"; |
|
62 } |
|
63 |
|
64 |
|
65 new TestCase( |
|
66 SECTION, |
|
67 "eval( " + expression +" )", |
|
68 "PASS", |
|
69 innerFinally ); |
|
70 new TestCase( |
|
71 SECTION, |
|
72 "eval( " + expression +" )", |
|
73 "PASS", |
|
74 outerCatch ); |
|
75 new TestCase( |
|
76 SECTION, |
|
77 "eval( " + expression +" )", |
|
78 "PASS", |
|
79 outerFinally ); |
|
80 |
|
81 |
|
82 } |