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

Unified Diff: src/parser.cc

Issue 1002253002: [strong] Check super constructor calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Should be ReferenceError Created 5 years, 9 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/messages.js ('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 c038ca2fa7f8db18b32436554a70d920ce829e50..afc952ce67015bb7505d91f619661223c7f24b13 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1192,8 +1192,27 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
directive_prologue = false;
}
+ Token::Value token = peek();
Scanner::Location token_loc = scanner()->peek_location();
+ Scanner::Location old_super_loc = function_state_->super_call_location();
Statement* stat = ParseStatementListItem(CHECK_OK);
+ 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) {
+ // TODO(rossberg): This is more permissive than spec'ed, it allows e.g.
+ // super(), 1;
+ // super() + "";
+ // super() = 0;
+ // That should still be safe, though, thanks to left-to-right evaluation.
+ // The proper check would be difficult to implement in the preparser.
+ ReportMessageAt(super_loc, "strong_super_call_nested");
+ *ok = false;
+ return NULL;
+ }
+
if (stat == NULL || stat->IsEmpty()) {
directive_prologue = false; // End of directive prologue.
continue;
@@ -3916,6 +3935,14 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
if (is_strict(language_mode())) {
CheckConflictingVarDeclarations(scope, CHECK_OK);
}
+ if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
+ if (!function_state.super_call_location().IsValid()) {
+ ReportMessageAt(function_name_location, "strong_super_call_missing",
+ kReferenceError);
+ *ok = false;
+ return nullptr;
+ }
+ }
}
FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
« no previous file with comments | « src/messages.js ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698