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 4082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4093 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | 4093 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); |
4094 *ok = false; | 4094 *ok = false; |
4095 return NULL; | 4095 return NULL; |
4096 } | 4096 } |
4097 if (IsEvalOrArguments(name)) { | 4097 if (IsEvalOrArguments(name)) { |
4098 ReportMessageAt(class_name_location, "strict_eval_arguments"); | 4098 ReportMessageAt(class_name_location, "strict_eval_arguments"); |
4099 *ok = false; | 4099 *ok = false; |
4100 return NULL; | 4100 return NULL; |
4101 } | 4101 } |
4102 | 4102 |
| 4103 // Create a block scope which is additionally tagged as class scope; this is |
| 4104 // important for resolving variable references to the class name in the strong |
| 4105 // mode. |
4103 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 4106 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
| 4107 block_scope->tag_as_class_scope(); |
4104 BlockState block_state(&scope_, block_scope); | 4108 BlockState block_state(&scope_, block_scope); |
4105 scope_->SetLanguageMode( | 4109 scope_->SetLanguageMode( |
4106 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 4110 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
4107 scope_->SetScopeName(name); | 4111 scope_->SetScopeName(name); |
4108 | 4112 |
4109 VariableProxy* proxy = NULL; | 4113 VariableProxy* proxy = NULL; |
4110 if (name != NULL) { | 4114 if (name != NULL) { |
4111 proxy = NewUnresolved(name, CONST); | 4115 proxy = NewUnresolved(name, CONST); |
4112 Declaration* declaration = | 4116 Declaration* declaration = |
4113 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 4117 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4157 | 4161 |
4158 Expect(Token::RBRACE, CHECK_OK); | 4162 Expect(Token::RBRACE, CHECK_OK); |
4159 int end_pos = scanner()->location().end_pos; | 4163 int end_pos = scanner()->location().end_pos; |
4160 | 4164 |
4161 if (constructor == NULL) { | 4165 if (constructor == NULL) { |
4162 constructor = | 4166 constructor = |
4163 DefaultConstructor(extends != NULL, block_scope, pos, end_pos); | 4167 DefaultConstructor(extends != NULL, block_scope, pos, end_pos); |
4164 } | 4168 } |
4165 | 4169 |
4166 block_scope->set_end_position(end_pos); | 4170 block_scope->set_end_position(end_pos); |
4167 block_scope = block_scope->FinalizeBlockScope(); | |
4168 | 4171 |
4169 if (name != NULL) { | 4172 if (name != NULL) { |
4170 DCHECK_NOT_NULL(proxy); | 4173 DCHECK_NOT_NULL(proxy); |
4171 DCHECK_NOT_NULL(block_scope); | |
4172 proxy->var()->set_initializer_position(end_pos); | 4174 proxy->var()->set_initializer_position(end_pos); |
| 4175 } else { |
| 4176 // Unnamed classes should not have scopes (the scope will be empty). |
| 4177 DCHECK_EQ(block_scope->num_var_or_const(), 0); |
| 4178 block_scope = nullptr; |
4173 } | 4179 } |
4174 | 4180 |
4175 return factory()->NewClassLiteral(name, block_scope, proxy, extends, | 4181 return factory()->NewClassLiteral(name, block_scope, proxy, extends, |
4176 constructor, properties, pos, end_pos); | 4182 constructor, properties, pos, end_pos); |
4177 } | 4183 } |
4178 | 4184 |
4179 | 4185 |
4180 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 4186 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
4181 // CallRuntime :: | 4187 // CallRuntime :: |
4182 // '%' Identifier Arguments | 4188 // '%' Identifier Arguments |
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5450 } else { | 5456 } else { |
5451 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5457 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5452 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5458 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5453 raw_string->length()); | 5459 raw_string->length()); |
5454 } | 5460 } |
5455 } | 5461 } |
5456 | 5462 |
5457 return running_hash; | 5463 return running_hash; |
5458 } | 5464 } |
5459 } } // namespace v8::internal | 5465 } } // namespace v8::internal |
OLD | NEW |