Index: src/preparser.cc |
diff --git a/src/preparser.cc b/src/preparser.cc |
index 5a6a094f6af52b7ba025e9d4ff9c0450499497f7..065bcef8c5f8a5d3301d01e1002b2031c60917c0 100644 |
--- a/src/preparser.cc |
+++ b/src/preparser.cc |
@@ -193,19 +193,31 @@ void PreParser::ParseStatementList(int end_token, bool* ok) { |
if (directive_prologue && peek() != Token::STRING) { |
directive_prologue = false; |
} |
- Token::Value token = peek(); |
- Scanner::Location old_super_loc = function_state_->super_call_location(); |
+ Scanner::Location token_loc = scanner()->peek_location(); |
+ Scanner::Location old_this_loc = function_state_->this_location(); |
+ Scanner::Location old_super_loc = function_state_->super_location(); |
Statement statement = ParseStatementListItem(ok); |
if (!*ok) return; |
- Scanner::Location super_loc = function_state_->super_call_location(); |
+ |
if (is_strong(language_mode()) && |
- i::IsConstructor(function_state_->kind()) && |
- !old_super_loc.IsValid() && super_loc.IsValid() && |
- token != Token::SUPER) { |
- ReportMessageAt(super_loc, "strong_super_call_nested"); |
- *ok = false; |
- return; |
+ scope_->is_function_scope() && |
+ i::IsConstructor(function_state_->kind())) { |
+ Scanner::Location this_loc = function_state_->this_location(); |
+ Scanner::Location super_loc = function_state_->super_location(); |
+ if (this_loc.beg_pos != old_this_loc.beg_pos && |
+ this_loc.beg_pos != token_loc.beg_pos) { |
+ ReportMessageAt(this_loc, "strong_constructor_this"); |
+ *ok = false; |
+ return; |
+ } |
+ if (super_loc.beg_pos != old_super_loc.beg_pos && |
+ super_loc.beg_pos != token_loc.beg_pos) { |
+ ReportMessageAt(super_loc, "strong_constructor_super"); |
+ *ok = false; |
+ return; |
+ } |
} |
+ |
if (directive_prologue) { |
if (statement.IsUseStrictLiteral()) { |
scope_->SetLanguageMode( |
@@ -515,6 +527,37 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
*ok = false; |
return Statement::Default(); |
+ case Token::THIS: |
+ case Token::SUPER: |
+ if (is_strong(language_mode()) && |
+ i::IsConstructor(function_state_->kind())) { |
+ bool is_this = peek() == Token::THIS; |
+ Expression expr = Expression::Default(); |
+ if (is_this) { |
+ expr = ParseStrongInitializationExpression(CHECK_OK); |
+ } else { |
+ expr = ParseStrongSuperCallExpression(CHECK_OK); |
+ } |
+ switch (peek()) { |
+ case Token::SEMICOLON: |
+ Consume(Token::SEMICOLON); |
+ break; |
+ case Token::RBRACE: |
+ case Token::EOS: |
+ break; |
+ default: |
+ if (!scanner()->HasAnyLineTerminatorBeforeNext()) { |
+ ReportMessageAt(function_state_->this_location(), |
+ is_this ? "strong_constructor_this" |
+ : "strong_constructor_super"); |
+ *ok = false; |
+ return Statement::Default(); |
+ } |
+ } |
+ return Statement::ExpressionStatement(expr); |
+ } |
+ break; |
+ |
// TODO(arv): Handle `let [` |
// https://code.google.com/p/v8/issues/detail?id=3847 |
@@ -959,7 +1002,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral( |
} |
if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { |
- if (!function_state.super_call_location().IsValid()) { |
+ if (!function_state.super_location().IsValid()) { |
ReportMessageAt(function_name_location, "strong_super_call_missing", |
kReferenceError); |
*ok = false; |