1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Statements/try-003.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 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-003.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. 1.16 + * 1.17 + * Author: christine@netscape.com 1.18 + * Date: 11 August 1998 1.19 + */ 1.20 +var SECTION = "try-003"; 1.21 +var VERSION = "ECMA_2"; 1.22 +var TITLE = "The try statement"; 1.23 +var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=313585"; 1.24 + 1.25 +startTest(); 1.26 +writeHeaderToLog( SECTION + " "+ TITLE); 1.27 + 1.28 +// Tests start here. 1.29 + 1.30 +TrySomething( "x = \"hi\"", false ); 1.31 +TrySomething( "throw \"boo\"", true ); 1.32 +TrySomething( "throw 3", true ); 1.33 + 1.34 +test(); 1.35 + 1.36 +/** 1.37 + * This function contains a try block with no catch block, 1.38 + * but it does have a finally block. Try to evaluate expressions 1.39 + * that do and do not throw exceptions. 1.40 + */ 1.41 + 1.42 +function TrySomething( expression, throwing ) { 1.43 + innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK"; 1.44 + if (throwing) { 1.45 + outerCatch = "FAILED: NO EXCEPTION CAUGHT"; 1.46 + } else { 1.47 + outerCatch = "PASS"; 1.48 + } 1.49 + outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK"; 1.50 + 1.51 + try { 1.52 + try { 1.53 + eval( expression ); 1.54 + } finally { 1.55 + innerFinally = "PASS"; 1.56 + } 1.57 + } catch ( e ) { 1.58 + if (throwing) { 1.59 + outerCatch = "PASS"; 1.60 + } else { 1.61 + outerCatch = "FAIL: HIT OUTER CATCH BLOCK"; 1.62 + } 1.63 + } finally { 1.64 + outerFinally = "PASS"; 1.65 + } 1.66 + 1.67 + 1.68 + new TestCase( 1.69 + SECTION, 1.70 + "eval( " + expression +" )", 1.71 + "PASS", 1.72 + innerFinally ); 1.73 + new TestCase( 1.74 + SECTION, 1.75 + "eval( " + expression +" )", 1.76 + "PASS", 1.77 + outerCatch ); 1.78 + new TestCase( 1.79 + SECTION, 1.80 + "eval( " + expression +" )", 1.81 + "PASS", 1.82 + outerFinally ); 1.83 + 1.84 + 1.85 +}