8026039: future strict names are allowed as function name and argument name of a strict function

Reviewed-by: hannesw, jlaskey
This commit is contained in:
Athijegannathan Sundararajan 2013-10-08 14:57:31 +02:00
parent 1c0f202382
commit 21a8fda433
5 changed files with 69 additions and 4 deletions

View File

@ -40,9 +40,10 @@ import jdk.nashorn.internal.ir.visitor.NodeVisitor;
*/
@Immutable
public final class IdentNode extends Expression implements PropertyKey, TypeOverride<IdentNode>, FunctionCall {
private static final int PROPERTY_NAME = 1 << 0;
private static final int INITIALIZED_HERE = 1 << 1;
private static final int FUNCTION = 1 << 2;
private static final int PROPERTY_NAME = 1 << 0;
private static final int INITIALIZED_HERE = 1 << 1;
private static final int FUNCTION = 1 << 2;
private static final int FUTURESTRICT_NAME = 1 << 3;
/** Identifier. */
private final String name;
@ -196,6 +197,25 @@ public final class IdentNode extends Expression implements PropertyKey, TypeOver
return new IdentNode(this, name, callSiteType, flags | PROPERTY_NAME);
}
/**
* Check if this IdentNode is a future strict name
* @return true if this is a future strict name
*/
public boolean isFutureStrictName() {
return (flags & FUTURESTRICT_NAME) != 0;
}
/**
* Flag this IdentNode as a future strict name
* @return a node equivalent to this one except for the requested change.
*/
public IdentNode setIsFutureStrictName() {
if (isFutureStrictName()) {
return this;
}
return new IdentNode(this, name, callSiteType, flags | FUTURESTRICT_NAME);
}
/**
* Helper function for local def analysis.
* @return true if IdentNode is initialized on creation

View File

@ -378,7 +378,7 @@ public abstract class AbstractParser {
next();
// Create IDENT node.
return new IdentNode(identToken, finish, ident);
return new IdentNode(identToken, finish, ident).setIsFutureStrictName();
}
// Get IDENT.

View File

@ -909,6 +909,10 @@ loop:
default:
break;
}
if (ident.isFutureStrictName()) {
throw error(AbstractParser.message("strict.name", ident.getName(), contextString), ident.getToken());
}
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* JDK-8026039: future strict names are allowed as function name and argument name of a strict function
*
* @test/compile-error
*/
function public() {"use strict"}
function f(public) {"use strict"}

View File

@ -0,0 +1,9 @@
test/script/error/JDK-8026039.js:30:9 "public" cannot be used as function name in strict mode
function public() {"use strict"}
^
test/script/error/JDK-8026039.js:32:11 Expected ident but found public
function f(public) {"use strict"}
^
test/script/error/JDK-8026039.js:33:0 Expected } but found eof
^