Debian Codegraph @

rhino/testsrc/tests/ecma_2/Statements/try-009.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-009.js';
7
8 /**
9 * File Name: try-009.js
10 * ECMA Section:
11 * Description: The try statement
12 *
13 * This test has a try block within a while block. Verify that an exception
14 * breaks out of the while. I don't really know why this is an interesting
15 * test case but Mike Shaver had two of these so what the hey.
16 *
17 * Author: [email protected]
18 * Date: 11 August 1998
19 */
20 var SECTION = "try-009";
21 var VERSION = "ECMA_2";
22 var TITLE = "The try statement: try in a while block";
23
24 startTest();
25 writeHeaderToLog( SECTION + " "+ TITLE);
26
27 var EXCEPTION_STRING = "Exception thrown: ";
28 var NO_EXCEPTION_STRING = "No exception thrown: ";
29
30
31 TryInWhile( new TryObject( "hello", ThrowException, true ) );
32 TryInWhile( new TryObject( "aloha", NoException, false ));
33
34 test();
35
36 function TryObject( value, throwFunction, result ) {
37 this.value = value;
38 this.thrower = throwFunction;
39 this.result = result;
40 }
41 function ThrowException() {
42 throw EXCEPTION_STRING + this.value;
43 }
44 function NoException() {
45 return NO_EXCEPTION_STRING + this.value;
46 }
47 function TryInWhile( object ) {
48 result = null;
49 while ( true ) {
50 try {
51 object.thrower();
52 result = NO_EXCEPTION_STRING + object.value;
53 break;
54 } catch ( e ) {
55 result = e;
56 break;
57 }
58 }
59
60 new TestCase(
61 SECTION,
62 "( "+ object +".thrower() )",
63 (object.result
64 ? EXCEPTION_STRING + object.value :
65 NO_EXCEPTION_STRING + object.value),
66 result );
67 }