finally-catchalls.js revision 2:da1e581c933b
1/*
2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/**
25 * finally-catchalls: should not be able to read, write, call properties from null literal.
26 *
27 * @test
28 * @run
29 */
30
31function test1() {
32    try {
33	print("try");
34	throw "ex";
35    } finally {
36	print("finally");
37    }
38}
39
40function test2() {
41    try {
42	print("try");
43    } finally {
44	print("finally");
45    }
46}
47
48function test3() {
49    try {
50	print("try");
51	return;
52    } finally {
53	print("finally");
54    }
55}
56
57function test4() {
58    var i = 0;
59    while (i<10) {
60	try {
61	    print("try "+i);
62	    i++;
63	    continue;
64	} finally {
65	    print("finally "+i);
66	}
67    }
68    print(i);
69}
70
71function test5() {
72    var i = 0;
73    while (i<10) {
74	try {
75	    print("try "+i);
76	    i++;
77	    break;
78	} finally {
79	    print("finally "+i);
80	}
81    }
82    print(i);
83}
84
85function test6() {
86    var i = 0;
87    while (i<10) {
88	try {
89	    print("try "+i);
90	    if (i == 5)
91		break;
92	    i++;
93	} finally {
94	    print("finally "+i);
95	}
96    }
97    print(i);
98}
99
100print("\ntest 1\n");
101try {
102    test1();
103} catch (e) {
104    print("got e");
105}
106
107print("\ntest 2\n");
108test2();
109
110print("\ntest 3\n");
111test3();
112
113print("\ntest 4\n");
114test4();
115
116print("\ntest 5\n");
117test5();
118
119print("\ntest 6\n");
120test6();
121
122