equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2010, 2013, 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 * NASHORN-58 |
|
26 * |
|
27 * @test |
|
28 * @run |
|
29 */ |
|
30 |
|
31 function test1() { |
|
32 var x = 1; |
|
33 try { |
|
34 print('try'); |
|
35 x = 2; |
|
36 } catch(e) { |
|
37 print('catch'); |
|
38 } finally { |
|
39 print('finally'); |
|
40 x = 3; |
|
41 } |
|
42 print(x); |
|
43 } |
|
44 |
|
45 function test2() { |
|
46 var x = 1; |
|
47 try { |
|
48 print('try'); |
|
49 } finally { |
|
50 print('finally'); |
|
51 x = 2; |
|
52 } |
|
53 print(x); |
|
54 } |
|
55 |
|
56 function test3() { |
|
57 try { |
|
58 return 2; |
|
59 } finally { |
|
60 return 3; |
|
61 } |
|
62 } |
|
63 |
|
64 function test4() { |
|
65 try { |
|
66 x = 1; |
|
67 print(x); |
|
68 try { |
|
69 x = 2; |
|
70 print(x); |
|
71 } finally { |
|
72 x = 3; |
|
73 print(x) |
|
74 try { |
|
75 x = 4; |
|
76 print(x); |
|
77 } finally { |
|
78 x = 5; |
|
79 print(x); |
|
80 } |
|
81 } |
|
82 print(x) |
|
83 } finally { |
|
84 x = 6; |
|
85 print(x); |
|
86 } |
|
87 print(x); |
|
88 } |
|
89 |
|
90 function test5() { |
|
91 try { |
|
92 x = 1; |
|
93 print(x); |
|
94 try { |
|
95 x = 2; |
|
96 print(x); |
|
97 } finally { |
|
98 x = 3; |
|
99 print(x) |
|
100 try { |
|
101 x = 4; |
|
102 print(x); |
|
103 } finally { |
|
104 x = 5; |
|
105 return x; |
|
106 } |
|
107 } |
|
108 print(x) |
|
109 } finally { |
|
110 x = 6; |
|
111 return x; |
|
112 } |
|
113 } |
|
114 |
|
115 function test6() { |
|
116 try { |
|
117 throw new Error("testing"); |
|
118 } catch (ex) { |
|
119 print(ex); |
|
120 return; |
|
121 } finally { |
|
122 print("finally"); |
|
123 } |
|
124 } |
|
125 |
|
126 function test7() { |
|
127 var e = new Error("no message"); |
|
128 var i = 3; |
|
129 try { |
|
130 throw e; |
|
131 } catch (ex) { |
|
132 } finally { |
|
133 i++; |
|
134 } |
|
135 if (i != 4) { |
|
136 print("FAIL"); |
|
137 } |
|
138 print("SUCCESS"); |
|
139 } |
|
140 |
|
141 |
|
142 test1(); |
|
143 test2(); |
|
144 print(test3()); |
|
145 test4(); |
|
146 print(test5()) |
|
147 test6(); |
|
148 test7(); |
|
149 |