16147
|
1 |
/*
|
16151
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
16147
|
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-73 : Loop break should not skip variable declarations.
|
|
26 |
*
|
|
27 |
* @test
|
|
28 |
* @run
|
|
29 |
*/
|
|
30 |
|
|
31 |
print("x = " + x);
|
|
32 |
do {
|
|
33 |
break;
|
|
34 |
var x;
|
|
35 |
} while (true);
|
|
36 |
|
|
37 |
|
|
38 |
print("y = " + y);
|
|
39 |
while (true) {
|
|
40 |
break;
|
|
41 |
var y;
|
|
42 |
}
|
|
43 |
|
|
44 |
print("z = " + z);
|
|
45 |
for ( ; ; ) {
|
|
46 |
break;
|
|
47 |
var z;
|
|
48 |
print("THIS SHOULD NEVER BE PRINTED!");
|
|
49 |
}
|
|
50 |
|
|
51 |
while (true) {
|
|
52 |
break;
|
|
53 |
if (true) {
|
|
54 |
var s;
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
print("s = "+s);
|
|
59 |
|
|
60 |
print("u = "+u);
|
|
61 |
for ( ; ; ) {
|
|
62 |
break;
|
|
63 |
while (true) {
|
|
64 |
do {
|
|
65 |
var u;
|
|
66 |
} while (true);
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
function 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 |
|
|
82 |
terminal();
|
|
83 |
|
|
84 |
function terminal2() {
|
|
85 |
print("q = "+q);
|
|
86 |
for (;;) {
|
|
87 |
return;
|
|
88 |
print("THIS SHOULD NEVER BE PRINTED!");
|
|
89 |
}
|
|
90 |
print("NEITHER SHOULD THIS");
|
|
91 |
}
|
|
92 |
|
|
93 |
try {
|
|
94 |
terminal2();
|
|
95 |
} catch (e) {
|
|
96 |
print(e);
|
|
97 |
}
|
|
98 |
|
|
99 |
function scope2() {
|
|
100 |
var b = 10;
|
|
101 |
print("b = "+b);
|
|
102 |
}
|
|
103 |
|
|
104 |
scope2();
|
|
105 |
|
|
106 |
try {
|
|
107 |
print("b is = "+b);
|
|
108 |
} catch (e) {
|
|
109 |
print(e);
|
|
110 |
}
|
|
111 |
|
|
112 |
|
|
113 |
function disp_a() {
|
|
114 |
var a = 20;
|
|
115 |
print("Value of 'a' inside the function " + a);
|
|
116 |
}
|
|
117 |
|
|
118 |
var a = 10;
|
|
119 |
|
|
120 |
disp_a();
|
|
121 |
|
|
122 |
print("Value of 'a' outside the function " + a);
|