1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/test262/ch12/12.14/S12.14_A17.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +// Copyright 2009 the Sputnik authors. All rights reserved. 1.5 +// This code is governed by the BSD license found in the LICENSE file. 1.6 + 1.7 +/** 1.8 + * Using "try" with "catch" or "finally" statement in a constructor 1.9 + * 1.10 + * @path ch12/12.14/S12.14_A17.js 1.11 + * @description Creating exceptions within constructor 1.12 + */ 1.13 + 1.14 +var i=1; 1.15 +function Integer( value, exception ) { 1.16 + try{ 1.17 + this.value = checkValue( value ); 1.18 + if(exception) $ERROR('#'+i+'.1: Must be exception'); 1.19 + } 1.20 + catch(e){ 1.21 + this.value = e.toString(); 1.22 + if(!exception) $ERROR('#'+i+'.2: Don`t must be exception'); 1.23 + } 1.24 + i++; 1.25 +} 1.26 + 1.27 +function checkValue(value){ 1.28 + if(Math.floor(value)!=value||isNaN(value)){ 1.29 + throw (INVALID_INTEGER_VALUE +": " + value); 1.30 + } 1.31 + else{ 1.32 + return value; 1.33 + } 1.34 +} 1.35 + 1.36 +// CHECK#1 1.37 +new Integer(13, false); 1.38 +// CHECK#2 1.39 +new Integer(NaN, true); 1.40 +// CHECK#3 1.41 +new Integer(0, false); 1.42 +// CHECK#4 1.43 +new Integer(Infinity, false); 1.44 +// CHECK#5 1.45 +new Integer(-1.23, true); 1.46 +// CHECK#6 1.47 +new Integer(Math.LN2, true); 1.48 +