Debian Codegraph @

rhino/testsrc/tests/ecma_2/Statements/try-007.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-007.js';
7
8 /**
9 * File Name: try-007.js
10 * ECMA Section:
11 * Description: The try statement
12 *
13 * This test has a for-in statement within a try block.
14 *
15 *
16 * Author: [email protected]
17 * Date: 11 August 1998
18 */
19 var SECTION = "try-007";
20 var VERSION = "ECMA_2";
21 var TITLE = "The try statement: for-in";
22
23 startTest();
24 writeHeaderToLog( SECTION + " "+ TITLE);
25
26 /**
27 * This is the "check" function for test objects that will
28 * throw an exception.
29 */
30 function throwException() {
31 throw EXCEPTION_STRING +": " + this.valueOf();
32 }
33 var EXCEPTION_STRING = "Exception thrown:";
34
35 /**
36 * This is the "check" function for test objects that do not
37 * throw an exception
38 */
39 function noException() {
40 return this.valueOf();
41 }
42
43 /**
44 * Add test cases here
45 */
46 TryForIn( new TryObject( "hello", throwException, true ));
47 TryForIn( new TryObject( "hola", noException, false ));
48
49 /**
50 * Run the test.
51 */
52
53 test();
54
55 /**
56 * This is the object that will be the "this" in a with block.
57 * The check function is either throwException() or noException().
58 * See above.
59 *
60 */
61 function TryObject( value, fun, exception ) {
62 this.value = value;
63 this.exception = exception;
64
65 this.check = fun;
66 this.valueOf = function () { return this.value; }
67 }
68
69 /**
70 * This function has a for-in statement within a try block. Test cases
71 * are added after the try-catch-finally statement. Within the for-in
72 * block, call a function that can throw an exception. Verify that any
73 * exceptions are properly caught.
74 */
75
76 function TryForIn( object ) {
77 try {
78 for ( p in object ) {
79 if ( typeof object[p] == "function" ) {
80 result = object[p]();
81 }
82 }
83 } catch ( e ) {
84 result = e;
85 }
86
87 new TestCase(
88 SECTION,
89 "TryForIn( " + object+ " )",
90 (object.exception ? EXCEPTION_STRING +": " + object.value : object.value),
91 result );
92
93 }