Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index b34b04e15252ee30774e2f6ebfd339f88fd646a0..2ad68daec64647f90530cc92d3a851999d7a730a 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -152,6 +152,13 @@ class ParserBase : public Traits { |
| scope_(scope) { |
| *scope_stack_ = scope_; |
|
Dmitry Lomov (no reviews)
2014/10/07 10:28:32
Why do you need this constructor?
arv (Not doing code reviews)
2014/10/07 14:47:09
This is due to how parser and preparser typedef Sc
Dmitry Lomov (no reviews)
2014/10/07 15:09:37
Could we investigate the possibility of removing t
arv (Not doing code reviews)
2014/10/07 15:16:52
I agree that this is confusing. I struggled quite
|
| } |
| + BlockState(typename Traits::Type::Scope** scope_stack, |
| + typename Traits::Type::Scope** scope) |
| + : scope_stack_(scope_stack), |
| + outer_scope_(*scope_stack), |
| + scope_(*scope) { |
| + *scope_stack_ = scope_; |
| + } |
| ~BlockState() { *scope_stack_ = outer_scope_; } |
| private: |
| @@ -1189,6 +1196,13 @@ class PreParserTraits { |
| return false; |
| } |
| + bool IsConstructorProperty(PreParserExpression property) { return false; } |
| + |
| + static PreParserExpression GetPropertyValue(PreParserExpression property) { |
| + UNREACHABLE(); |
| + return PreParserExpression::Default(); |
| + } |
| + |
| // Functions for encapsulating the differences between parsing and preparsing; |
| // operations interleaved with the recursive descent. |
| static void PushLiteralName(FuncNameInferrer* fni, PreParserIdentifier id) { |
| @@ -1314,12 +1328,12 @@ class PreParserTraits { |
| return PreParserExpression::Super(); |
| } |
| - static PreParserExpression ClassLiteral(PreParserIdentifier name, |
| - PreParserExpression extends, |
| - PreParserExpression constructor, |
| - PreParserExpressionList properties, |
| - int position, |
| - PreParserFactory* factory) { |
| + static PreParserExpression ClassExpression(PreParserIdentifier name, |
| + PreParserExpression extends, |
| + PreParserExpression constructor, |
| + PreParserExpressionList properties, |
| + int position, |
| + PreParserFactory* factory) { |
| return PreParserExpression::Default(); |
| } |
| @@ -1972,16 +1986,22 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
| *ok = false; |
| return this->EmptyObjectLiteralProperty(); |
| } |
| - if (is_generator && in_class && !is_static && this->IsConstructor(name)) { |
| - ReportMessageAt(scanner()->location(), "constructor_special_method"); |
| - *ok = false; |
| - return this->EmptyObjectLiteralProperty(); |
| + |
| + FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod |
| + : FunctionKind::kConciseMethod; |
| + |
| + if (in_class && !is_static && this->IsConstructor(name)) { |
| + if (is_generator) { |
| + ReportMessageAt(scanner()->location(), "constructor_special_method"); |
| + *ok = false; |
| + return this->EmptyObjectLiteralProperty(); |
| + } |
| + |
| + kind = FunctionKind::kConstructorMethod; |
| } |
| checker->CheckProperty(name_token, kValueProperty, |
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| - FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod |
| - : FunctionKind::kConciseMethod; |
| value = this->ParseFunctionLiteral( |
| name, scanner()->location(), |
| @@ -2739,25 +2759,24 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseClassLiteral( |
| return this->EmptyExpression(); |
| } |
| - // TODO(arv): Implement scopes and name binding in class body only. |
| - // TODO(arv): Maybe add CLASS_SCOPE? |
| - typename Traits::Type::ScopePtr extends_scope = |
| - this->NewScope(scope_, BLOCK_SCOPE); |
| - FunctionState extends_function_state( |
| - &function_state_, &scope_, &extends_scope, zone(), |
| - this->ast_value_factory(), ast_node_id_gen_); |
| - scope_->SetStrictMode(STRICT); |
| - scope_->SetScopeName(name); |
| - |
| ExpressionT extends = this->EmptyExpression(); |
| if (Check(Token::EXTENDS)) { |
| + typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); |
| + BlockState block_state(&scope_, &scope); |
|
Dmitry Lomov (no reviews)
2014/10/07 10:28:32
Seems like BlockState block_state(&scope_, scope)
arv (Not doing code reviews)
2014/10/07 14:47:09
That works with PreParser but not with Parser.
|
| + scope_->SetStrictMode(STRICT); |
| extends = this->ParseLeftHandSideExpression(CHECK_OK); |
| } |
| + // TODO(arv): Implement scopes and name binding in class body only. |
| + typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); |
| + BlockState block_state(&scope_, &scope); |
| + scope_->SetStrictMode(STRICT); |
| + scope_->SetScopeName(name); |
| + |
| ObjectLiteralChecker checker(this, STRICT); |
| typename Traits::Type::PropertyList properties = |
| this->NewPropertyList(4, zone_); |
| - FunctionLiteralT constructor = this->EmptyFunctionLiteral(); |
| + ExpressionT constructor = this->EmptyExpression(); |
| Expect(Token::LBRACE, CHECK_OK); |
| while (peek() != Token::RBRACE) { |
| @@ -2769,7 +2788,11 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseClassLiteral( |
| ObjectLiteralPropertyT property = |
| this->ParsePropertyDefinition(&checker, in_class, is_static, CHECK_OK); |
| - properties->Add(property, zone()); |
| + if (this->IsConstructorProperty(property)) { |
| + constructor = this->GetPropertyValue(property); |
| + } else { |
| + properties->Add(property, zone()); |
| + } |
| if (fni_ != NULL) { |
| fni_->Infer(); |
| @@ -2778,8 +2801,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseClassLiteral( |
| } |
| Expect(Token::RBRACE, CHECK_OK); |
| - return this->ClassLiteral(name, extends, constructor, properties, pos, |
| - factory()); |
| + return this->ClassExpression(name, extends, constructor, properties, pos, |
| + factory()); |
| } |