Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 0147caf5d134e312bc5fd49754d7c57c8d19f866..cb3d01f76a9a9f964dead4c090a9bca497769fe8 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -1936,11 +1936,12 @@ template <class Traits> |
| typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
| Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, |
| bool in_class, bool is_static, bool* ok) { |
| - // TODO(arv): Add support for concise generator methods. |
| ExpressionT value = this->EmptyExpression(); |
| bool is_get = false; |
| bool is_set = false; |
| bool name_is_static = false; |
| + bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); |
| + |
| Token::Value name_token = peek(); |
| int next_pos = peek_position(); |
| IdentifierT name = |
| @@ -1949,7 +1950,7 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
| if (fni_ != NULL) this->PushLiteralName(fni_, name); |
| - if (!in_class && peek() == Token::COLON) { |
| + if (!in_class && !is_generator && peek() == Token::COLON) { |
| // PropertyDefinition : PropertyName ':' AssignmentExpression |
| checker->CheckProperty(name_token, kValueProperty, |
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| @@ -1957,7 +1958,8 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
| value = this->ParseAssignmentExpression( |
| true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| - } else if (allow_harmony_object_literals_ && peek() == Token::LPAREN) { |
| + } else if (is_generator || |
| + (allow_harmony_object_literals_ && peek() == Token::LPAREN)) { |
| // Concise Method |
| if (is_static && this->IsPrototype(name)) { |
| @@ -1965,14 +1967,23 @@ 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(); |
| + } |
| checker->CheckProperty(name_token, kValueProperty, |
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| + FunctionKind kind = FunctionKind::kConciseMethod; |
| + if (is_generator) { |
|
Dmitry Lomov (no reviews)
2014/09/18 07:43:57
Nit: maybe the following is better:
1) add ``kConc
arv (Not doing code reviews)
2014/09/18 15:59:02
Thanks. That is much better.
|
| + kind = static_cast<FunctionKind>(kind | FunctionKind::kGeneratorFunction); |
| + } |
| value = this->ParseFunctionLiteral( |
| name, scanner()->location(), |
| false, // reserved words are allowed here |
| - FunctionKind::kConciseMethod, RelocInfo::kNoPosition, |
| - FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY, |
| + kind, RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, |
| + FunctionLiteral::NORMAL_ARITY, |
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| } else if (in_class && name_is_static && !is_static) { |