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

Unified Diff: src/preparser.h

Issue 1328083002: [es6] support `get` and `set` in shorthand properties (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: A more fundamental refactoring to make things clearer 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 | test/cctest/test-parsing.cc » ('j') | 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 4f710fb65a7301543da44fa206300506d9afd255..b7d8237fe243c11b52a33049c15187314fdae5ec 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2611,19 +2611,73 @@ 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) {
caitp (gmail) 2015/09/07 03:16:17 I reorganized ParsePropertyDefinition because it w
+ // ObjectLiteral-exclusive productions
+ switch (peek()) {
+ case Token::COLON: {
+ // PropertyDefinition :
+ // PropertyName : AssignmentExpression
+ // PropertyName : BindingPattern
+ if (!*is_computed_name) {
+ checker->CheckProperty(name_token, kValueProperty, is_static,
+ is_generator,
+ 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);
+ }
+ case Token::ASSIGN:
+ // CoverInitializedName
+ // BindingIdentifier = AssignmentPattern
+ this->ExpressionUnexpectedToken(classifier);
+ case Token::COMMA:
+ case Token::RBRACE: {
+ // BindingIdentifier
+ if (!Token::IsIdentifier(name_token, language_mode(),
+ this->is_generator()))
+ break;
adamk 2015/09/08 23:17:17 This break makes this whole approach not much easi
caitp (gmail) 2015/09/08 23:35:13 It can work the other way, just makes the inventio
+
+ 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 (Check(Token::ASSIGN)) {
+ // CoverInitializedName
+ // BindingIdentifier = AssignmentPattern
+ 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 {
+ // BindingIdentifier
+ value = lhs;
+ }
+
+ return factory()->NewObjectLiteralProperty(
+ name_expression, value, ObjectLiteralProperty::COMPUTED, false,
+ false);
+ }
+ default:
+ break;
}
- Consume(Token::COLON);
- value = this->ParseAssignmentExpression(
- true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ }
- } else if (is_generator || peek() == Token::LPAREN) {
- // Concise Method
+ 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,13 +2704,14 @@ 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
return ParsePropertyDefinition(checker, true, has_extends, true,
is_computed_name, nullptr, classifier, ok);
} else if (is_get || is_set) {
- // Accessor
+ // MethodDefinition (Accessors) :
+ // get PropertyName ( ) { FunctionBody }
+ // set PropertyName ( PropertySetParameterList ) { FunctionBody }
name = this->EmptyIdentifier();
bool dont_care = false;
name_token = peek();
@@ -2691,44 +2746,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);
}
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698