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

Unified Diff: src/parser.cc

Issue 722793005: Classes: Implement correct name binding (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: git rebase Created 6 years, 1 month 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') | no next file with comments »
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 99c93b88faffa57bcf087fdac07ad9010688cafa..b2cf3b1a6d385ee7d79b9b46bcda1dc2dd209346 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -685,13 +685,6 @@ Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory,
pos);
}
-Expression* ParserTraits::ClassExpression(
- const AstRawString* name, Expression* extends, Expression* constructor,
- ZoneList<ObjectLiteral::Property*>* properties, int start_position,
- int end_position, AstNodeFactory* factory) {
- return factory->NewClassLiteral(name, extends, constructor, properties,
- start_position, end_position);
-}
Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope,
int pos, int end_pos) {
@@ -777,6 +770,14 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral(
}
+ClassLiteral* ParserTraits::ParseClassLiteral(
+ const AstRawString* name, Scanner::Location class_name_location,
+ bool name_is_strict_reserved, int pos, bool* ok) {
+ return parser_->ParseClassLiteral(name, class_name_location,
+ name_is_strict_reserved, pos, ok);
+}
+
+
Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
: ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit,
info->extension(), NULL, info->zone(), this),
@@ -1993,8 +1994,8 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
bool is_strict_reserved = false;
const AstRawString* name =
ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
- Expression* value = ParseClassLiteral(name, scanner()->location(),
- is_strict_reserved, pos, CHECK_OK);
+ ClassLiteral* value = ParseClassLiteral(name, scanner()->location(),
+ is_strict_reserved, pos, CHECK_OK);
VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue());
Declaration* declaration =
@@ -3893,6 +3894,90 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
}
+ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
marja 2015/02/10 11:31:49 Is there a reason why ParseClassLiteral is not in
+ 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, "unexpected_strict_reserved");
+ *ok = false;
+ return NULL;
+ }
+ if (IsEvalOrArguments(name)) {
+ ReportMessageAt(class_name_location, "strict_eval_arguments");
+ *ok = false;
+ return NULL;
+ }
+
+ Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
+ BlockState block_state(&scope_, block_scope);
+ scope_->SetStrictMode(STRICT);
+ scope_->SetScopeName(name);
+
+ VariableProxy* proxy = NULL;
+ if (name != NULL) {
+ proxy = NewUnresolved(name, CONST, Interface::NewConst());
+ Declaration* declaration =
+ factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos);
+ Declare(declaration, true, CHECK_OK);
+ }
+
+ Expression* extends = NULL;
+ if (Check(Token::EXTENDS)) {
+ block_scope->set_start_position(scanner()->location().end_pos);
+ extends = ParseLeftHandSideExpression(CHECK_OK);
+ } else {
+ block_scope->set_start_position(scanner()->location().end_pos);
+ }
+
+ ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone());
+ Expression* constructor = NULL;
+ bool has_seen_constructor = false;
+
+ 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;
+ ObjectLiteral::Property* property = ParsePropertyDefinition(
+ NULL, in_class, is_static, &has_seen_constructor, CHECK_OK);
+
+ if (has_seen_constructor && constructor == NULL) {
+ constructor = GetPropertyValue(property);
+ } else {
+ properties->Add(property, zone());
+ }
+
+ if (fni_ != NULL) {
+ fni_->Infer();
+ fni_->Leave();
+ }
+ }
+
+ Expect(Token::RBRACE, CHECK_OK);
+ int end_pos = scanner()->location().end_pos;
+
+ if (constructor == NULL) {
+ constructor =
+ DefaultConstructor(extends != NULL, block_scope, pos, end_pos);
+ }
+
+ block_scope->set_end_position(end_pos);
+ block_scope = block_scope->FinalizeBlockScope();
+
+ if (name != NULL) {
+ DCHECK_NOT_NULL(proxy);
+ DCHECK_NOT_NULL(block_scope);
+ proxy->var()->set_initializer_position(end_pos);
+ }
+
+ return factory()->NewClassLiteral(name, block_scope, proxy, extends,
+ constructor, properties, pos, end_pos);
+}
+
+
Expression* Parser::ParseV8Intrinsic(bool* ok) {
// CallRuntime ::
// '%' Identifier Arguments
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698