NASHORN-73.js revision 877:cf4d2252d444
1284345Ssjg/* 2284345Ssjg * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3284345Ssjg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4284345Ssjg * 5284345Ssjg * This code is free software; you can redistribute it and/or modify it 6284345Ssjg * under the terms of the GNU General Public License version 2 only, as 7284345Ssjg * published by the Free Software Foundation. 8284345Ssjg * 9284345Ssjg * This code is distributed in the hope that it will be useful, but WITHOUT 10284345Ssjg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11284345Ssjg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12284345Ssjg * version 2 for more details (a copy is included in the LICENSE file that 13284345Ssjg * accompanied this code). 14284345Ssjg * 15284345Ssjg * You should have received a copy of the GNU General Public License version 16284345Ssjg * 2 along with this work; if not, write to the Free Software Foundation, 17284345Ssjg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18284345Ssjg * 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-73 : Loop break should not skip variable declarations. 26 * 27 * @test 28 * @run 29 */ 30 31print("x = " + x); 32do { 33 break; 34 var x; 35} while (true); 36 37 38print("y = " + y); 39while (true) { 40 break; 41 var y; 42} 43 44print("z = " + z); 45for ( ; ; ) { 46 break; 47 var z; 48 print("THIS SHOULD NEVER BE PRINTED!"); 49} 50 51while (true) { 52 break; 53 if (true) { 54 var s; 55 } 56} 57 58print("s = "+s); 59 60print("u = "+u); 61for ( ; ; ) { 62 break; 63 while (true) { 64 do { 65 var u; 66 } while (true); 67 } 68} 69 70function terminal() { 71 print("r = "+r); 72 print("t = "+t); 73 for (;;) { 74 var r; 75 return; 76 var t; 77 print("THIS SHOULD NEVER BE PRINTED!"); 78 } 79 print("NEITHER SHOULD THIS"); 80} 81 82terminal(); 83 84function terminal2() { 85 print("q = "+q); 86 for (;;) { 87 return; 88 print("THIS SHOULD NEVER BE PRINTED!"); 89 } 90 print("NEITHER SHOULD THIS"); 91} 92 93try { 94 terminal2(); 95} catch (e) { 96 print(e); 97} 98 99function scope2() { 100 var b = 10; 101 print("b = "+b); 102} 103 104scope2(); 105 106try { 107 print("b is = "+b); 108} catch (e) { 109 print(e); 110} 111 112 113function disp_a() { 114 var a = 20; 115 print("Value of 'a' inside the function " + a); 116} 117 118var a = 10; 119 120disp_a(); 121 122print("Value of 'a' outside the function " + a); 123