1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Statements/try-012.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + * File Name: try-012.js 1.12 + * ECMA Section: 1.13 + * Description: The try statement 1.14 + * 1.15 + * This test has a try with no catch, and a finally. This is like try-003, 1.16 + * but throws from a finally block, not the try block. 1.17 + * 1.18 + * Author: christine@netscape.com 1.19 + * Date: 11 August 1998 1.20 + */ 1.21 +var SECTION = "try-012"; 1.22 +var VERSION = "ECMA_2"; 1.23 +var TITLE = "The try statement"; 1.24 +var BUGNUMBER="336872"; 1.25 + 1.26 +startTest(); 1.27 +writeHeaderToLog( SECTION + " "+ TITLE); 1.28 + 1.29 +// Tests start here. 1.30 + 1.31 +TrySomething( "x = \"hi\"", true ); 1.32 +TrySomething( "throw \"boo\"", true ); 1.33 +TrySomething( "throw 3", true ); 1.34 + 1.35 +test(); 1.36 + 1.37 +/** 1.38 + * This function contains a try block with no catch block, 1.39 + * but it does have a finally block. Try to evaluate expressions 1.40 + * that do and do not throw exceptions. 1.41 + * 1.42 + * The productioni TryStatement Block Finally is evaluated as follows: 1.43 + * 1. Evaluate Block 1.44 + * 2. Evaluate Finally 1.45 + * 3. If Result(2).type is normal return result 1 (in the test case, result 1 has 1.46 + * the completion type throw) 1.47 + * 4. return result 2 (does not get hit in this case) 1.48 + * 1.49 + */ 1.50 + 1.51 +function TrySomething( expression, throwing ) { 1.52 + innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK"; 1.53 + if (throwing) { 1.54 + outerCatch = "FAILED: NO EXCEPTION CAUGHT"; 1.55 + } else { 1.56 + outerCatch = "PASS"; 1.57 + } 1.58 + outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK"; 1.59 + 1.60 + 1.61 + // If the inner finally does not throw an exception, the result 1.62 + // of the try block should be returned. (Type of inner return 1.63 + // value should be throw if finally executes correctly 1.64 + 1.65 + try { 1.66 + try { 1.67 + throw 0; 1.68 + } finally { 1.69 + innerFinally = "PASS"; 1.70 + eval( expression ); 1.71 + } 1.72 + } catch ( e ) { 1.73 + if (throwing) { 1.74 + outerCatch = "PASS"; 1.75 + } else { 1.76 + outerCatch = "FAIL: HIT OUTER CATCH BLOCK"; 1.77 + } 1.78 + } finally { 1.79 + outerFinally = "PASS"; 1.80 + } 1.81 + 1.82 + 1.83 + new TestCase( 1.84 + SECTION, 1.85 + "eval( " + expression +" ): evaluated inner finally block", 1.86 + "PASS", 1.87 + innerFinally ); 1.88 + new TestCase( 1.89 + SECTION, 1.90 + "eval( " + expression +" ): evaluated outer catch block ", 1.91 + "PASS", 1.92 + outerCatch ); 1.93 + new TestCase( 1.94 + SECTION, 1.95 + "eval( " + expression +" ): evaluated outer finally block", 1.96 + "PASS", 1.97 + outerFinally ); 1.98 +}