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

Unified Diff: src/parser.cc

Issue 561913002: Class syntax parsing (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add early error checks for static prototype and get/set constructor Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index b5f9c1bbbe5c9ebca94d01d8ea90586e7f63a80e..9a088bc646ce7611f9908d0792d33d60f1901037 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -366,6 +366,16 @@ bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
}
+bool ParserTraits::IsPrototype(const AstRawString* identifier) const {
+ return identifier == parser_->ast_value_factory_->prototype_string();
+}
+
+
+bool ParserTraits::IsConstructor(const AstRawString* identifier) const {
+ return identifier == parser_->ast_value_factory_->constructor_string();
+}
+
+
bool ParserTraits::IsThisProperty(Expression* expression) {
DCHECK(expression != NULL);
Property* property = expression->AsProperty();
@@ -1123,10 +1133,13 @@ Statement* Parser::ParseModuleElement(ZoneList<const AstRawString*>* labels,
// ImportDeclaration
// ExportDeclaration
// GeneratorDeclaration
+ // ClassDeclaration
switch (peek()) {
case Token::FUNCTION:
return ParseFunctionDeclaration(NULL, ok);
+ case Token::CLASS:
+ return ParseClassDeclaration(NULL, ok);
case Token::IMPORT:
return ParseImportDeclaration(ok);
case Token::EXPORT:
@@ -1466,6 +1479,10 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
result = ParseFunctionDeclaration(&names, CHECK_OK);
break;
+ case Token::CLASS:
+ result = ParseClassDeclaration(&names, CHECK_OK);
+ break;
+
case Token::VAR:
case Token::LET:
case Token::CONST:
@@ -1528,10 +1545,13 @@ Statement* Parser::ParseBlockElement(ZoneList<const AstRawString*>* labels,
// LetDeclaration
// ConstDeclaration
// GeneratorDeclaration
+ // ClassDeclaration
switch (peek()) {
case Token::FUNCTION:
return ParseFunctionDeclaration(NULL, ok);
+ case Token::CLASS:
+ return ParseClassDeclaration(NULL, ok);
case Token::CONST:
return ParseVariableStatement(kModuleElement, NULL, ok);
case Token::LET:
@@ -1643,6 +1663,9 @@ Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels,
return ParseFunctionDeclaration(NULL, ok);
}
+ case Token::CLASS:
+ return ParseClassDeclaration(NULL, ok);
+
case Token::DEBUGGER:
return ParseDebuggerStatement(ok);
@@ -1911,6 +1934,27 @@ Statement* Parser::ParseFunctionDeclaration(
}
+Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
+ bool* ok) {
+ // ClassDeclaration ::
+ // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
+ Expect(Token::CLASS, CHECK_OK);
+ int pos = position();
+ bool is_strict_reserved = false;
+ const AstRawString* name =
+ ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
+ ClassLiteral* lit = ParseClassLiteral(name, scanner()->location(),
+ is_strict_reserved, pos, CHECK_OK);
+ VariableMode mode = LET;
+ VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
+ Declaration* declaration =
+ factory()->NewClassDeclaration(proxy, lit, scope_, pos);
+ Declare(declaration, true, CHECK_OK);
+ if (names) names->Add(name, zone());
+ return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
+}
+
+
Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) {
if (allow_harmony_scoping() && strict_mode() == STRICT) {
return ParseScopedBlock(labels, ok);
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698