test/script/basic/es6/const-reassign.js

changeset 991
b7a2db4de254
child 1243
2b51c0b3f463
equal deleted inserted replaced
990:46647c4943ff 991:b7a2db4de254
1 /*
2 * Copyright (c) 2010, 2014, 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 * JDK-8051889: Implement block scoping in symbol assignment and scope computation
26 *
27 * @test
28 * @run
29 * @option --language=es6 */
30
31 "use strict";
32
33 try {
34 eval('"use strict";\n' +
35 'const x = 2;\n' +
36 'x = 1;\n');
37 } catch (e) {
38 print(e.name);
39 }
40
41 try {
42 eval('"use strict";\n' +
43 'const x = 2;\n' +
44 'x++;\n');
45 fail("const assignment didn't throw");
46 } catch (e) {
47 print(e.name);
48 }
49
50 try {
51 eval('"use strict";\n' +
52 'const x = 2;\n' +
53 'x--;\n');
54 fail("const assignment didn't throw");
55 } catch (e) {
56 print(e.name);
57 }
58
59 try {
60 eval('"use strict";\n' +
61 'const x = 2;\n' +
62 '++x;\n');
63 fail("const assignment didn't throw");
64 } catch (e) {
65 print(e.name);
66 }
67
68 try {
69 eval('"use strict";\n' +
70 'const x = 2;\n' +
71 '--x;\n');
72 fail("const assignment didn't throw");
73 } catch (e) {
74 print(e.name);
75 }
76
77 try {
78 eval('"use strict";\n' +
79 'const x = 2;\n' +
80 'x += 1;\n');
81 fail("const assignment didn't throw");
82 } catch (e) {
83 print(e.name);
84 }
85
86 try {
87 eval('"use strict";\n' +
88 'const x = 2;\n' +
89 'x *= 1;\n');
90 fail("const assignment didn't throw");
91 } catch (e) {
92 print(e.name);
93 }
94
95 try {
96 eval('"use strict";\n' +
97 'const x = 2;\n' +
98 'x /= 1;\n');
99 fail("const assignment didn't throw");
100 } catch (e) {
101 print(e.name);
102 }
103
104 try {
105 eval('"use strict";\n' +
106 'const x = 2;\n' +
107 'x %= 1;\n');
108 fail("const assignment didn't throw");
109 } catch (e) {
110 print(e.name);
111 }
112
113 try {
114 eval('"use strict";\n' +
115 'const x = 2;\n' +
116 'x |= 1;\n');
117 fail("const assignment didn't throw");
118 } catch (e) {
119 print(e.name);
120 }
121
122 try {
123 eval('"use strict";\n' +
124 'const x = 2;\n' +
125 'x &= 1;\n');
126 fail("const assignment didn't throw");
127 } catch (e) {
128 print(e.name);
129 }
130
131 try {
132 eval('"use strict";\n' +
133 'const x = 2;\n' +
134 'x ^= 1;\n');
135 fail("const assignment didn't throw");
136 } catch (e) {
137 print(e.name);
138 }
139
140 try {
141 eval('"use strict";\n' +
142 'const x = 2;\n' +
143 'x <<= 1;\n');
144 fail("const assignment didn't throw");
145 } catch (e) {
146 print(e.name);
147 }
148
149 try {
150 eval('"use strict";\n' +
151 'const x = 2;\n' +
152 'x >>= 1;\n');
153 fail("const assignment didn't throw");
154 } catch (e) {
155 print(e.name);
156 }
157
158 try {
159 eval('"use strict";\n' +
160 'const x = 2;\n' +
161 'x >>>= 1;\n');
162 fail("const assignment didn't throw");
163 } catch (e) {
164 print(e.name);
165 }
166
167 try {
168 eval('"use strict";\n' +
169 'const x = 2;\n' +
170 'delete x;\n');
171 fail("const assignment didn't throw");
172 } catch (e) {
173 print(e.name);
174 }

mercurial