Index: src/scopes.cc |
diff --git a/src/scopes.cc b/src/scopes.cc |
index 60c14dbdc8d752af1cb209897c97eb7d944f553e..9f682381432cb70a11c6c57182bb79b72daa2f23 100644 |
--- a/src/scopes.cc |
+++ b/src/scopes.cc |
@@ -77,6 +77,7 @@ Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
internals_(4, zone), |
temps_(4, zone), |
params_(4, zone), |
+ param_positions_(4, zone), |
unresolved_(16, zone), |
decls_(4, zone), |
module_descriptor_( |
@@ -100,6 +101,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
internals_(4, zone), |
temps_(4, zone), |
params_(4, zone), |
+ param_positions_(4, zone), |
unresolved_(16, zone), |
decls_(4, zone), |
module_descriptor_(NULL), |
@@ -126,6 +128,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope, |
internals_(0, zone), |
temps_(0, zone), |
params_(0, zone), |
+ param_positions_(0, zone), |
unresolved_(0, zone), |
decls_(0, zone), |
module_descriptor_(NULL), |
@@ -183,6 +186,7 @@ void Scope::SetDefaults(ScopeType scope_type, Scope* outer_scope, |
module_var_ = NULL, |
rest_parameter_ = NULL; |
rest_index_ = -1; |
+ has_parameter_expressions_ = false; |
scope_info_ = scope_info; |
start_position_ = RelocInfo::kNoPosition; |
end_position_ = RelocInfo::kNoPosition; |
@@ -459,7 +463,7 @@ Variable* Scope::Lookup(const AstRawString* name) { |
Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, |
- bool is_rest, bool* is_duplicate) { |
+ bool is_rest, bool* is_duplicate, int pos) { |
DCHECK(!already_resolved()); |
DCHECK(is_function_scope()); |
Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, |
@@ -472,6 +476,7 @@ Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, |
// TODO(wingo): Avoid O(n^2) check. |
*is_duplicate = IsDeclaredParameter(name); |
params_.Add(var, zone()); |
+ param_positions_.Add(pos, zone()); |
return var; |
} |
@@ -542,6 +547,18 @@ void Scope::AddDeclaration(Declaration* declaration) { |
} |
+void Scope::UndeclareParametersForExpressions() { |
+ DCHECK(is_function_scope()); |
+ DCHECK(!has_parameter_expressions_); |
+ has_parameter_expressions_ = true; |
+ for (int i = 0; i < num_parameters(); ++i) { |
+ Variable* p = parameter(i); |
+ const AstRawString* name = p->raw_name(); |
+ variables_.Remove(const_cast<AstRawString*>(name), name->hash()); |
+ } |
+} |
+ |
+ |
void Scope::SetIllegalRedeclaration(Expression* expression) { |
// Record only the first illegal redeclaration. |
if (!HasIllegalRedeclaration()) { |
@@ -1419,6 +1436,11 @@ void Scope::AllocateParameterLocals(Isolate* isolate) { |
void Scope::AllocateParameter(Variable* var, int index) { |
if (MustAllocate(var)) { |
if (MustAllocateInContext(var)) { |
+ if (has_parameter_expressions_) { |
+ // If hasParameterExpressions is true, context-allocate the redeclared |
+ // lexical variable, not the function parameter. |
+ var = variables_.Lookup(var->raw_name()); |
+ } |
DCHECK(var->IsUnallocated() || var->IsContextSlot()); |
if (var->IsUnallocated()) { |
AllocateHeapSlot(var); |