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