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

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

Issue 2176653003: Wrap ClassLiterals in DoExpressions instead of giving them BlockScopes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 5 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
Index: src/parsing/parameter-initializer-rewriter.cc
diff --git a/src/parsing/parameter-initializer-rewriter.cc b/src/parsing/parameter-initializer-rewriter.cc
index 7a19138069ab525422e93f30fd02c86df204cc9f..e25fafc153d6b408a345103eed06105039e11360 100644
--- a/src/parsing/parameter-initializer-rewriter.cc
+++ b/src/parsing/parameter-initializer-rewriter.cc
@@ -16,8 +16,10 @@ namespace {
class Rewriter final : public AstExpressionVisitor {
public:
- Rewriter(uintptr_t stack_limit, Expression* initializer, Scope* param_scope)
+ Rewriter(uintptr_t stack_limit, Expression* initializer, Scope* old_scope,
+ Scope* param_scope)
: AstExpressionVisitor(stack_limit, initializer),
+ old_scope_(old_scope),
param_scope_(param_scope) {}
private:
@@ -31,16 +33,18 @@ class Rewriter final : public AstExpressionVisitor {
void VisitTryCatchStatement(TryCatchStatement* stmt) override;
void VisitWithStatement(WithStatement* stmt) override;
+ Scope* old_scope_;
Scope* param_scope_;
};
void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) {
- function_literal->scope()->ReplaceOuterScope(param_scope_);
+ if (function_literal->scope()->outer_scope() == old_scope_) {
+ function_literal->scope()->ReplaceOuterScope(param_scope_);
+ }
}
void Rewriter::VisitClassLiteral(ClassLiteral* class_literal) {
- class_literal->scope()->ReplaceOuterScope(param_scope_);
if (class_literal->extends() != nullptr) {
Visit(class_literal->extends());
}
@@ -73,29 +77,33 @@ void Rewriter::VisitVariableProxy(VariableProxy* proxy) {
void Rewriter::VisitBlock(Block* stmt) {
- if (stmt->scope() != nullptr)
+ if (stmt->scope() != nullptr && stmt->scope()->outer_scope() == old_scope_) {
stmt->scope()->ReplaceOuterScope(param_scope_);
- else
- VisitStatements(stmt->statements());
+ }
+ VisitStatements(stmt->statements());
}
void Rewriter::VisitTryCatchStatement(TryCatchStatement* stmt) {
+ if (stmt->scope()->outer_scope() == old_scope_) {
+ stmt->scope()->ReplaceOuterScope(param_scope_);
+ }
Visit(stmt->try_block());
- stmt->scope()->ReplaceOuterScope(param_scope_);
}
void Rewriter::VisitWithStatement(WithStatement* stmt) {
Visit(stmt->expression());
- stmt->scope()->ReplaceOuterScope(param_scope_);
+ if (stmt->scope()->outer_scope() == old_scope_) {
+ stmt->scope()->ReplaceOuterScope(param_scope_);
+ }
}
} // anonymous namespace
void ReparentParameterExpressionScope(uintptr_t stack_limit, Expression* expr,
- Scope* param_scope) {
+ Scope* old_scope, Scope* param_scope) {
// The only case that uses this code is block scopes for parameters containing
// sloppy eval.
DCHECK(param_scope->is_block_scope());
@@ -103,7 +111,7 @@ void ReparentParameterExpressionScope(uintptr_t stack_limit, Expression* expr,
DCHECK(param_scope->calls_sloppy_eval());
DCHECK(param_scope->outer_scope()->is_function_scope());
- Rewriter rewriter(stack_limit, expr, param_scope);
+ Rewriter rewriter(stack_limit, expr, old_scope, param_scope);
rewriter.Run();
}

Powered by Google App Engine
This is Rietveld 408576698