Index: src/ast/scopes.cc |
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc |
index 73c243b6250c21e4adccb99288be13b8b803707e..f34e3e0ee85a99e6e172eade4ab32519bd55742b 100644 |
--- a/src/ast/scopes.cc |
+++ b/src/ast/scopes.cc |
@@ -436,15 +436,34 @@ 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 https://tc39.github.io/ecma262/#sec-functiondeclarationinstantiation, |
adamk
2016/09/01 17:36:26
The style we've mostly been going for here has bee
lpy
2016/09/01 20:00:55
Done.
|
+ // 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); |
@@ -1501,9 +1520,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. |