diff --git a/src/ast.h b/src/ast.h index 394e7f974a..03f1adf5ae 100644 --- a/src/ast.h +++ b/src/ast.h @@ -2510,27 +2510,23 @@ class ClassLiteral FINAL : public Expression { Handle name() const { return raw_name_->string(); } const AstRawString* raw_name() const { return raw_name_; } Expression* extends() const { return extends_; } - FunctionLiteral* constructor() const { return constructor_; } + Expression* constructor() const { return constructor_; } ZoneList* properties() const { return properties_; } protected: ClassLiteral(Zone* zone, const AstRawString* name, Expression* extends, - FunctionLiteral* constructor, ZoneList* properties, - AstValueFactory* ast_value_factory, int position, IdGen* id_gen) + Expression* constructor, ZoneList* properties, + int position, IdGen* id_gen) : Expression(zone, position, id_gen), raw_name_(name), - raw_inferred_name_(ast_value_factory->empty_string()), extends_(extends), constructor_(constructor), properties_(properties) {} private: const AstRawString* raw_name_; - Handle name_; - const AstString* raw_inferred_name_; - Handle inferred_name_; Expression* extends_; - FunctionLiteral* constructor_; + Expression* constructor_; ZoneList* properties_; }; @@ -3504,13 +3500,11 @@ class AstNodeFactory FINAL BASE_EMBEDDED { } ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends, - FunctionLiteral* constructor, + Expression* constructor, ZoneList* properties, - AstValueFactory* ast_value_factory, int position) { - ClassLiteral* lit = - new (zone_) ClassLiteral(zone_, name, extends, constructor, properties, - ast_value_factory, position, id_gen_); + ClassLiteral* lit = new (zone_) ClassLiteral( + zone_, name, extends, constructor, properties, position, id_gen_); VISIT_AND_RETURN(ClassLiteral, lit) } diff --git a/src/parser.cc b/src/parser.cc index 2e552e10f3..9d10d308b2 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -664,6 +664,13 @@ Expression* ParserTraits::SuperReference( pos); } +Expression* ParserTraits::ClassLiteral( + const AstRawString* name, Expression* extends, Expression* constructor, + ZoneList* properties, int pos, + AstNodeFactory* factory) { + return factory->NewClassLiteral(name, extends, constructor, properties, pos); +} + Literal* ParserTraits::ExpressionFromLiteral( Token::Value token, int pos, Scanner* scanner, @@ -1962,8 +1969,8 @@ Statement* Parser::ParseClassDeclaration(ZoneList* names, bool is_strict_reserved = false; const AstRawString* name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); - ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), - is_strict_reserved, pos, CHECK_OK); + Expression* value = ParseClassLiteral(name, scanner()->location(), + is_strict_reserved, pos, CHECK_OK); Block* block = factory()->NewBlock(NULL, 1, true, pos); VariableMode mode = LET; diff --git a/src/parser.h b/src/parser.h index d73075a42a..40886f669d 100644 --- a/src/parser.h +++ b/src/parser.h @@ -524,7 +524,6 @@ class ParserTraits { } static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return NULL; } static FunctionLiteral* EmptyFunctionLiteral() { return NULL; } - static ClassLiteral* EmptyClassLiteral() { return NULL; } // Used in error return values. static ZoneList* NullExpressionList() { @@ -549,6 +548,12 @@ class ParserTraits { Expression* SuperReference(Scope* scope, AstNodeFactory* factory, int pos = RelocInfo::kNoPosition); + Expression* ClassLiteral(const AstRawString* name, Expression* extends, + Expression* constructor, + ZoneList* properties, + int pos, + AstNodeFactory* factory); + Literal* ExpressionFromLiteral( Token::Value token, int pos, Scanner* scanner, AstNodeFactory* factory); diff --git a/src/preparser.h b/src/preparser.h index f9a3fbea0b..bdcc42ba16 100644 --- a/src/preparser.h +++ b/src/preparser.h @@ -64,7 +64,6 @@ class ParserBase : public Traits { typedef typename Traits::Type::Expression ExpressionT; typedef typename Traits::Type::Identifier IdentifierT; typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; - typedef typename Traits::Type::ClassLiteral ClassLiteralT; typedef typename Traits::Type::Literal LiteralT; typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; @@ -502,10 +501,10 @@ class ParserBase : public Traits { bool* ok); ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, bool* ok); - ClassLiteralT ParseClassLiteral(IdentifierT name, - Scanner::Location function_name_location, - bool name_is_strict_reserved, int pos, - bool* ok); + ExpressionT ParseClassLiteral(IdentifierT name, + Scanner::Location function_name_location, + bool name_is_strict_reserved, int pos, + bool* ok); // Checks if the expression is a valid reference expression (e.g., on the // left-hand side of assignments). Although ruled out by ECMA as early errors, @@ -1087,7 +1086,6 @@ class PreParserFactory { PreParserExpression extends, PreParserExpression constructor, PreParserExpressionList properties, - AstValueFactory* ast_value_factory, int position) { return PreParserExpression::Default(); } @@ -1287,9 +1285,6 @@ class PreParserTraits { static PreParserExpression EmptyFunctionLiteral() { return PreParserExpression::Default(); } - static PreParserExpression EmptyClassLiteral() { - return PreParserExpression::Default(); - } static PreParserExpressionList NullExpressionList() { return PreParserExpressionList(); } @@ -1318,6 +1313,15 @@ class PreParserTraits { return PreParserExpression::Super(); } + static PreParserExpression ClassLiteral(PreParserIdentifier name, + PreParserExpression extends, + PreParserExpression constructor, + PreParserExpressionList properties, + int position, + PreParserFactory* factory) { + return PreParserExpression::Default(); + } + static PreParserExpression ExpressionFromLiteral( Token::Value token, int pos, Scanner* scanner, PreParserFactory* factory) { @@ -2713,21 +2717,19 @@ typename ParserBase::ExpressionT ParserBase< template -typename ParserBase::ClassLiteralT -ParserBase::ParseClassLiteral(IdentifierT name, - Scanner::Location class_name_location, - bool name_is_strict_reserved, int pos, - bool* ok) { +typename ParserBase::ExpressionT ParserBase::ParseClassLiteral( + IdentifierT name, Scanner::Location class_name_location, + bool name_is_strict_reserved, int pos, bool* ok) { // All parts of a ClassDeclaration or a ClassExpression are strict code. if (name_is_strict_reserved) { ReportMessageAt(class_name_location, "unexpected_strict_reserved"); *ok = false; - return this->EmptyClassLiteral(); + return this->EmptyExpression(); } if (this->IsEvalOrArguments(name)) { ReportMessageAt(class_name_location, "strict_eval_arguments"); *ok = false; - return this->EmptyClassLiteral(); + return this->EmptyExpression(); } // TODO(arv): Implement scopes and name binding in class body only. @@ -2742,8 +2744,7 @@ ParserBase::ParseClassLiteral(IdentifierT name, ExpressionT extends = this->EmptyExpression(); if (Check(Token::EXTENDS)) { - extends = - this->ParseLeftHandSideExpression(CHECK_OK_CUSTOM(EmptyClassLiteral)); + extends = this->ParseLeftHandSideExpression(CHECK_OK); } ObjectLiteralChecker checker(this, STRICT); @@ -2751,15 +2752,15 @@ ParserBase::ParseClassLiteral(IdentifierT name, this->NewPropertyList(4, zone_); FunctionLiteralT constructor = this->EmptyFunctionLiteral(); - Expect(Token::LBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); + Expect(Token::LBRACE, CHECK_OK); while (peek() != Token::RBRACE) { if (Check(Token::SEMICOLON)) continue; if (fni_ != NULL) fni_->Enter(); const bool in_class = true; const bool is_static = false; - ObjectLiteralPropertyT property = this->ParsePropertyDefinition( - &checker, in_class, is_static, CHECK_OK_CUSTOM(EmptyClassLiteral)); + ObjectLiteralPropertyT property = + this->ParsePropertyDefinition(&checker, in_class, is_static, CHECK_OK); properties->Add(property, zone()); @@ -2768,10 +2769,10 @@ ParserBase::ParseClassLiteral(IdentifierT name, fni_->Leave(); } } - Expect(Token::RBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); + Expect(Token::RBRACE, CHECK_OK); - return factory()->NewClassLiteral(name, extends, constructor, properties, - this->ast_value_factory(), pos); + return this->ClassLiteral(name, extends, constructor, properties, pos, + factory()); }