S12.14_A17.js (997B)
1 // Copyright 2009 the Sputnik authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 info: Using "try" with "catch" or "finally" statement in a constructor 6 es5id: 12.14_A17 7 description: Creating exceptions within constructor 8 ---*/ 9 10 var i=1; 11 function Integer( value, exception ) { 12 try{ 13 this.value = checkValue( value ); 14 if(exception) throw new Test262Error('#'+i+'.1: Must be exception'); 15 } 16 catch(e){ 17 this.value = e.toString(); 18 if(!exception) throw new Test262Error('#'+i+'.2: Don`t must be exception'); 19 } 20 i++; 21 } 22 23 function checkValue(value){ 24 if(Math.floor(value)!=value||isNaN(value)){ 25 throw (INVALID_INTEGER_VALUE +": " + value); 26 } 27 else{ 28 return value; 29 } 30 } 31 32 // CHECK#1 33 new Integer(13, false); 34 // CHECK#2 35 new Integer(NaN, true); 36 // CHECK#3 37 new Integer(0, false); 38 // CHECK#4 39 new Integer(Infinity, false); 40 // CHECK#5 41 new Integer(-1.23, true); 42 // CHECK#6 43 new Integer(Math.LN2, true); 44 45 reportCompare(0, 0);