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

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

mercurial