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

Side by Side Diff: src/parsing/parser.cc

Issue 2302643002: Split the AST representation of class properties from object properties (Closed)
Patch Set: remove spurious classliteralproperty typedef Created 4 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 unified diff | Download patch
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 <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 4518 matching lines...) Expand 10 before | Expand all | Expand 10 after
4529 extends = ParseLeftHandSideExpression(CHECK_OK); 4529 extends = ParseLeftHandSideExpression(CHECK_OK);
4530 CheckNoTailCallExpressions(CHECK_OK); 4530 CheckNoTailCallExpressions(CHECK_OK);
4531 RewriteNonPattern(CHECK_OK); 4531 RewriteNonPattern(CHECK_OK);
4532 impl()->AccumulateFormalParameterContainmentErrors(); 4532 impl()->AccumulateFormalParameterContainmentErrors();
4533 } else { 4533 } else {
4534 block_state.set_start_position(scanner()->location().end_pos); 4534 block_state.set_start_position(scanner()->location().end_pos);
4535 } 4535 }
4536 4536
4537 4537
4538 ClassLiteralChecker checker(this); 4538 ClassLiteralChecker checker(this);
4539 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4); 4539 ZoneList<ClassLiteral::Property*>* properties = NewClassPropertyList(4);
4540 FunctionLiteral* constructor = nullptr; 4540 FunctionLiteral* constructor = nullptr;
4541 bool has_seen_constructor = false; 4541 bool has_seen_constructor = false;
4542 4542
4543 Expect(Token::LBRACE, CHECK_OK); 4543 Expect(Token::LBRACE, CHECK_OK);
4544 4544
4545 const bool has_extends = extends != nullptr; 4545 const bool has_extends = extends != nullptr;
4546 while (peek() != Token::RBRACE) { 4546 while (peek() != Token::RBRACE) {
4547 if (Check(Token::SEMICOLON)) continue; 4547 if (Check(Token::SEMICOLON)) continue;
4548 FuncNameInferrer::State fni_state(fni_); 4548 FuncNameInferrer::State fni_state(fni_);
4549 const bool in_class = true;
4550 bool is_computed_name = false; // Classes do not care about computed 4549 bool is_computed_name = false; // Classes do not care about computed
4551 // property names here. 4550 // property names here.
4552 ExpressionClassifier property_classifier(this); 4551 ExpressionClassifier property_classifier(this);
4553 const AstRawString* property_name = nullptr; 4552 const AstRawString* property_name = nullptr;
4554 ObjectLiteral::Property* property = ParsePropertyDefinition( 4553 ClassLiteral::Property* property = ParseClassPropertyDefinition(
4555 &checker, in_class, has_extends, &is_computed_name, 4554 &checker, has_extends, &is_computed_name, &has_seen_constructor,
4556 &has_seen_constructor, &property_name, CHECK_OK); 4555 &property_name, CHECK_OK);
4557 RewriteNonPattern(CHECK_OK); 4556 RewriteNonPattern(CHECK_OK);
4558 impl()->AccumulateFormalParameterContainmentErrors(); 4557 impl()->AccumulateFormalParameterContainmentErrors();
4559 4558
4560 if (has_seen_constructor && constructor == nullptr) { 4559 if (has_seen_constructor && constructor == nullptr) {
4561 constructor = GetPropertyValue(property)->AsFunctionLiteral(); 4560 constructor = GetPropertyValue(property)->AsFunctionLiteral();
4562 DCHECK_NOT_NULL(constructor); 4561 DCHECK_NOT_NULL(constructor);
4563 constructor->set_raw_name( 4562 constructor->set_raw_name(
4564 name != nullptr ? name : ast_value_factory()->empty_string()); 4563 name != nullptr ? name : ast_value_factory()->empty_string());
4565 } else { 4564 } else {
4566 properties->Add(property, zone()); 4565 properties->Add(property, zone());
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
5321 return true; 5320 return true;
5322 } 5321 }
5323 if (expr->IsBinaryOperation() && 5322 if (expr->IsBinaryOperation() &&
5324 expr->AsBinaryOperation()->op() == Token::COMMA) { 5323 expr->AsBinaryOperation()->op() == Token::COMMA) {
5325 return true; 5324 return true;
5326 } 5325 }
5327 // Everything else does not need rewriting. 5326 // Everything else does not need rewriting.
5328 return false; 5327 return false;
5329 } 5328 }
5330 5329
5331 void VisitObjectLiteralProperty(ObjectLiteralProperty* property) override { 5330 void VisitLiteralProperty(LiteralProperty* property) override {
5332 if (property == nullptr) return; 5331 if (property == nullptr) return;
5333 // Do not rewrite (computed) key expressions 5332 // Do not rewrite (computed) key expressions
5334 AST_REWRITE_PROPERTY(Expression, property, value); 5333 AST_REWRITE_PROPERTY(Expression, property, value);
5335 } 5334 }
5336 5335
5337 Parser* parser_; 5336 Parser* parser_;
5338 }; 5337 };
5339 5338
5340 void Parser::RewriteNonPattern(bool* ok) { 5339 void Parser::RewriteNonPattern(bool* ok) {
5341 ValidateExpression(CHECK_OK_VOID); 5340 ValidateExpression(CHECK_OK_VOID);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
5532 5531
5533 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]] 5532 // Ignore "__proto__" as a name when it's being used to set the [[Prototype]]
5534 // of an object literal. 5533 // of an object literal.
5535 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return; 5534 if (property->kind() == ObjectLiteralProperty::PROTOTYPE) return;
5536 5535
5537 DCHECK(!value->IsAnonymousFunctionDefinition() || 5536 DCHECK(!value->IsAnonymousFunctionDefinition() ||
5538 property->kind() == ObjectLiteralProperty::COMPUTED); 5537 property->kind() == ObjectLiteralProperty::COMPUTED);
5539 SetFunctionName(value, name); 5538 SetFunctionName(value, name);
5540 } 5539 }
5541 5540
5541 void Parser::SetFunctionNameFromPropertyName(ClassLiteralProperty* property,
adamk 2016/09/01 21:18:23 Duplicating this is kind of sad...I wonder why we
bakkot 2016/09/01 23:24:31 I'm going to leave this as-is for the moment. I'm
5542 const AstRawString* name) {
5543 Expression* value = property->value();
5544
5545 // Computed name setting must happen at runtime.
5546 if (property->is_computed_name()) return;
5547
5548 // Getter and setter names are handled here because their names
5549 // change in ES2015, even though they are not anonymous.
5550 auto function = value->AsFunctionLiteral();
5551 DCHECK_NOT_NULL(function);
5552
5553 bool is_getter = property->kind() == ClassLiteralProperty::GETTER;
5554 bool is_setter = property->kind() == ClassLiteralProperty::SETTER;
5555 if (is_getter || is_setter) {
5556 DCHECK_NOT_NULL(name);
5557 const AstRawString* prefix = is_getter
5558 ? ast_value_factory()->get_space_string()
5559 : ast_value_factory()->set_space_string();
5560 function->set_raw_name(ast_value_factory()->NewConsString(prefix, name));
5561 return;
5562 }
5563
5564 SetFunctionName(value, name);
5565 }
5566
5542 void Parser::SetFunctionNameFromIdentifierRef(Expression* value, 5567 void Parser::SetFunctionNameFromIdentifierRef(Expression* value,
5543 Expression* identifier) { 5568 Expression* identifier) {
5544 if (!identifier->IsVariableProxy()) return; 5569 if (!identifier->IsVariableProxy()) return;
5545 SetFunctionName(value, identifier->AsVariableProxy()->raw_name()); 5570 SetFunctionName(value, identifier->AsVariableProxy()->raw_name());
5546 } 5571 }
5547 5572
5548 void Parser::SetFunctionName(Expression* value, const AstRawString* name) { 5573 void Parser::SetFunctionName(Expression* value, const AstRawString* name) {
5549 DCHECK_NOT_NULL(name); 5574 DCHECK_NOT_NULL(name);
5550 if (!value->IsAnonymousFunctionDefinition()) return; 5575 if (!value->IsAnonymousFunctionDefinition()) return;
5551 auto function = value->AsFunctionLiteral(); 5576 auto function = value->AsFunctionLiteral();
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
6488 node->Print(Isolate::Current()); 6513 node->Print(Isolate::Current());
6489 } 6514 }
6490 #endif // DEBUG 6515 #endif // DEBUG
6491 6516
6492 #undef CHECK_OK 6517 #undef CHECK_OK
6493 #undef CHECK_OK_VOID 6518 #undef CHECK_OK_VOID
6494 #undef CHECK_FAILED 6519 #undef CHECK_FAILED
6495 6520
6496 } // namespace internal 6521 } // namespace internal
6497 } // namespace v8 6522 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698