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

Unified Diff: src/parser.cc

Issue 1060913005: [strong] Stricter check for referring to other classes inside methods. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: . Created 5 years, 8 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/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 53aa2ee2462ba2b55f4d150df5118d3a711097cf..8c3e4d45124c48e99a6d7a822b65b7e3c8d8ad38 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1011,6 +1011,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
bool ok = true;
int beg_pos = scanner()->location().beg_pos;
+ function_state.set_consecutive_class_declaration_batch_start(beg_pos);
if (info->is_module()) {
DCHECK(allow_harmony_modules());
ParseModuleItemList(body, &ok);
@@ -1130,6 +1131,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope,
shared_info->kind(), &function_factory);
+ function_state.set_consecutive_class_declaration_batch_start(
+ scanner()->location().beg_pos);
DCHECK(is_sloppy(scope->language_mode()) ||
is_strict(info->language_mode()));
DCHECK(info->language_mode() == shared_info->language_mode());
@@ -1314,6 +1317,13 @@ Statement* Parser::ParseStatementListItem(bool* ok) {
// Statement
// Declaration
+ if (peek() != Token::CLASS) {
rossberg 2015/04/20 11:15:25 Hm, I'm not sure I fully understand the logic. You
marja 2015/04/20 15:58:22 Done + added a test for the counterexample (which
+ // No more classes follow; reset the start position for the consecutive
+ // class declaration batch.
+ function_state_->set_consecutive_class_declaration_batch_start(
+ scanner()->peek_location().beg_pos);
+ }
+
switch (peek()) {
case Token::FUNCTION:
return ParseFunctionDeclaration(NULL, ok);
@@ -1946,14 +1956,19 @@ Variable* Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
if (var == NULL) {
// Declare the name.
Variable::Kind kind = Variable::NORMAL;
+ int consecutive_declaration_batch_start = -1;
if (declaration->IsFunctionDeclaration()) {
kind = Variable::FUNCTION;
} else if (declaration->IsVariableDeclaration() &&
declaration->AsVariableDeclaration()->is_class_declaration()) {
kind = Variable::CLASS;
+ consecutive_declaration_batch_start =
+ declaration->AsVariableDeclaration()
+ ->consecutive_declaration_batch_start();
}
var = declaration_scope->DeclareLocal(
- name, mode, declaration->initialization(), kind, kNotAssigned);
+ name, mode, declaration->initialization(), kind, kNotAssigned,
+ consecutive_declaration_batch_start);
} else if (IsLexicalVariableMode(mode) ||
IsLexicalVariableMode(var->mode()) ||
((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) &&
@@ -2173,7 +2188,8 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
VariableProxy* proxy = NewUnresolved(name, mode);
const bool is_class_declaration = true;
Declaration* declaration = factory()->NewVariableDeclaration(
- proxy, mode, scope_, pos, is_class_declaration);
+ proxy, mode, scope_, pos, is_class_declaration,
+ function_state_->consecutive_class_declaration_batch_start());
Declare(declaration, true, CHECK_OK);
proxy->var()->set_initializer_position(position());
@@ -3907,6 +3923,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// '(' (Identifier)*[','] ')'
Expect(Token::LPAREN, CHECK_OK);
scope->set_start_position(scanner()->location().beg_pos);
+ function_state.set_consecutive_class_declaration_batch_start(
+ scanner()->location().beg_pos);
// We don't yet know if the function will be strict, so we cannot yet
// produce errors for parameter names or duplicates. However, we remember
@@ -4331,8 +4349,10 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
VariableProxy* proxy = NULL;
if (name != NULL) {
proxy = NewUnresolved(name, CONST);
- Declaration* declaration =
- factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos);
+ const bool is_class_declaration = true;
+ Declaration* declaration = factory()->NewVariableDeclaration(
+ proxy, CONST, block_scope, pos, is_class_declaration,
+ function_state_->consecutive_class_declaration_batch_start());
Declare(declaration, true, CHECK_OK);
}

Powered by Google App Engine
This is Rietveld 408576698