1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Statements/try-008.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 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-008.js 1.12 + * ECMA Section: 1.13 + * Description: The try statement 1.14 + * 1.15 + * This test has a try block in a constructor. 1.16 + * 1.17 + * 1.18 + * Author: christine@netscape.com 1.19 + * Date: 11 August 1998 1.20 + */ 1.21 +var SECTION = "try-008"; 1.22 +var VERSION = "ECMA_2"; 1.23 +var TITLE = "The try statement: try in a constructor"; 1.24 + 1.25 +startTest(); 1.26 +writeHeaderToLog( SECTION + " "+ TITLE); 1.27 + 1.28 +function Integer( value, exception ) { 1.29 + try { 1.30 + this.value = checkValue( value ); 1.31 + } catch ( e ) { 1.32 + this.value = e.toString(); 1.33 + } 1.34 + 1.35 + new TestCase( 1.36 + SECTION, 1.37 + "Integer( " + value +" )", 1.38 + (exception ? INVALID_INTEGER_VALUE +": " + value : this.value), 1.39 + this.value ); 1.40 +} 1.41 + 1.42 +var INVALID_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor"; 1.43 + 1.44 +function checkValue( value ) { 1.45 + if ( Math.floor(value) != value || isNaN(value) ) { 1.46 + throw ( INVALID_INTEGER_VALUE +": " + value ); 1.47 + } else { 1.48 + return value; 1.49 + } 1.50 +} 1.51 + 1.52 +// add test cases 1.53 + 1.54 +new Integer( 3, false ); 1.55 +new Integer( NaN, true ); 1.56 +new Integer( 0, false ); 1.57 +new Integer( Infinity, false ); 1.58 +new Integer( -2.12, true ); 1.59 +new Integer( Math.LN2, true ); 1.60 + 1.61 + 1.62 +test();