1 /* |
1 /* |
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
8 * |
8 * |
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
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 |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
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 |
12 * version 2 for more details (a copy is included in the LICENSE file that |
13 * accompanied this code). |
13 * accompanied this code). |
14 * |
14 * |
15 * You should have received a copy of the GNU General Public License version |
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, |
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. |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 * |
18 * |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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 |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
168 var scope = {value:10}; |
168 var scope = {value:10}; |
169 var scope2 = {value:20}; |
169 var scope2 = {value:20}; |
170 var outer = 0; |
170 var outer = 0; |
171 outer_label: |
171 outer_label: |
172 while (outer < 5) { |
172 while (outer < 5) { |
173 var i=0; |
173 var i=0; |
174 while (i < 10) { |
174 while (i < 10) { |
175 with(scope) { |
175 with(scope) { |
176 print("loop header "+i); |
176 print("loop header "+i); |
177 with (scope2) { |
177 with (scope2) { |
178 value = 11; |
178 value = 11; |
179 i++; |
179 i++; |
180 if ((i & 1) != 0) { |
180 if ((i & 1) != 0) { |
181 print("continue"); |
181 print("continue"); |
182 outer++; |
182 outer++; |
183 continue outer_label; |
183 continue outer_label; |
184 } |
184 } |
185 } |
185 } |
186 } |
186 } |
187 print(value); |
187 print(value); |
188 } |
188 } |
189 } |
189 } |
190 } |
190 } |
191 |
191 |
192 //labelled break |
192 //labelled break |
193 function test6() { |
193 function test6() { |
194 var value = "hello"; |
194 var value = "hello"; |
195 var scope = {value:10}; |
195 var scope = {value:10}; |
196 var scope2 = {value:20}; |
196 var scope2 = {value:20}; |
197 outer: |
197 outer: |
198 { |
198 { |
199 var i=0; |
199 var i=0; |
200 while (i < 10) { |
200 while (i < 10) { |
201 with(scope) { |
201 with(scope) { |
202 print("loop header "+i); |
202 print("loop header "+i); |
203 with (scope2) { |
203 with (scope2) { |
204 value = 11; |
204 value = 11; |
205 i++; |
205 i++; |
206 if ((i & 1) != 0) { |
206 if ((i & 1) != 0) { |
207 print("break"); |
207 print("break"); |
208 break outer; |
208 break outer; |
209 } |
209 } |
210 } |
210 } |
211 } |
211 } |
212 print(value); |
212 print(value); |
213 } |
213 } |
214 } |
214 } |
215 } |
215 } |
216 |
216 |
217 //exceptions in one scope and then the other |
217 //exceptions in one scope and then the other |
218 function test7() { |
218 function test7() { |
219 var value = "hello"; |
219 var value = "hello"; |
220 var scope = {value:10}; |
220 var scope = {value:10}; |
221 var scope2 = {value:20}; |
221 var scope2 = {value:20}; |
222 var global = false; |
222 var global = false; |
223 try { |
223 try { |
224 with(scope) { |
224 with(scope) { |
225 try { |
225 try { |
226 print(value); |
226 print(value); |
227 value = 4711; |
227 value = 4711; |
228 print(value); |
228 print(value); |
229 with(scope2) { |
229 with(scope2) { |
230 print(value); |
230 print(value); |
231 value = 17; |
231 value = 17; |
232 print(value); |
232 print(value); |
233 global = true; |
233 global = true; |
234 throw "inner"; |
234 throw "inner"; |
235 } |
235 } |
236 } catch (ei) { |
236 } catch (ei) { |
237 print(ei); |
237 print(ei); |
238 print(value); |
238 print(value); |
239 if (global) { |
239 if (global) { |
240 throw "outer"; |
240 throw "outer"; |
241 } |
241 } |
242 } |
242 } |
243 } |
243 } |
244 } catch (eo) { |
244 } catch (eo) { |
245 print(eo); |
245 print(eo); |
246 print(value); |
246 print(value); |
247 } |
247 } |
248 print(value); |
248 print(value); |
249 } |
249 } |
250 |
250 |
251 |
251 |