Tue, 08 Oct 2013 14:57:31 +0200
8026039: future strict names are allowed as function name and argument name of a strict function
Reviewed-by: hannesw, jlaskey
1.1 --- a/src/jdk/nashorn/internal/ir/IdentNode.java Tue Oct 08 13:11:15 2013 +0200 1.2 +++ b/src/jdk/nashorn/internal/ir/IdentNode.java Tue Oct 08 14:57:31 2013 +0200 1.3 @@ -40,9 +40,10 @@ 1.4 */ 1.5 @Immutable 1.6 public final class IdentNode extends Expression implements PropertyKey, TypeOverride<IdentNode>, FunctionCall { 1.7 - private static final int PROPERTY_NAME = 1 << 0; 1.8 - private static final int INITIALIZED_HERE = 1 << 1; 1.9 - private static final int FUNCTION = 1 << 2; 1.10 + private static final int PROPERTY_NAME = 1 << 0; 1.11 + private static final int INITIALIZED_HERE = 1 << 1; 1.12 + private static final int FUNCTION = 1 << 2; 1.13 + private static final int FUTURESTRICT_NAME = 1 << 3; 1.14 1.15 /** Identifier. */ 1.16 private final String name; 1.17 @@ -197,6 +198,25 @@ 1.18 } 1.19 1.20 /** 1.21 + * Check if this IdentNode is a future strict name 1.22 + * @return true if this is a future strict name 1.23 + */ 1.24 + public boolean isFutureStrictName() { 1.25 + return (flags & FUTURESTRICT_NAME) != 0; 1.26 + } 1.27 + 1.28 + /** 1.29 + * Flag this IdentNode as a future strict name 1.30 + * @return a node equivalent to this one except for the requested change. 1.31 + */ 1.32 + public IdentNode setIsFutureStrictName() { 1.33 + if (isFutureStrictName()) { 1.34 + return this; 1.35 + } 1.36 + return new IdentNode(this, name, callSiteType, flags | FUTURESTRICT_NAME); 1.37 + } 1.38 + 1.39 + /** 1.40 * Helper function for local def analysis. 1.41 * @return true if IdentNode is initialized on creation 1.42 */
2.1 --- a/src/jdk/nashorn/internal/parser/AbstractParser.java Tue Oct 08 13:11:15 2013 +0200 2.2 +++ b/src/jdk/nashorn/internal/parser/AbstractParser.java Tue Oct 08 14:57:31 2013 +0200 2.3 @@ -378,7 +378,7 @@ 2.4 next(); 2.5 2.6 // Create IDENT node. 2.7 - return new IdentNode(identToken, finish, ident); 2.8 + return new IdentNode(identToken, finish, ident).setIsFutureStrictName(); 2.9 } 2.10 2.11 // Get IDENT.
3.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Tue Oct 08 13:11:15 2013 +0200 3.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Tue Oct 08 14:57:31 2013 +0200 3.3 @@ -909,6 +909,10 @@ 3.4 default: 3.5 break; 3.6 } 3.7 + 3.8 + if (ident.isFutureStrictName()) { 3.9 + throw error(AbstractParser.message("strict.name", ident.getName(), contextString), ident.getToken()); 3.10 + } 3.11 } 3.12 } 3.13
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/script/error/JDK-8026039.js Tue Oct 08 14:57:31 2013 +0200 4.3 @@ -0,0 +1,32 @@ 4.4 +/* 4.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/** 4.28 + * JDK-8026039: future strict names are allowed as function name and argument name of a strict function 4.29 + * 4.30 + * @test/compile-error 4.31 + */ 4.32 + 4.33 +function public() {"use strict"} 4.34 + 4.35 +function f(public) {"use strict"}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/script/error/JDK-8026039.js.EXPECTED Tue Oct 08 14:57:31 2013 +0200 5.3 @@ -0,0 +1,9 @@ 5.4 +test/script/error/JDK-8026039.js:30:9 "public" cannot be used as function name in strict mode 5.5 +function public() {"use strict"} 5.6 + ^ 5.7 +test/script/error/JDK-8026039.js:32:11 Expected ident but found public 5.8 +function f(public) {"use strict"} 5.9 + ^ 5.10 +test/script/error/JDK-8026039.js:33:0 Expected } but found eof 5.11 + 5.12 +^