OLD | NEW |
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 Loading... |
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 (peek() != Token::CLASS) { |
| 1318 // No more classes follow; reset the start position for the consecutive |
| 1319 // class declaration group. |
| 1320 scope_->set_class_declaration_group_start(-1); |
| 1321 } |
| 1322 |
1317 switch (peek()) { | 1323 switch (peek()) { |
1318 case Token::FUNCTION: | 1324 case Token::FUNCTION: |
1319 return ParseFunctionDeclaration(NULL, ok); | 1325 return ParseFunctionDeclaration(NULL, ok); |
1320 case Token::CLASS: | 1326 case Token::CLASS: |
| 1327 if (scope_->class_declaration_group_start() < 0) { |
| 1328 scope_->set_class_declaration_group_start( |
| 1329 scanner()->peek_location().beg_pos); |
| 1330 } |
1321 return ParseClassDeclaration(NULL, ok); | 1331 return ParseClassDeclaration(NULL, ok); |
1322 case Token::CONST: | 1332 case Token::CONST: |
1323 case Token::VAR: | 1333 case Token::VAR: |
1324 return ParseVariableStatement(kStatementListItem, NULL, ok); | 1334 return ParseVariableStatement(kStatementListItem, NULL, ok); |
1325 case Token::LET: | 1335 case Token::LET: |
1326 if (is_strict(language_mode())) { | 1336 if (is_strict(language_mode())) { |
1327 return ParseVariableStatement(kStatementListItem, NULL, ok); | 1337 return ParseVariableStatement(kStatementListItem, NULL, ok); |
1328 } | 1338 } |
1329 // Fall through. | 1339 // Fall through. |
1330 default: | 1340 default: |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 if (declaration_scope->is_function_scope() || | 1947 if (declaration_scope->is_function_scope() || |
1938 declaration_scope->is_strict_eval_scope() || | 1948 declaration_scope->is_strict_eval_scope() || |
1939 declaration_scope->is_block_scope() || | 1949 declaration_scope->is_block_scope() || |
1940 declaration_scope->is_module_scope() || | 1950 declaration_scope->is_module_scope() || |
1941 declaration_scope->is_script_scope()) { | 1951 declaration_scope->is_script_scope()) { |
1942 // Declare the variable in the declaration scope. | 1952 // Declare the variable in the declaration scope. |
1943 var = declaration_scope->LookupLocal(name); | 1953 var = declaration_scope->LookupLocal(name); |
1944 if (var == NULL) { | 1954 if (var == NULL) { |
1945 // Declare the name. | 1955 // Declare the name. |
1946 Variable::Kind kind = Variable::NORMAL; | 1956 Variable::Kind kind = Variable::NORMAL; |
| 1957 int declaration_group_start = -1; |
1947 if (declaration->IsFunctionDeclaration()) { | 1958 if (declaration->IsFunctionDeclaration()) { |
1948 kind = Variable::FUNCTION; | 1959 kind = Variable::FUNCTION; |
1949 } else if (declaration->IsVariableDeclaration() && | 1960 } else if (declaration->IsVariableDeclaration() && |
1950 declaration->AsVariableDeclaration()->is_class_declaration()) { | 1961 declaration->AsVariableDeclaration()->is_class_declaration()) { |
1951 kind = Variable::CLASS; | 1962 kind = Variable::CLASS; |
| 1963 declaration_group_start = |
| 1964 declaration->AsVariableDeclaration()->declaration_group_start(); |
1952 } | 1965 } |
1953 var = declaration_scope->DeclareLocal( | 1966 var = declaration_scope->DeclareLocal( |
1954 name, mode, declaration->initialization(), kind, kNotAssigned); | 1967 name, mode, declaration->initialization(), kind, kNotAssigned, |
| 1968 declaration_group_start); |
1955 } else if (IsLexicalVariableMode(mode) || | 1969 } else if (IsLexicalVariableMode(mode) || |
1956 IsLexicalVariableMode(var->mode()) || | 1970 IsLexicalVariableMode(var->mode()) || |
1957 ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && | 1971 ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && |
1958 !declaration_scope->is_script_scope())) { | 1972 !declaration_scope->is_script_scope())) { |
1959 // The name was declared in this scope before; check for conflicting | 1973 // The name was declared in this scope before; check for conflicting |
1960 // re-declarations. We have a conflict if either of the declarations is | 1974 // 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 | 1975 // 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 | 1976 // compatibility). There is similar code in runtime.cc in the Declare |
1963 // functions. The function CheckConflictingVarDeclarations checks for | 1977 // functions. The function CheckConflictingVarDeclarations checks for |
1964 // var and let bindings from different scopes whereas this is a check for | 1978 // 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 Loading... |
2164 bool is_strict_reserved = false; | 2178 bool is_strict_reserved = false; |
2165 const AstRawString* name = | 2179 const AstRawString* name = |
2166 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 2180 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
2167 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), | 2181 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), |
2168 is_strict_reserved, pos, CHECK_OK); | 2182 is_strict_reserved, pos, CHECK_OK); |
2169 | 2183 |
2170 VariableMode mode = is_strong(language_mode()) ? CONST : LET; | 2184 VariableMode mode = is_strong(language_mode()) ? CONST : LET; |
2171 VariableProxy* proxy = NewUnresolved(name, mode); | 2185 VariableProxy* proxy = NewUnresolved(name, mode); |
2172 const bool is_class_declaration = true; | 2186 const bool is_class_declaration = true; |
2173 Declaration* declaration = factory()->NewVariableDeclaration( | 2187 Declaration* declaration = factory()->NewVariableDeclaration( |
2174 proxy, mode, scope_, pos, is_class_declaration); | 2188 proxy, mode, scope_, pos, is_class_declaration, |
2175 Declare(declaration, true, CHECK_OK); | 2189 scope_->class_declaration_group_start()); |
| 2190 Variable* outer_class_variable = Declare(declaration, true, CHECK_OK); |
2176 proxy->var()->set_initializer_position(position()); | 2191 proxy->var()->set_initializer_position(position()); |
| 2192 if (value->class_variable_proxy() && value->class_variable_proxy()->var() && |
| 2193 outer_class_variable->is_class()) { |
| 2194 // In some cases, the outer variable is not detected as a class variable; |
| 2195 // this happens e.g., for lazy methods. They are excluded from strong mode |
| 2196 // checks for now. TODO(marja, rossberg): re-create variables with the |
| 2197 // correct Kind and remove this hack. |
| 2198 value->class_variable_proxy() |
| 2199 ->var() |
| 2200 ->AsClassVariable() |
| 2201 ->set_corresponding_outer_class_variable( |
| 2202 outer_class_variable->AsClassVariable()); |
| 2203 } |
2177 | 2204 |
2178 Token::Value init_op = | 2205 Token::Value init_op = |
2179 is_strong(language_mode()) ? Token::INIT_CONST : Token::INIT_LET; | 2206 is_strong(language_mode()) ? Token::INIT_CONST : Token::INIT_LET; |
2180 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | 2207 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); |
2181 Statement* assignment_statement = | 2208 Statement* assignment_statement = |
2182 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 2209 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
2183 if (names) names->Add(name, zone()); | 2210 if (names) names->Add(name, zone()); |
2184 return assignment_statement; | 2211 return assignment_statement; |
2185 } | 2212 } |
2186 | 2213 |
(...skipping 2079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4266 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 4293 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
4267 block_scope->tag_as_class_scope(); | 4294 block_scope->tag_as_class_scope(); |
4268 BlockState block_state(&scope_, block_scope); | 4295 BlockState block_state(&scope_, block_scope); |
4269 scope_->SetLanguageMode( | 4296 scope_->SetLanguageMode( |
4270 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 4297 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
4271 scope_->SetScopeName(name); | 4298 scope_->SetScopeName(name); |
4272 | 4299 |
4273 VariableProxy* proxy = NULL; | 4300 VariableProxy* proxy = NULL; |
4274 if (name != NULL) { | 4301 if (name != NULL) { |
4275 proxy = NewUnresolved(name, CONST); | 4302 proxy = NewUnresolved(name, CONST); |
4276 Declaration* declaration = | 4303 const bool is_class_declaration = true; |
4277 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 4304 Declaration* declaration = factory()->NewVariableDeclaration( |
| 4305 proxy, CONST, block_scope, pos, is_class_declaration, |
| 4306 scope_->class_declaration_group_start()); |
4278 Declare(declaration, true, CHECK_OK); | 4307 Declare(declaration, true, CHECK_OK); |
4279 } | 4308 } |
4280 | 4309 |
4281 Expression* extends = NULL; | 4310 Expression* extends = NULL; |
4282 if (Check(Token::EXTENDS)) { | 4311 if (Check(Token::EXTENDS)) { |
4283 block_scope->set_start_position(scanner()->location().end_pos); | 4312 block_scope->set_start_position(scanner()->location().end_pos); |
4284 extends = ParseLeftHandSideExpression(CHECK_OK); | 4313 extends = ParseLeftHandSideExpression(CHECK_OK); |
4285 } else { | 4314 } else { |
4286 block_scope->set_start_position(scanner()->location().end_pos); | 4315 block_scope->set_start_position(scanner()->location().end_pos); |
4287 } | 4316 } |
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5723 | 5752 |
5724 Expression* Parser::SpreadCallNew(Expression* function, | 5753 Expression* Parser::SpreadCallNew(Expression* function, |
5725 ZoneList<v8::internal::Expression*>* args, | 5754 ZoneList<v8::internal::Expression*>* args, |
5726 int pos) { | 5755 int pos) { |
5727 args->InsertAt(0, function, zone()); | 5756 args->InsertAt(0, function, zone()); |
5728 | 5757 |
5729 return factory()->NewCallRuntime( | 5758 return factory()->NewCallRuntime( |
5730 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5759 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5731 } | 5760 } |
5732 } } // namespace v8::internal | 5761 } } // namespace v8::internal |
OLD | NEW |