Debian Codegraph @

rhino/testsrc/tests/ecma_2/Statements/try-001.js

raw symbols SCIP
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/. */
5
6 gTestfile = 'try-001.js';
7
8 /**
9 * File Name: try-001.js
10 * ECMA Section:
11 * Description: The try statement
12 *
13 * This test contains try, catch, and finally blocks. An exception is
14 * sometimes thrown by a function called from within the try block.
15 *
16 * This test doesn't actually make any LiveConnect calls.
17 *
18 *
19 * Author: [email protected]
20 * Date: 11 August 1998
21 */
22 var SECTION = "";
23 var VERSION = "ECMA_2";
24 var TITLE = "The try statement";
25
26 startTest();
27 writeHeaderToLog( SECTION + " "+ TITLE);
28
29 var INVALID_JAVA_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor";
30
31 TryNewJavaInteger( "3.14159", INVALID_JAVA_INTEGER_VALUE );
32 TryNewJavaInteger( NaN, INVALID_JAVA_INTEGER_VALUE );
33 TryNewJavaInteger( 0, 0 );
34 TryNewJavaInteger( -1, -1 );
35 TryNewJavaInteger( 1, 1 );
36 TryNewJavaInteger( Infinity, Infinity );
37
38 test();
39
40 /**
41 * Check to see if the input is valid for java.lang.Integer. If it is
42 * not valid, throw INVALID_JAVA_INTEGER_VALUE. If input is valid,
43 * return Number( v )
44 *
45 */
46
47 function newJavaInteger( v ) {
48 value = Number( v );
49 if ( Math.floor(value) != value || isNaN(value) ) {
50 throw ( INVALID_JAVA_INTEGER_VALUE );
51 } else {
52 return value;
53 }
54 }
55
56 /**
57 * Call newJavaInteger( value ) from within a try block. Catch any
58 * exception, and store it in result. Verify that we got the right
59 * return value from newJavaInteger in cases in which we do not expect
60 * exceptions, and that we got the exception in cases where an exception
61 * was expected.
62 */
63 function TryNewJavaInteger( value, expect ) {
64 var finalTest = false;
65
66 try {
67 result = newJavaInteger( value );
68 } catch ( e ) {
69 result = String( e );
70 } finally {
71 finalTest = true;
72 }
73 new TestCase(
74 SECTION,
75 "newJavaValue( " + value +" )",
76 expect,
77 result);
78
79 new TestCase(
80 SECTION,
81 "newJavaValue( " + value +" ) hit finally block",
82 true,
83 finalTest);
84
85 }
86