Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: src/ast/scopes.cc

Issue 2290753003: Allow lexically declared "arguments" in function scope in sloppy mode. (Closed)
Patch Set: clang format Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index 02b34335265bf72633fe0dc1486141b8d1aeae00..635fec817740b317f8e948d29c4c457c74c2794e 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -492,15 +492,32 @@ void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) {
receiver_ = var;
}
-void DeclarationScope::DeclareDefaultFunctionVariables(
- AstValueFactory* ast_value_factory) {
+void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) {
DCHECK(is_function_scope());
DCHECK(!is_arrow_scope());
+
+ // Check if there's lexically declared variable named arguments to avoid
+ // redeclaration. See ES#sec-functiondeclarationinstantiation, step 20.
+ Variable* arg_variable = LookupLocal(ast_value_factory->arguments_string());
+ if (arg_variable != nullptr && IsLexicalVariableMode(arg_variable->mode())) {
+ return;
+ }
+
// Declare 'arguments' variable which exists in all non arrow functions.
// Note that it might never be accessed, in which case it won't be
// allocated during variable allocation.
- arguments_ = Declare(zone(), this, ast_value_factory->arguments_string(), VAR,
- Variable::ARGUMENTS, kCreatedInitialized);
+ if (arg_variable == nullptr) {
+ arguments_ = Declare(zone(), this, ast_value_factory->arguments_string(),
+ VAR, Variable::ARGUMENTS, kCreatedInitialized);
+ } else {
+ arguments_ = arg_variable;
+ }
+}
+
+void DeclarationScope::DeclareDefaultFunctionVariables(
+ AstValueFactory* ast_value_factory) {
+ DCHECK(is_function_scope());
+ DCHECK(!is_arrow_scope());
new_target_ = Declare(zone(), this, ast_value_factory->new_target_string(),
CONST, Variable::NORMAL, kCreatedInitialized);
@@ -1508,8 +1525,8 @@ void DeclarationScope::AllocateParameterLocals() {
bool uses_sloppy_arguments = false;
- // Functions have 'arguments' declared implicitly in all non arrow functions.
if (arguments_ != nullptr) {
+ DCHECK(!is_arrow_scope());
// 'arguments' is used. Unless there is also a parameter called
// 'arguments', we must be conservative and allocate all parameters to
// the context assuming they will be captured by the arguments object.
@@ -1530,9 +1547,6 @@ void DeclarationScope::AllocateParameterLocals() {
// allocate the arguments object by nulling out arguments_.
arguments_ = nullptr;
}
-
- } else {
- DCHECK(is_arrow_scope());
}
// The same parameter may occur multiple times in the parameters_ list.
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698