js/src/tests/ecma_2/Statements/try-001.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8  *  File Name:          try-001.js
     9  *  ECMA Section:
    10  *  Description:        The try statement
    11  *
    12  *  This test contains try, catch, and finally blocks.  An exception is
    13  *  sometimes thrown by a function called from within the try block.
    14  *
    15  *
    16  *  Author:             christine@netscape.com
    17  *  Date:               11 August 1998
    18  */
    19 var SECTION = "";
    20 var VERSION = "ECMA_2";
    21 var TITLE   = "The try statement";
    23 startTest();
    24 writeHeaderToLog( SECTION + " "+ TITLE);
    26 var INVALID_JAVA_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor";
    28 TryNewJavaInteger( "3.14159", INVALID_JAVA_INTEGER_VALUE );
    29 TryNewJavaInteger( NaN, INVALID_JAVA_INTEGER_VALUE );
    30 TryNewJavaInteger( 0,  0 );
    31 TryNewJavaInteger( -1, -1 );
    32 TryNewJavaInteger( 1,  1 );
    33 TryNewJavaInteger( Infinity, Infinity );
    35 test();
    37 /**
    38  *  Check to see if the input is valid for java.lang.Integer. If it is
    39  *  not valid, throw INVALID_JAVA_INTEGER_VALUE.  If input is valid,
    40  *  return Number( v )
    41  *
    42  */
    44 function newJavaInteger( v ) {
    45   value = Number( v );
    46   if ( Math.floor(value) != value || isNaN(value) ) {
    47     throw ( INVALID_JAVA_INTEGER_VALUE );
    48   } else {
    49     return value;
    50   }
    51 }
    53 /**
    54  *  Call newJavaInteger( value ) from within a try block.  Catch any
    55  *  exception, and store it in result.  Verify that we got the right
    56  *  return value from newJavaInteger in cases in which we do not expect
    57  *  exceptions, and that we got the exception in cases where an exception
    58  *  was expected.
    59  */
    60 function TryNewJavaInteger( value, expect ) {
    61   var finalTest = false;
    63   try {
    64     result = newJavaInteger( value );
    65   } catch ( e ) {
    66     result = String( e );
    67   } finally {
    68     finalTest = true;
    69   }
    70   new TestCase(
    71     SECTION,
    72     "newJavaValue( " + value +" )",
    73     expect,
    74     result);
    76   new TestCase(
    77     SECTION,
    78     "newJavaValue( " + value +" ) hit finally block",
    79     true,
    80     finalTest);
    82 }

mercurial