Index: src/scopes.cc |
diff --git a/src/scopes.cc b/src/scopes.cc |
index 01e311e292d05be9801948a7fd6758b2861d8d88..13e8ecd1efa09d0fabf6a444ade615ecd257708c 100644 |
--- a/src/scopes.cc |
+++ b/src/scopes.cc |
@@ -180,6 +180,8 @@ void Scope::SetDefaults(ScopeType scope_type, |
num_heap_slots_ = 0; |
num_modules_ = 0; |
module_var_ = NULL, |
+ rest_parameter_ = NULL; |
+ rest_index_ = -1; |
scope_info_ = scope_info; |
start_position_ = RelocInfo::kNoPosition; |
end_position_ = RelocInfo::kNoPosition; |
@@ -450,11 +452,17 @@ Variable* Scope::Lookup(const AstRawString* name) { |
} |
-Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode) { |
+Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, |
+ bool is_rest) { |
DCHECK(!already_resolved()); |
DCHECK(is_function_scope()); |
Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL, |
kCreatedInitialized); |
+ if (is_rest) { |
+ DCHECK_EQ(NULL, rest_parameter_); |
+ rest_parameter_ = var; |
+ rest_index_ = num_parameters(); |
+ } |
params_.Add(var, zone()); |
return var; |
} |
@@ -1286,12 +1294,18 @@ void Scope::AllocateParameterLocals() { |
uses_sloppy_arguments = strict_mode() == SLOPPY; |
} |
+ if (rest_parameter_ && !MustAllocate(rest_parameter_)) { |
+ rest_parameter_ = NULL; |
+ } |
+ |
// The same parameter may occur multiple times in the parameters_ list. |
// If it does, and if it is not copied into the context object, it must |
// receive the highest parameter index for that parameter; thus iteration |
// order is relevant! |
for (int i = params_.length() - 1; i >= 0; --i) { |
Variable* var = params_[i]; |
+ if (var == rest_parameter_) continue; |
+ |
DCHECK(var->scope() == this); |
if (uses_sloppy_arguments || has_forced_context_allocation()) { |
// Force context allocation of the parameter. |
@@ -1359,6 +1373,10 @@ void Scope::AllocateNonParameterLocals() { |
if (function_ != NULL) { |
AllocateNonParameterLocal(function_->proxy()->var()); |
} |
+ |
+ if (rest_parameter_) { |
+ AllocateNonParameterLocal(rest_parameter_); |
+ } |
} |