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

Unified Diff: src/parsing/parser.cc

Issue 1563923002: [es6] Handle function names in object and class literals (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Handled review comments Created 4 years, 11 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 | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 4a355546d80e326af054966158adf69e367a827a..ee2a696d458b2441135e61a88fcb25f748e7db68 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -4927,9 +4927,10 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
bool is_computed_name = false; // Classes do not care about computed
// property names here.
ExpressionClassifier classifier;
+ const AstRawString* name = nullptr;
ObjectLiteral::Property* property = ParsePropertyDefinition(
&checker, in_class, has_extends, is_static, &is_computed_name,
- &has_seen_constructor, &classifier, CHECK_OK);
+ &has_seen_constructor, &classifier, &name, CHECK_OK);
ValidateExpression(&classifier, CHECK_OK);
if (has_seen_constructor && constructor == NULL) {
@@ -4940,6 +4941,10 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
}
if (fni_ != NULL) fni_->Infer();
+
+ if (allow_harmony_function_name()) {
+ SetFunctionNameFromPropertyName(property, name);
+ }
}
Expect(Token::RBRACE, CHECK_OK);
@@ -6522,5 +6527,43 @@ void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) {
}
+void ParserTraits::SetFunctionNameFromPropertyName(
+ ObjectLiteralProperty* property, const AstRawString* name) {
+ Expression* value = property->value();
+ if (!value->IsFunctionLiteral() && !value->IsClassLiteral()) return;
+
+ // TODO(adamk): Support computed names.
+ if (property->is_computed_name()) return;
+ DCHECK_NOT_NULL(name);
+
+ // Ignore "__proto__" as a name when it's being used to set the [[Prototype]]
+ // of an object literal.
+ if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return;
+
+ if (value->IsFunctionLiteral()) {
+ auto function = value->AsFunctionLiteral();
+ if (function->is_anonymous()) {
+ if (property->kind() == ObjectLiteralProperty::GETTER) {
+ function->set_raw_name(parser_->ast_value_factory()->NewConsString(
+ parser_->ast_value_factory()->get_space_string(), name));
+ } else if (property->kind() == ObjectLiteralProperty::SETTER) {
+ function->set_raw_name(parser_->ast_value_factory()->NewConsString(
+ parser_->ast_value_factory()->set_space_string(), name));
+ } else {
+ function->set_raw_name(name);
+ DCHECK_EQ(ObjectLiteralProperty::COMPUTED, property->kind());
+ }
+ }
+ } else {
+ DCHECK(value->IsClassLiteral());
+ DCHECK_EQ(ObjectLiteralProperty::COMPUTED, property->kind());
+ auto class_literal = value->AsClassLiteral();
+ if (class_literal->raw_name() == nullptr) {
+ class_literal->set_raw_name(name);
+ }
+ }
+}
+
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698