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

Unified Diff: src/preparser.h

Issue 1348773004: [cleanup] refactor ParsePropertyDefinition for clarity (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Few more comments fixed up Created 5 years, 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 9f2b13212c6526f7d130502e0d08a315177671fb..a5aa3709a6d509174fe9c02530b80cd940c907ab 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2611,19 +2611,66 @@ ParserBase<Traits>::ParsePropertyDefinition(
this->PushLiteralName(fni_, name);
}
- if (!in_class && !is_generator && peek() == Token::COLON) {
- // PropertyDefinition : PropertyName ':' AssignmentExpression
- if (!*is_computed_name) {
- checker->CheckProperty(name_token, kValueProperty, is_static,
- is_generator,
- CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ if (!in_class && !is_generator) {
+ DCHECK(!is_static);
+
+ if (peek() == Token::COLON) {
+ // PropertyDefinition
+ // PropertyName ':' AssignmentExpression
+ if (!*is_computed_name) {
+ checker->CheckProperty(name_token, kValueProperty, false, false,
+ CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ }
+ Consume(Token::COLON);
+ value = this->ParseAssignmentExpression(
+ true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ return factory()->NewObjectLiteralProperty(name_expression, value, false,
+ *is_computed_name);
}
- Consume(Token::COLON);
- value = this->ParseAssignmentExpression(
- true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
- } else if (is_generator || peek() == Token::LPAREN) {
- // Concise Method
+ if (Token::IsIdentifier(name_token, language_mode(),
+ this->is_generator()) &&
+ (peek() == Token::COMMA || peek() == Token::RBRACE ||
+ peek() == Token::ASSIGN)) {
+ // PropertyDefinition
+ // IdentifierReference
+ // CoverInitializedName
+ //
+ // CoverInitializedName
+ // IdentifierReference Initializer?
+ if (classifier->duplicate_finder() != nullptr &&
+ scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) {
+ classifier->RecordDuplicateFormalParameterError(scanner()->location());
+ }
+
+ ExpressionT lhs = this->ExpressionFromIdentifier(
+ name, next_beg_pos, next_end_pos, scope_, factory());
+
+ if (peek() == Token::ASSIGN) {
+ this->ExpressionUnexpectedToken(classifier);
+ Consume(Token::ASSIGN);
+ ExpressionClassifier rhs_classifier;
+ ExpressionT rhs = this->ParseAssignmentExpression(
+ true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ classifier->Accumulate(rhs_classifier,
+ ExpressionClassifier::ExpressionProductions);
+ value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
+ RelocInfo::kNoPosition);
+ } else {
+ value = lhs;
+ }
+
+ return factory()->NewObjectLiteralProperty(
+ name_expression, value, ObjectLiteralProperty::COMPUTED, false,
+ false);
+ }
+ }
+
+
+ if (is_generator || peek() == Token::LPAREN) {
+ // MethodDefinition
+ // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
+ // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
if (!*is_computed_name) {
checker->CheckProperty(name_token, kMethodProperty, is_static,
is_generator,
@@ -2650,15 +2697,19 @@ ParserBase<Traits>::ParsePropertyDefinition(
return factory()->NewObjectLiteralProperty(name_expression, value,
ObjectLiteralProperty::COMPUTED,
is_static, *is_computed_name);
+ }
- } else if (in_class && name_is_static && !is_static) {
- // static MethodDefinition
+ if (in_class && name_is_static && !is_static) {
+ // ClassElement (static)
+ // 'static' MethodDefinition
return ParsePropertyDefinition(checker, true, has_extends, true,
is_computed_name, nullptr, classifier, ok);
- } else if ((is_get || is_set) &&
- (in_class || (peek() != Token::RBRACE && peek() != Token::COMMA &&
- peek() != Token::ASSIGN))) {
- // Accessor
+ }
+
+ if (is_get || is_set) {
+ // MethodDefinition (Accessors)
+ // get PropertyName '(' ')' '{' FunctionBody '}'
+ // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}'
name = this->EmptyIdentifier();
bool dont_care = false;
name_token = peek();
@@ -2693,44 +2744,12 @@ ParserBase<Traits>::ParsePropertyDefinition(
name_expression, value,
is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER,
is_static, *is_computed_name);
-
- } else if (!in_class && Token::IsIdentifier(name_token, language_mode(),
- this->is_generator())) {
- DCHECK(!*is_computed_name);
- DCHECK(!is_static);
-
- if (classifier->duplicate_finder() != nullptr &&
- scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) {
- classifier->RecordDuplicateFormalParameterError(scanner()->location());
- }
-
- ExpressionT lhs = this->ExpressionFromIdentifier(
- name, next_beg_pos, next_end_pos, scope_, factory());
- if (peek() == Token::ASSIGN) {
- this->ExpressionUnexpectedToken(classifier);
- Consume(Token::ASSIGN);
- ExpressionClassifier rhs_classifier;
- ExpressionT rhs = this->ParseAssignmentExpression(
- true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
- classifier->Accumulate(rhs_classifier,
- ExpressionClassifier::ExpressionProductions);
- value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
- RelocInfo::kNoPosition);
- } else {
- value = lhs;
- }
- return factory()->NewObjectLiteralProperty(
- name_expression, value, ObjectLiteralProperty::COMPUTED, false, false);
-
- } else {
- Token::Value next = Next();
- ReportUnexpectedToken(next);
- *ok = false;
- return this->EmptyObjectLiteralProperty();
}
- return factory()->NewObjectLiteralProperty(name_expression, value, is_static,
- *is_computed_name);
+ Token::Value next = Next();
+ ReportUnexpectedToken(next);
+ *ok = false;
+ return this->EmptyObjectLiteralProperty();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698