|
1 /* |
|
2 * Copyright (c) 2017, 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-8027302: Identifiers containing unicode escapes are not recognized as reserved words |
|
26 * |
|
27 * @test |
|
28 * @run |
|
29 */ |
|
30 |
|
31 // keywords containing escapes |
|
32 |
|
33 try { |
|
34 eval("v\\u0061r i;"); |
|
35 fail("Expected error"); |
|
36 } catch (e) { |
|
37 Assert.assertTrue(e instanceof SyntaxError); |
|
38 } |
|
39 |
|
40 try { |
|
41 eval("\\u0069f (true) ;"); |
|
42 fail("Expected error"); |
|
43 } catch (e) { |
|
44 Assert.assertTrue(e instanceof ReferenceError); // no SyntaxError in ES5 |
|
45 } |
|
46 |
|
47 try { |
|
48 eval("if (true) ; \\u0065lse ;"); |
|
49 fail("Expected error"); |
|
50 } catch (e) { |
|
51 Assert.assertTrue(e instanceof ReferenceError); // no SyntaxError in ES5 |
|
52 } |
|
53 |
|
54 try { |
|
55 eval("f\\u0075nction x() {}"); |
|
56 fail("Expected error"); |
|
57 } catch (e) { |
|
58 Assert.assertTrue(e instanceof SyntaxError); |
|
59 } |
|
60 |
|
61 try { |
|
62 eval("var f = f\\u0075nction() {}"); |
|
63 fail("Expected error"); |
|
64 } catch (e) { |
|
65 Assert.assertTrue(e instanceof SyntaxError); |
|
66 } |
|
67 |
|
68 try { |
|
69 eval("var o = { f: f\\u0075nction() {}}"); |
|
70 fail("Expected error"); |
|
71 } catch (e) { |
|
72 Assert.assertTrue(e instanceof SyntaxError); |
|
73 } |
|
74 |
|
75 try { |
|
76 eval("var a = [f\\u0075nction() {}]"); |
|
77 fail("Expected error"); |
|
78 } catch (e) { |
|
79 Assert.assertTrue(e instanceof SyntaxError); |
|
80 } |
|
81 |
|
82 // keywords as identifiers, with and without escapes |
|
83 |
|
84 try { |
|
85 eval("function break() {}"); |
|
86 fail("Expected error"); |
|
87 } catch (e) { |
|
88 Assert.assertTrue(e instanceof SyntaxError); |
|
89 } |
|
90 |
|
91 try { |
|
92 eval("function bre\\u0061k() {}"); |
|
93 } catch (e) { |
|
94 fail("Unexpected error"); |
|
95 } |
|
96 |
|
97 try { |
|
98 eval("function f(break) {}"); |
|
99 fail("Expected error"); |
|
100 } catch (e) { |
|
101 Assert.assertTrue(e instanceof SyntaxError); |
|
102 } |
|
103 |
|
104 try { |
|
105 eval("function f(bre\\u0061k) {}"); |
|
106 } catch (e) { |
|
107 fail("Unexpected error"); |
|
108 } |
|
109 |
|
110 try { |
|
111 eval("var break = 3"); |
|
112 fail("Expected error"); |
|
113 } catch (e) { |
|
114 Assert.assertTrue(e instanceof SyntaxError); |
|
115 } |
|
116 |
|
117 try { |
|
118 eval("'use strict'; var break = 3"); |
|
119 fail("Expected error"); |
|
120 } catch (e) { |
|
121 Assert.assertTrue(e instanceof SyntaxError); |
|
122 } |
|
123 |
|
124 try { |
|
125 eval("var bre\\u0061k = 3"); |
|
126 } catch (e) { |
|
127 fail("Unexpected error"); |
|
128 } |
|
129 |
|
130 try { |
|
131 eval("'use strict'; var bre\\u0061k = 3"); |
|
132 } catch (e) { |
|
133 fail("Unexpected error"); |
|
134 } |
|
135 |
|
136 try { |
|
137 eval("var package = 3"); |
|
138 } catch (e) { |
|
139 fail("Unexpected error"); |
|
140 } |
|
141 |
|
142 try { |
|
143 eval("'use strict'; var package = 3"); |
|
144 fail("Expected error"); |
|
145 } catch (e) { |
|
146 Assert.assertTrue(e instanceof SyntaxError); |
|
147 } |
|
148 |
|
149 try { |
|
150 eval("var p\\u0061ckage = 3"); |
|
151 } catch (e) { |
|
152 fail("Unexpected error"); |
|
153 } |
|
154 |
|
155 try { |
|
156 eval("'use strict'; var p\\u0061ckage = 3"); |
|
157 } catch (e) { |
|
158 fail("Unexpected error"); |
|
159 } |
|
160 |