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

Unified Diff: src/preparser.h

Issue 1002253002: [strong] Check super constructor calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Typo 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
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index a17296349b362df6afefbb5b8538d7c030915270..b938c3783c54d868ba399a4d58178f2a2ae407ea 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -221,6 +221,13 @@ class ParserBase : public Traits {
void AddProperty() { expected_property_count_++; }
int expected_property_count() { return expected_property_count_; }
+ Scanner::Location super_call_location() const {
+ return super_call_location_;
+ }
+ void set_super_call_location(Scanner::Location location) {
+ super_call_location_ = location;
+ }
+
bool is_generator() const { return IsGeneratorFunction(kind_); }
FunctionKind kind() const { return kind_; }
@@ -251,6 +258,9 @@ class ParserBase : public Traits {
// Properties count estimation.
int expected_property_count_;
+ // Location of call to the "super" constructor (invalid if none).
+ Scanner::Location super_call_location_;
+
FunctionKind kind_;
// For generators, this variable may hold the generator object. It variable
// is used by yield expressions and return statements. It is not necessary
@@ -1661,6 +1671,7 @@ ParserBase<Traits>::FunctionState::FunctionState(
: next_materialized_literal_index_(0),
next_handler_index_(0),
expected_property_count_(0),
+ super_call_location_(Scanner::Location::invalid()),
kind_(kind),
generator_object_variable_(NULL),
function_state_stack_(function_state_stack),
@@ -2802,6 +2813,13 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) {
// new super() is never allowed.
// super() is only allowed in derived constructor
if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
+ if (is_strong(language_mode()) &&
+ function_state->super_call_location().IsValid()) {
+ ReportMessageAt(scanner()->location(), "strong_super_call_duplicate");
+ *ok = false;
+ return this->EmptyExpression();
+ }
+ function_state->set_super_call_location(scanner()->location());
return this->SuperReference(scope_, factory());
}
}
@@ -2871,6 +2889,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
int materialized_literal_count = -1;
int expected_property_count = -1;
int handler_count = 0;
+ Scanner::Location super_loc;
{
typename Traits::Type::Factory function_factory(ast_value_factory());
@@ -2926,6 +2945,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
expected_property_count = function_state.expected_property_count();
handler_count = function_state.handler_count();
}
+ super_loc = function_state.super_call_location();
scope->set_start_position(start_pos);
scope->set_end_position(scanner()->location().end_pos);
@@ -2945,8 +2965,9 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
CHECK_OK);
}
- if (allow_harmony_scoping() && is_strict(language_mode()))
+ if (allow_harmony_scoping() && is_strict(language_mode())) {
this->CheckConflictingVarDeclarations(scope, CHECK_OK);
+ }
}
FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
@@ -2958,6 +2979,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
start_pos);
function_literal->set_function_token_position(start_pos);
+ if (super_loc.IsValid()) function_state_->set_super_call_location(super_loc);
if (fni_ != NULL) this->InferFunctionName(fni_, function_literal);

Powered by Google App Engine
This is Rietveld 408576698