Chromium Code Reviews| Index: src/parsing/parser.cc |
| diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc |
| index 4a355546d80e326af054966158adf69e367a827a..f86a66253def90e9a1397d7093850703ee86226f 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,36 @@ 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; |
|
Dan Ehrenberg
2016/01/06 21:25:39
Optional: Add a failing test for this case?
adamk
2016/01/06 21:53:02
Done. And this caught a bug for static class prope
|
| + DCHECK_NOT_NULL(name); |
| + |
| + 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); |
| + } |
| + } |
| + } else if (value->IsClassLiteral()) { |
| + auto class_literal = value->AsClassLiteral(); |
|
Dan Ehrenberg
2016/01/06 21:25:39
DCHECK that it's a CONSTANT property?
adamk
2016/01/06 21:53:02
It's not, though. It's "COMPUTED". I've added a DC
|
| + if (class_literal->raw_name() == nullptr) { |
| + class_literal->set_raw_name(name); |
| + } |
| + } |
| +} |
| + |
| + |
| } // namespace internal |
| } // namespace v8 |