src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java
changeset 47337 079a87f87518
parent 47287 8eb5e3ccee56
child 48334 fdefa410d655
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java	Fri Oct 13 15:22:02 2017 +0200
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java	Fri Oct 13 17:25:12 2017 +0200
@@ -1472,12 +1472,7 @@
      */
     private void verifyIdent(final IdentNode ident, final String contextString) {
         verifyStrictIdent(ident, contextString);
-        if (isES6()) {
-            final TokenType tokenType = TokenLookup.lookupKeyword(ident.getName().toCharArray(), 0, ident.getName().length());
-            if (tokenType != IDENT && tokenType.getKind() != TokenKind.FUTURESTRICT) {
-                throw error(expectMessage(IDENT));
-            }
-        }
+        checkEscapedKeyword(ident);
     }
 
     /**
@@ -1502,6 +1497,18 @@
         }
     }
 
+    /**
+     * ES6 11.6.2: A code point in a ReservedWord cannot be expressed by a | UnicodeEscapeSequence.
+     */
+    private void checkEscapedKeyword(final IdentNode ident) {
+        if (isES6() && ident.containsEscapes()) {
+            final TokenType tokenType = TokenLookup.lookupKeyword(ident.getName().toCharArray(), 0, ident.getName().length());
+            if (tokenType != IDENT && !(tokenType.getKind() == TokenKind.FUTURESTRICT && !isStrictMode)) {
+                throw error(AbstractParser.message("keyword.escaped.character"), ident.getToken());
+            }
+        }
+    }
+
     /*
      * VariableStatement :
      *      var VariableDeclarationList ;
@@ -2646,7 +2653,7 @@
                     });
                 } else {
                     // ECMA 12.4.1 strict mode restrictions
-                    verifyStrictIdent((IdentNode) exception, "catch argument");
+                    verifyIdent((IdentNode) exception, "catch argument");
                 }
 
 
@@ -2761,6 +2768,7 @@
                 break;
             }
             detectSpecialProperty(ident);
+            checkEscapedKeyword(ident);
             return ident;
         case OCTAL_LEGACY:
             if (isStrictMode) {
@@ -3404,6 +3412,7 @@
             // Catch special functions.
             if (lhs instanceof IdentNode) {
                 detectSpecialFunction((IdentNode)lhs);
+                checkEscapedKeyword((IdentNode)lhs);
             }
 
             lhs = new CallNode(callLine, callToken, finish, lhs, arguments, false);
@@ -3779,7 +3788,7 @@
                 expect(IDENT);
             }
             name = getIdent();
-            verifyStrictIdent(name, "function name");
+            verifyIdent(name, "function name");
         } else if (isStatement) {
             // Nashorn extension: anonymous function statements.
             // Do not allow anonymous function statement if extensions
@@ -4871,7 +4880,7 @@
         final String contextString = "function parameter";
         if (param instanceof IdentNode) {
             final IdentNode ident = (IdentNode)param;
-            verifyStrictIdent(ident, contextString);
+            verifyIdent(ident, contextString);
             final ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
             if (currentFunction != null) {
                 currentFunction.addParameterBinding(ident);