Chromium Code Reviews| Index: src/parser.cc |
| diff --git a/src/parser.cc b/src/parser.cc |
| index aa6ee8ccb6c67a3d210a39b18e97a31f9808ea32..49a08ce9c5a0687b90e0e121df1133cc0cb86a6c 100644 |
| --- a/src/parser.cc |
| +++ b/src/parser.cc |
| @@ -1809,6 +1809,7 @@ Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
| if (declaration_scope->is_function_scope() || |
| declaration_scope->is_strict_eval_scope() || |
| declaration_scope->is_block_scope() || |
| + declaration_scope->is_class_scope() || |
| declaration_scope->is_module_scope() || |
| declaration_scope->is_script_scope()) { |
| // Declare the variable in the declaration scope. |
| @@ -4093,8 +4094,8 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, |
| return NULL; |
| } |
| - Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
| - BlockState block_state(&scope_, block_scope); |
| + Scope* class_scope = NewScope(scope_, CLASS_SCOPE); |
| + BlockState block_state(&scope_, class_scope); |
| scope_->SetLanguageMode( |
| static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
| scope_->SetScopeName(name); |
| @@ -4103,16 +4104,16 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, |
| if (name != NULL) { |
| proxy = NewUnresolved(name, CONST); |
| Declaration* declaration = |
| - factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); |
| + factory()->NewVariableDeclaration(proxy, CONST, class_scope, pos); |
| Declare(declaration, true, CHECK_OK); |
| } |
| Expression* extends = NULL; |
| if (Check(Token::EXTENDS)) { |
| - block_scope->set_start_position(scanner()->location().end_pos); |
| + class_scope->set_start_position(scanner()->location().end_pos); |
| extends = ParseLeftHandSideExpression(CHECK_OK); |
| } else { |
| - block_scope->set_start_position(scanner()->location().end_pos); |
| + class_scope->set_start_position(scanner()->location().end_pos); |
| } |
| @@ -4153,19 +4154,21 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, |
| if (constructor == NULL) { |
| constructor = |
| - DefaultConstructor(extends != NULL, block_scope, pos, end_pos); |
| + DefaultConstructor(extends != NULL, class_scope, pos, end_pos); |
| } |
| - block_scope->set_end_position(end_pos); |
| - block_scope = block_scope->FinalizeBlockScope(); |
| + class_scope->set_end_position(end_pos); |
| if (name != NULL) { |
| DCHECK_NOT_NULL(proxy); |
| - DCHECK_NOT_NULL(block_scope); |
| proxy->var()->set_initializer_position(end_pos); |
| + } else { |
| + // Unnamed classes should not have scopes (the class scope will be empty). |
|
arv (Not doing code reviews)
2015/03/03 15:36:28
Unnamed classed do not need to have a scope.
marja
2015/03/03 15:52:14
Clarification: this comment was b/c some places re
|
| + DCHECK(class_scope->num_var_or_const() == 0); |
| + class_scope = nullptr; |
| } |
| - return factory()->NewClassLiteral(name, block_scope, proxy, extends, |
| + return factory()->NewClassLiteral(name, class_scope, proxy, extends, |
| constructor, properties, pos, end_pos); |
| } |