Index: src/parsing/preparser.cc |
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc |
index c255285e9f67b2a7ec826d1505beabee38ac85a7..d4438b8d696722c1e3dae4180fde1386f519706e 100644 |
--- a/src/parsing/preparser.cc |
+++ b/src/parsing/preparser.cc |
@@ -135,6 +135,18 @@ |
// That means that contextual checks (like a label being declared where |
// it is used) are generally omitted. |
+PreParser::Statement PreParser::ParseClassDeclaration( |
+ ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { |
+ int pos = position(); |
+ bool is_strict_reserved = false; |
+ Identifier name = |
+ ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
+ ExpressionClassifier no_classifier(this); |
+ ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, |
+ CHECK_OK); |
+ return Statement::Default(); |
+} |
+ |
PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
Consume(Token::FUNCTION); |
int pos = position(); |
@@ -239,6 +251,57 @@ |
return kLazyParsingComplete; |
} |
+PreParserExpression PreParser::ParseClassLiteral( |
+ PreParserIdentifier name, Scanner::Location class_name_location, |
+ bool name_is_strict_reserved, int pos, bool* ok) { |
+ // All parts of a ClassDeclaration and ClassExpression are strict code. |
+ if (name_is_strict_reserved) { |
+ ReportMessageAt(class_name_location, |
+ MessageTemplate::kUnexpectedStrictReserved); |
+ *ok = false; |
+ return EmptyExpression(); |
+ } |
+ if (IsEvalOrArguments(name)) { |
+ ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
+ *ok = false; |
+ return EmptyExpression(); |
+ } |
+ |
+ LanguageMode class_language_mode = language_mode(); |
+ BlockState block_state(zone(), &scope_state_); |
+ scope()->SetLanguageMode( |
+ static_cast<LanguageMode>(class_language_mode | STRICT)); |
+ // TODO(marja): Make PreParser use scope names too. |
+ // this->scope()->SetScopeName(name); |
+ |
+ bool has_extends = Check(Token::EXTENDS); |
+ if (has_extends) { |
+ ExpressionClassifier extends_classifier(this); |
+ ParseLeftHandSideExpression(CHECK_OK); |
+ ValidateExpression(CHECK_OK); |
+ impl()->AccumulateFormalParameterContainmentErrors(); |
+ } |
+ |
+ ClassLiteralChecker checker(this); |
+ bool has_seen_constructor = false; |
+ |
+ Expect(Token::LBRACE, CHECK_OK); |
+ while (peek() != Token::RBRACE) { |
+ if (Check(Token::SEMICOLON)) continue; |
+ bool is_computed_name = false; // Classes do not care about computed |
+ // property names here. |
+ ExpressionClassifier property_classifier(this); |
+ ParseClassPropertyDefinition(&checker, has_extends, &is_computed_name, |
+ &has_seen_constructor, CHECK_OK); |
+ ValidateExpression(CHECK_OK); |
+ impl()->AccumulateFormalParameterContainmentErrors(); |
+ } |
+ |
+ Expect(Token::RBRACE, CHECK_OK); |
+ |
+ return Expression::Default(); |
+} |
+ |
PreParserExpression PreParser::ExpressionFromIdentifier( |
PreParserIdentifier name, int start_position, int end_position, |
InferName infer) { |