OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-visitor.h" | 9 #include "src/ast/ast-expression-visitor.h" |
10 #include "src/ast/ast-literal-reindexer.h" | 10 #include "src/ast/ast-literal-reindexer.h" |
(...skipping 4909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4920 | 4920 |
4921 const bool has_extends = extends != nullptr; | 4921 const bool has_extends = extends != nullptr; |
4922 while (peek() != Token::RBRACE) { | 4922 while (peek() != Token::RBRACE) { |
4923 if (Check(Token::SEMICOLON)) continue; | 4923 if (Check(Token::SEMICOLON)) continue; |
4924 FuncNameInferrer::State fni_state(fni_); | 4924 FuncNameInferrer::State fni_state(fni_); |
4925 const bool in_class = true; | 4925 const bool in_class = true; |
4926 const bool is_static = false; | 4926 const bool is_static = false; |
4927 bool is_computed_name = false; // Classes do not care about computed | 4927 bool is_computed_name = false; // Classes do not care about computed |
4928 // property names here. | 4928 // property names here. |
4929 ExpressionClassifier classifier; | 4929 ExpressionClassifier classifier; |
4930 const AstRawString* name = nullptr; | |
4930 ObjectLiteral::Property* property = ParsePropertyDefinition( | 4931 ObjectLiteral::Property* property = ParsePropertyDefinition( |
4931 &checker, in_class, has_extends, is_static, &is_computed_name, | 4932 &checker, in_class, has_extends, is_static, &is_computed_name, |
4932 &has_seen_constructor, &classifier, CHECK_OK); | 4933 &has_seen_constructor, &classifier, &name, CHECK_OK); |
4933 ValidateExpression(&classifier, CHECK_OK); | 4934 ValidateExpression(&classifier, CHECK_OK); |
4934 | 4935 |
4935 if (has_seen_constructor && constructor == NULL) { | 4936 if (has_seen_constructor && constructor == NULL) { |
4936 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 4937 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
4937 DCHECK_NOT_NULL(constructor); | 4938 DCHECK_NOT_NULL(constructor); |
4938 } else { | 4939 } else { |
4939 properties->Add(property, zone()); | 4940 properties->Add(property, zone()); |
4940 } | 4941 } |
4941 | 4942 |
4942 if (fni_ != NULL) fni_->Infer(); | 4943 if (fni_ != NULL) fni_->Infer(); |
4944 | |
4945 if (allow_harmony_function_name()) { | |
4946 SetFunctionNameFromPropertyName(property, name); | |
4947 } | |
4943 } | 4948 } |
4944 | 4949 |
4945 Expect(Token::RBRACE, CHECK_OK); | 4950 Expect(Token::RBRACE, CHECK_OK); |
4946 int end_pos = scanner()->location().end_pos; | 4951 int end_pos = scanner()->location().end_pos; |
4947 | 4952 |
4948 if (constructor == NULL) { | 4953 if (constructor == NULL) { |
4949 constructor = DefaultConstructor(extends != NULL, block_scope, pos, end_pos, | 4954 constructor = DefaultConstructor(extends != NULL, block_scope, pos, end_pos, |
4950 block_scope->language_mode()); | 4955 block_scope->language_mode()); |
4951 } | 4956 } |
4952 | 4957 |
(...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6515 } | 6520 } |
6516 | 6521 |
6517 | 6522 |
6518 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { | 6523 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { |
6519 DCHECK(expr->IsRewritableAssignmentExpression()); | 6524 DCHECK(expr->IsRewritableAssignmentExpression()); |
6520 parser_->function_state_->AddDestructuringAssignment( | 6525 parser_->function_state_->AddDestructuringAssignment( |
6521 Parser::DestructuringAssignment(expr, parser_->scope_)); | 6526 Parser::DestructuringAssignment(expr, parser_->scope_)); |
6522 } | 6527 } |
6523 | 6528 |
6524 | 6529 |
6530 void ParserTraits::SetFunctionNameFromPropertyName( | |
6531 ObjectLiteralProperty* property, const AstRawString* name) { | |
6532 Expression* value = property->value(); | |
6533 if (!value->IsFunctionLiteral() && !value->IsClassLiteral()) return; | |
6534 | |
6535 // TODO(adamk): Support computed names. | |
6536 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
| |
6537 DCHECK_NOT_NULL(name); | |
6538 | |
6539 if (value->IsFunctionLiteral()) { | |
6540 auto function = value->AsFunctionLiteral(); | |
6541 if (function->is_anonymous()) { | |
6542 if (property->kind() == ObjectLiteralProperty::GETTER) { | |
6543 function->set_raw_name(parser_->ast_value_factory()->NewConsString( | |
6544 parser_->ast_value_factory()->get_space_string(), name)); | |
6545 } else if (property->kind() == ObjectLiteralProperty::SETTER) { | |
6546 function->set_raw_name(parser_->ast_value_factory()->NewConsString( | |
6547 parser_->ast_value_factory()->set_space_string(), name)); | |
6548 } else { | |
6549 function->set_raw_name(name); | |
6550 } | |
6551 } | |
6552 } else if (value->IsClassLiteral()) { | |
6553 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
| |
6554 if (class_literal->raw_name() == nullptr) { | |
6555 class_literal->set_raw_name(name); | |
6556 } | |
6557 } | |
6558 } | |
6559 | |
6560 | |
6525 } // namespace internal | 6561 } // namespace internal |
6526 } // namespace v8 | 6562 } // namespace v8 |
OLD | NEW |