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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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;
6537 DCHECK_NOT_NULL(name);
6538
6539 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]]
6540 // of an object literal.
6541 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return;
6542
6543 if (value->IsFunctionLiteral()) {
6544 auto function = value->AsFunctionLiteral();
6545 if (function->is_anonymous()) {
6546 if (property->kind() == ObjectLiteralProperty::GETTER) {
6547 function->set_raw_name(parser_->ast_value_factory()->NewConsString(
6548 parser_->ast_value_factory()->get_space_string(), name));
6549 } else if (property->kind() == ObjectLiteralProperty::SETTER) {
6550 function->set_raw_name(parser_->ast_value_factory()->NewConsString(
6551 parser_->ast_value_factory()->set_space_string(), name));
6552 } else {
6553 function->set_raw_name(name);
6554 DCHECK_EQ(ObjectLiteralProperty::COMPUTED, property->kind());
6555 }
6556 }
6557 } else {
6558 DCHECK(value->IsClassLiteral());
6559 DCHECK_EQ(ObjectLiteralProperty::COMPUTED, property->kind());
6560 auto class_literal = value->AsClassLiteral();
6561 if (class_literal->raw_name() == nullptr) {
6562 class_literal->set_raw_name(name);
6563 }
6564 }
6565 }
6566
6567
6525 } // namespace internal 6568 } // namespace internal
6526 } // namespace v8 6569 } // namespace v8
OLDNEW
« 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