1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Statements/try-005.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 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-005.js 1.12 + * ECMA Section: 1.13 + * Description: The try statement 1.14 + * 1.15 + * This test has a try with one catch block but no finally. Same 1.16 + * as try-004, but the eval statement is called from a function, not 1.17 + * directly from within the try block. 1.18 + * 1.19 + * Author: christine@netscape.com 1.20 + * Date: 11 August 1998 1.21 + */ 1.22 +var SECTION = "try-005"; 1.23 +var VERSION = "ECMA_2"; 1.24 +var TITLE = "The try statement"; 1.25 + 1.26 +startTest(); 1.27 +writeHeaderToLog( SECTION + " "+ TITLE); 1.28 + 1.29 +TryToCatch( "Math.PI", Math.PI ); 1.30 +TryToCatch( "Thrower(5)", "Caught 5" ); 1.31 +TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" ); 1.32 + 1.33 +test(); 1.34 + 1.35 +function Thrower( v ) { 1.36 + throw "Caught " + v; 1.37 +} 1.38 +function Eval( v ) { 1.39 + return eval( v ); 1.40 +} 1.41 + 1.42 +/** 1.43 + * Evaluate a string. Catch any exceptions thrown. If no exception is 1.44 + * expected, verify the result of the evaluation. If an exception is 1.45 + * expected, verify that we got the right exception. 1.46 + */ 1.47 + 1.48 +function TryToCatch( value, expect ) { 1.49 + try { 1.50 + result = Eval( value ); 1.51 + } catch ( e ) { 1.52 + result = e; 1.53 + } 1.54 + 1.55 + new TestCase( 1.56 + SECTION, 1.57 + "eval( " + value +" )", 1.58 + expect, 1.59 + result ); 1.60 +}