Chromium Code Reviews| Index: src/parsing/parameter-initializer-rewriter.cc |
| diff --git a/src/parsing/parameter-initializer-rewriter.cc b/src/parsing/parameter-initializer-rewriter.cc |
| index 6362c63f8ec65863e97ffac96f362a1e6ced4c9d..bb4e6eeca51b06cdddbd6b24859539d0273d47c7 100644 |
| --- a/src/parsing/parameter-initializer-rewriter.cc |
| +++ b/src/parsing/parameter-initializer-rewriter.cc |
| @@ -55,8 +55,9 @@ Rewriter::~Rewriter() { |
| // Ensure that we add temporaries in the order they appeared in old_scope_. |
| std::sort(temps_.begin(), temps_.end(), LessThanSecond()); |
| for (auto var_and_index : temps_) { |
| - var_and_index.first->set_scope(new_scope_); |
| - new_scope_->AddTemporary(var_and_index.first); |
| + Scope* scope = new_scope_->ClosureScope(); |
| + var_and_index.first->set_scope(scope); |
| + scope->AddTemporary(var_and_index.first); |
| } |
| } |
| } |
| @@ -90,11 +91,11 @@ void Rewriter::VisitVariableProxy(VariableProxy* proxy) { |
| if (proxy->is_resolved()) { |
| Variable* var = proxy->var(); |
| if (var->mode() != TEMPORARY) return; |
| - // For rewriting inside the same ClosureScope (e.g., putting default |
| - // parameter values in their own inner scope in certain cases), refrain |
| - // from invalidly moving temporaries to a block scope. |
| - if (var->scope()->ClosureScope() == new_scope_->ClosureScope()) return; |
| - int index = old_scope_->RemoveTemporary(var); |
| + // Temporaries are only placed in ClosureScopes. |
| + DCHECK_EQ(var->scope(), var->scope()->ClosureScope()); |
| + // If the temporary is already where it should be, return quickly. |
| + if (var->scope() == new_scope_->ClosureScope()) return; |
| + int index = old_scope_->ClosureScope()->RemoveTemporary(var); |
|
adamk
2016/06/27 18:49:31
What if the rewriter computed the ClosureScopes of
nickie
2016/06/28 09:26:37
Done.
|
| if (index >= 0) { |
| temps_.push_back(std::make_pair(var, index)); |
| } |