Debian Codegraph @

rhino/testsrc/tests/ecma_2/Statements/try-012.js

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