Chromium Code Reviews| 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 1791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1802 // variable and also set its mode. In any case, a Declaration node | 1802 // variable and also set its mode. In any case, a Declaration node |
| 1803 // will be added to the scope so that the declaration can be added | 1803 // will be added to the scope so that the declaration can be added |
| 1804 // to the corresponding activation frame at runtime if necessary. | 1804 // to the corresponding activation frame at runtime if necessary. |
| 1805 // For instance declarations inside an eval scope need to be added | 1805 // For instance declarations inside an eval scope need to be added |
| 1806 // to the calling function context. | 1806 // to the calling function context. |
| 1807 // Similarly, strict mode eval scope does not leak variable declarations to | 1807 // Similarly, strict mode eval scope does not leak variable declarations to |
| 1808 // the caller's scope so we declare all locals, too. | 1808 // the caller's scope so we declare all locals, too. |
| 1809 if (declaration_scope->is_function_scope() || | 1809 if (declaration_scope->is_function_scope() || |
| 1810 declaration_scope->is_strict_eval_scope() || | 1810 declaration_scope->is_strict_eval_scope() || |
| 1811 declaration_scope->is_block_scope() || | 1811 declaration_scope->is_block_scope() || |
| 1812 declaration_scope->is_class_scope() || | |
| 1812 declaration_scope->is_module_scope() || | 1813 declaration_scope->is_module_scope() || |
| 1813 declaration_scope->is_script_scope()) { | 1814 declaration_scope->is_script_scope()) { |
| 1814 // Declare the variable in the declaration scope. | 1815 // Declare the variable in the declaration scope. |
| 1815 var = declaration_scope->LookupLocal(name); | 1816 var = declaration_scope->LookupLocal(name); |
| 1816 if (var == NULL) { | 1817 if (var == NULL) { |
| 1817 // Declare the name. | 1818 // Declare the name. |
| 1818 var = declaration_scope->DeclareLocal( | 1819 var = declaration_scope->DeclareLocal( |
| 1819 name, mode, declaration->initialization(), | 1820 name, mode, declaration->initialization(), |
| 1820 declaration->IsFunctionDeclaration() ? Variable::FUNCTION | 1821 declaration->IsFunctionDeclaration() ? Variable::FUNCTION |
| 1821 : Variable::NORMAL, | 1822 : Variable::NORMAL, |
| (...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4086 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | 4087 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); |
| 4087 *ok = false; | 4088 *ok = false; |
| 4088 return NULL; | 4089 return NULL; |
| 4089 } | 4090 } |
| 4090 if (IsEvalOrArguments(name)) { | 4091 if (IsEvalOrArguments(name)) { |
| 4091 ReportMessageAt(class_name_location, "strict_eval_arguments"); | 4092 ReportMessageAt(class_name_location, "strict_eval_arguments"); |
| 4092 *ok = false; | 4093 *ok = false; |
| 4093 return NULL; | 4094 return NULL; |
| 4094 } | 4095 } |
| 4095 | 4096 |
| 4096 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 4097 Scope* class_scope = NewScope(scope_, CLASS_SCOPE); |
| 4097 BlockState block_state(&scope_, block_scope); | 4098 BlockState block_state(&scope_, class_scope); |
| 4098 scope_->SetLanguageMode( | 4099 scope_->SetLanguageMode( |
| 4099 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 4100 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
| 4100 scope_->SetScopeName(name); | 4101 scope_->SetScopeName(name); |
| 4101 | 4102 |
| 4102 VariableProxy* proxy = NULL; | 4103 VariableProxy* proxy = NULL; |
| 4103 if (name != NULL) { | 4104 if (name != NULL) { |
| 4104 proxy = NewUnresolved(name, CONST); | 4105 proxy = NewUnresolved(name, CONST); |
| 4105 Declaration* declaration = | 4106 Declaration* declaration = |
| 4106 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 4107 factory()->NewVariableDeclaration(proxy, CONST, class_scope, pos); |
| 4107 Declare(declaration, true, CHECK_OK); | 4108 Declare(declaration, true, CHECK_OK); |
| 4108 } | 4109 } |
| 4109 | 4110 |
| 4110 Expression* extends = NULL; | 4111 Expression* extends = NULL; |
| 4111 if (Check(Token::EXTENDS)) { | 4112 if (Check(Token::EXTENDS)) { |
| 4112 block_scope->set_start_position(scanner()->location().end_pos); | 4113 class_scope->set_start_position(scanner()->location().end_pos); |
| 4113 extends = ParseLeftHandSideExpression(CHECK_OK); | 4114 extends = ParseLeftHandSideExpression(CHECK_OK); |
| 4114 } else { | 4115 } else { |
| 4115 block_scope->set_start_position(scanner()->location().end_pos); | 4116 class_scope->set_start_position(scanner()->location().end_pos); |
| 4116 } | 4117 } |
| 4117 | 4118 |
| 4118 | 4119 |
| 4119 ClassLiteralChecker checker(this); | 4120 ClassLiteralChecker checker(this); |
| 4120 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); | 4121 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); |
| 4121 FunctionLiteral* constructor = NULL; | 4122 FunctionLiteral* constructor = NULL; |
| 4122 bool has_seen_constructor = false; | 4123 bool has_seen_constructor = false; |
| 4123 | 4124 |
| 4124 Expect(Token::LBRACE, CHECK_OK); | 4125 Expect(Token::LBRACE, CHECK_OK); |
| 4125 | 4126 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 4146 fni_->Infer(); | 4147 fni_->Infer(); |
| 4147 fni_->Leave(); | 4148 fni_->Leave(); |
| 4148 } | 4149 } |
| 4149 } | 4150 } |
| 4150 | 4151 |
| 4151 Expect(Token::RBRACE, CHECK_OK); | 4152 Expect(Token::RBRACE, CHECK_OK); |
| 4152 int end_pos = scanner()->location().end_pos; | 4153 int end_pos = scanner()->location().end_pos; |
| 4153 | 4154 |
| 4154 if (constructor == NULL) { | 4155 if (constructor == NULL) { |
| 4155 constructor = | 4156 constructor = |
| 4156 DefaultConstructor(extends != NULL, block_scope, pos, end_pos); | 4157 DefaultConstructor(extends != NULL, class_scope, pos, end_pos); |
| 4157 } | 4158 } |
| 4158 | 4159 |
| 4159 block_scope->set_end_position(end_pos); | 4160 class_scope->set_end_position(end_pos); |
| 4160 block_scope = block_scope->FinalizeBlockScope(); | |
| 4161 | 4161 |
| 4162 if (name != NULL) { | 4162 if (name != NULL) { |
| 4163 DCHECK_NOT_NULL(proxy); | 4163 DCHECK_NOT_NULL(proxy); |
| 4164 DCHECK_NOT_NULL(block_scope); | |
| 4165 proxy->var()->set_initializer_position(end_pos); | 4164 proxy->var()->set_initializer_position(end_pos); |
| 4165 } else { | |
| 4166 // Unnamed classes should not have scopes (the class scope will be empty). | |
|
arv (Not doing code reviews)
2015/03/03 15:36:28
Unnamed classed do not need to have a scope.
marja
2015/03/03 15:52:14
Clarification: this comment was b/c some places re
| |
| 4167 DCHECK(class_scope->num_var_or_const() == 0); | |
| 4168 class_scope = nullptr; | |
| 4166 } | 4169 } |
| 4167 | 4170 |
| 4168 return factory()->NewClassLiteral(name, block_scope, proxy, extends, | 4171 return factory()->NewClassLiteral(name, class_scope, proxy, extends, |
| 4169 constructor, properties, pos, end_pos); | 4172 constructor, properties, pos, end_pos); |
| 4170 } | 4173 } |
| 4171 | 4174 |
| 4172 | 4175 |
| 4173 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 4176 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
| 4174 // CallRuntime :: | 4177 // CallRuntime :: |
| 4175 // '%' Identifier Arguments | 4178 // '%' Identifier Arguments |
| 4176 | 4179 |
| 4177 int pos = peek_position(); | 4180 int pos = peek_position(); |
| 4178 Expect(Token::MOD, CHECK_OK); | 4181 Expect(Token::MOD, CHECK_OK); |
| (...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5443 } else { | 5446 } else { |
| 5444 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5447 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
| 5445 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5448 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
| 5446 raw_string->length()); | 5449 raw_string->length()); |
| 5447 } | 5450 } |
| 5448 } | 5451 } |
| 5449 | 5452 |
| 5450 return running_hash; | 5453 return running_hash; |
| 5451 } | 5454 } |
| 5452 } } // namespace v8::internal | 5455 } } // namespace v8::internal |
| OLD | NEW |