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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 return 0; 1307 return 0;
1308 } 1308 }
1309 1309
1310 1310
1311 Statement* Parser::ParseStatementListItem(bool* ok) { 1311 Statement* Parser::ParseStatementListItem(bool* ok) {
1312 // (Ecma 262 6th Edition, 13.1): 1312 // (Ecma 262 6th Edition, 13.1):
1313 // StatementListItem: 1313 // StatementListItem:
1314 // Statement 1314 // Statement
1315 // Declaration 1315 // Declaration
1316 1316
1317 if (scope_->consecutive_class_declaration_group_start() >= 0 &&
rossberg 2015/04/21 13:30:02 Isn't this extra condition redundant?
marja 2015/04/23 09:52:37 Done.
1318 peek() != Token::CLASS) {
1319 // No more classes follow; reset the start position for the consecutive
1320 // class declaration group.
1321 scope_->set_consecutive_class_declaration_group_start(-1);
1322 }
1323
1317 switch (peek()) { 1324 switch (peek()) {
1318 case Token::FUNCTION: 1325 case Token::FUNCTION:
1319 return ParseFunctionDeclaration(NULL, ok); 1326 return ParseFunctionDeclaration(NULL, ok);
1320 case Token::CLASS: 1327 case Token::CLASS:
1328 if (scope_->consecutive_class_declaration_group_start() < 0) {
1329 scope_->set_consecutive_class_declaration_group_start(
1330 scanner()->peek_location().beg_pos);
1331 }
1321 return ParseClassDeclaration(NULL, ok); 1332 return ParseClassDeclaration(NULL, ok);
1322 case Token::CONST: 1333 case Token::CONST:
1323 case Token::VAR: 1334 case Token::VAR:
1324 return ParseVariableStatement(kStatementListItem, NULL, ok); 1335 return ParseVariableStatement(kStatementListItem, NULL, ok);
1325 case Token::LET: 1336 case Token::LET:
1326 if (is_strict(language_mode())) { 1337 if (is_strict(language_mode())) {
1327 return ParseVariableStatement(kStatementListItem, NULL, ok); 1338 return ParseVariableStatement(kStatementListItem, NULL, ok);
1328 } 1339 }
1329 // Fall through. 1340 // Fall through.
1330 default: 1341 default:
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 if (declaration_scope->is_function_scope() || 1948 if (declaration_scope->is_function_scope() ||
1938 declaration_scope->is_strict_eval_scope() || 1949 declaration_scope->is_strict_eval_scope() ||
1939 declaration_scope->is_block_scope() || 1950 declaration_scope->is_block_scope() ||
1940 declaration_scope->is_module_scope() || 1951 declaration_scope->is_module_scope() ||
1941 declaration_scope->is_script_scope()) { 1952 declaration_scope->is_script_scope()) {
1942 // Declare the variable in the declaration scope. 1953 // Declare the variable in the declaration scope.
1943 var = declaration_scope->LookupLocal(name); 1954 var = declaration_scope->LookupLocal(name);
1944 if (var == NULL) { 1955 if (var == NULL) {
1945 // Declare the name. 1956 // Declare the name.
1946 Variable::Kind kind = Variable::NORMAL; 1957 Variable::Kind kind = Variable::NORMAL;
1958 int consecutive_declaration_group_start = -1;
1947 if (declaration->IsFunctionDeclaration()) { 1959 if (declaration->IsFunctionDeclaration()) {
1948 kind = Variable::FUNCTION; 1960 kind = Variable::FUNCTION;
1949 } else if (declaration->IsVariableDeclaration() && 1961 } else if (declaration->IsVariableDeclaration() &&
1950 declaration->AsVariableDeclaration()->is_class_declaration()) { 1962 declaration->AsVariableDeclaration()->is_class_declaration()) {
1951 kind = Variable::CLASS; 1963 kind = Variable::CLASS;
1964 consecutive_declaration_group_start =
1965 declaration->AsVariableDeclaration()
1966 ->consecutive_declaration_group_start();
1952 } 1967 }
1953 var = declaration_scope->DeclareLocal( 1968 var = declaration_scope->DeclareLocal(
1954 name, mode, declaration->initialization(), kind, kNotAssigned); 1969 name, mode, declaration->initialization(), kind, kNotAssigned,
1970 consecutive_declaration_group_start);
1955 } else if (IsLexicalVariableMode(mode) || 1971 } else if (IsLexicalVariableMode(mode) ||
1956 IsLexicalVariableMode(var->mode()) || 1972 IsLexicalVariableMode(var->mode()) ||
1957 ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && 1973 ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) &&
1958 !declaration_scope->is_script_scope())) { 1974 !declaration_scope->is_script_scope())) {
1959 // The name was declared in this scope before; check for conflicting 1975 // The name was declared in this scope before; check for conflicting
1960 // re-declarations. We have a conflict if either of the declarations is 1976 // re-declarations. We have a conflict if either of the declarations is
1961 // not a var (in script scope, we also have to ignore legacy const for 1977 // not a var (in script scope, we also have to ignore legacy const for
1962 // compatibility). There is similar code in runtime.cc in the Declare 1978 // compatibility). There is similar code in runtime.cc in the Declare
1963 // functions. The function CheckConflictingVarDeclarations checks for 1979 // functions. The function CheckConflictingVarDeclarations checks for
1964 // var and let bindings from different scopes whereas this is a check for 1980 // var and let bindings from different scopes whereas this is a check for
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 bool is_strict_reserved = false; 2180 bool is_strict_reserved = false;
2165 const AstRawString* name = 2181 const AstRawString* name =
2166 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 2182 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
2167 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), 2183 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(),
2168 is_strict_reserved, pos, CHECK_OK); 2184 is_strict_reserved, pos, CHECK_OK);
2169 2185
2170 VariableMode mode = is_strong(language_mode()) ? CONST : LET; 2186 VariableMode mode = is_strong(language_mode()) ? CONST : LET;
2171 VariableProxy* proxy = NewUnresolved(name, mode); 2187 VariableProxy* proxy = NewUnresolved(name, mode);
2172 const bool is_class_declaration = true; 2188 const bool is_class_declaration = true;
2173 Declaration* declaration = factory()->NewVariableDeclaration( 2189 Declaration* declaration = factory()->NewVariableDeclaration(
2174 proxy, mode, scope_, pos, is_class_declaration); 2190 proxy, mode, scope_, pos, is_class_declaration,
2175 Declare(declaration, true, CHECK_OK); 2191 scope_->consecutive_class_declaration_group_start());
2192 Variable* outer_class_variable = Declare(declaration, true, CHECK_OK);
2176 proxy->var()->set_initializer_position(position()); 2193 proxy->var()->set_initializer_position(position());
2194 if (value->class_variable_proxy() && value->class_variable_proxy()->var()) {
2195 value->class_variable_proxy()
2196 ->var()
2197 ->set_corresponding_outer_class_variable(outer_class_variable);
2198 }
2177 2199
2178 Token::Value init_op = 2200 Token::Value init_op =
2179 is_strong(language_mode()) ? Token::INIT_CONST : Token::INIT_LET; 2201 is_strong(language_mode()) ? Token::INIT_CONST : Token::INIT_LET;
2180 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); 2202 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos);
2181 Statement* assignment_statement = 2203 Statement* assignment_statement =
2182 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); 2204 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
2183 if (names) names->Add(name, zone()); 2205 if (names) names->Add(name, zone());
2184 return assignment_statement; 2206 return assignment_statement;
2185 } 2207 }
2186 2208
(...skipping 2135 matching lines...) Expand 10 before | Expand all | Expand 10 after
4322 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 4344 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
4323 block_scope->tag_as_class_scope(); 4345 block_scope->tag_as_class_scope();
4324 BlockState block_state(&scope_, block_scope); 4346 BlockState block_state(&scope_, block_scope);
4325 scope_->SetLanguageMode( 4347 scope_->SetLanguageMode(
4326 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); 4348 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT));
4327 scope_->SetScopeName(name); 4349 scope_->SetScopeName(name);
4328 4350
4329 VariableProxy* proxy = NULL; 4351 VariableProxy* proxy = NULL;
4330 if (name != NULL) { 4352 if (name != NULL) {
4331 proxy = NewUnresolved(name, CONST); 4353 proxy = NewUnresolved(name, CONST);
4332 Declaration* declaration = 4354 const bool is_class_declaration = true;
4333 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); 4355 Declaration* declaration = factory()->NewVariableDeclaration(
4356 proxy, CONST, block_scope, pos, is_class_declaration,
4357 scope_->consecutive_class_declaration_group_start());
4334 Declare(declaration, true, CHECK_OK); 4358 Declare(declaration, true, CHECK_OK);
4335 } 4359 }
4336 4360
4337 Expression* extends = NULL; 4361 Expression* extends = NULL;
4338 if (Check(Token::EXTENDS)) { 4362 if (Check(Token::EXTENDS)) {
4339 block_scope->set_start_position(scanner()->location().end_pos); 4363 block_scope->set_start_position(scanner()->location().end_pos);
4340 extends = ParseLeftHandSideExpression(CHECK_OK); 4364 extends = ParseLeftHandSideExpression(CHECK_OK);
4341 } else { 4365 } else {
4342 block_scope->set_start_position(scanner()->location().end_pos); 4366 block_scope->set_start_position(scanner()->location().end_pos);
4343 } 4367 }
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after
5779 5803
5780 Expression* Parser::SpreadCallNew(Expression* function, 5804 Expression* Parser::SpreadCallNew(Expression* function,
5781 ZoneList<v8::internal::Expression*>* args, 5805 ZoneList<v8::internal::Expression*>* args,
5782 int pos) { 5806 int pos) {
5783 args->InsertAt(0, function, zone()); 5807 args->InsertAt(0, function, zone());
5784 5808
5785 return factory()->NewCallRuntime( 5809 return factory()->NewCallRuntime(
5786 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5810 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5787 } 5811 }
5788 } } // namespace v8::internal 5812 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698