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

Unified Diff: src/parsing/parameter-initializer-rewriter.cc

Issue 2083083007: Fix bug with re-scoping arrow function parameter initializers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test according to reviews Created 4 years, 6 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.cc ('k') | test/mjsunit/regress/regress-622663.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
« no previous file with comments | « src/ast/scopes.cc ('k') | test/mjsunit/regress/regress-622663.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698