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/scopes.h" | 7 #include "src/scopes.h" |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 | 145 |
146 | 146 |
147 void Scope::SetDefaults(ScopeType scope_type, | 147 void Scope::SetDefaults(ScopeType scope_type, |
148 Scope* outer_scope, | 148 Scope* outer_scope, |
149 Handle<ScopeInfo> scope_info) { | 149 Handle<ScopeInfo> scope_info) { |
150 outer_scope_ = outer_scope; | 150 outer_scope_ = outer_scope; |
151 scope_type_ = scope_type; | 151 scope_type_ = scope_type; |
152 scope_name_ = ast_value_factory_->empty_string(); | 152 scope_name_ = ast_value_factory_->empty_string(); |
153 dynamics_ = NULL; | 153 dynamics_ = NULL; |
154 receiver_ = NULL; | 154 receiver_ = NULL; |
155 new_target_ = nullptr; | |
155 function_ = NULL; | 156 function_ = NULL; |
156 arguments_ = NULL; | 157 arguments_ = NULL; |
157 illegal_redecl_ = NULL; | 158 illegal_redecl_ = NULL; |
158 scope_inside_with_ = false; | 159 scope_inside_with_ = false; |
159 scope_contains_with_ = false; | 160 scope_contains_with_ = false; |
160 scope_calls_eval_ = false; | 161 scope_calls_eval_ = false; |
161 scope_uses_arguments_ = false; | 162 scope_uses_arguments_ = false; |
162 scope_uses_super_property_ = false; | 163 scope_uses_super_property_ = false; |
163 scope_uses_super_constructor_call_ = false; | 164 scope_uses_super_constructor_call_ = false; |
164 scope_uses_this_ = false; | 165 scope_uses_this_ = false; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 PrintF("global : "); | 285 PrintF("global : "); |
285 top->interface()->Print(); | 286 top->interface()->Print(); |
286 } | 287 } |
287 #endif | 288 #endif |
288 | 289 |
289 info->PrepareForCompilation(scope); | 290 info->PrepareForCompilation(scope); |
290 return true; | 291 return true; |
291 } | 292 } |
292 | 293 |
293 | 294 |
294 void Scope::Initialize(bool uninitialized_this) { | 295 void Scope::Initialize(bool subclass_constructor) { |
295 DCHECK(!already_resolved()); | 296 DCHECK(!already_resolved()); |
296 | 297 |
297 // Add this scope as a new inner scope of the outer scope. | 298 // Add this scope as a new inner scope of the outer scope. |
298 if (outer_scope_ != NULL) { | 299 if (outer_scope_ != NULL) { |
299 outer_scope_->inner_scopes_.Add(this, zone()); | 300 outer_scope_->inner_scopes_.Add(this, zone()); |
300 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); | 301 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); |
301 } else { | 302 } else { |
302 scope_inside_with_ = is_with_scope(); | 303 scope_inside_with_ = is_with_scope(); |
303 } | 304 } |
304 | 305 |
305 // Declare convenience variables. | 306 // Declare convenience variables. |
306 // Declare and allocate receiver (even for the script scope, and even | 307 // Declare and allocate receiver (even for the script scope, and even |
307 // if naccesses_ == 0). | 308 // if naccesses_ == 0). |
308 // NOTE: When loading parameters in the script scope, we must take | 309 // NOTE: When loading parameters in the script scope, we must take |
309 // care not to access them as properties of the global object, but | 310 // care not to access them as properties of the global object, but |
310 // instead load them directly from the stack. Currently, the only | 311 // instead load them directly from the stack. Currently, the only |
311 // such parameter is 'this' which is passed on the stack when | 312 // such parameter is 'this' which is passed on the stack when |
312 // invoking scripts | 313 // invoking scripts |
313 if (is_declaration_scope()) { | 314 if (is_declaration_scope()) { |
314 DCHECK(!uninitialized_this || is_function_scope()); | 315 DCHECK(!subclass_constructor || is_function_scope()); |
315 DCHECK(FLAG_experimental_classes || !uninitialized_this); | 316 DCHECK(FLAG_experimental_classes || !subclass_constructor); |
316 Variable* var = variables_.Declare( | 317 Variable* var = variables_.Declare( |
317 this, ast_value_factory_->this_string(), | 318 this, ast_value_factory_->this_string(), |
318 uninitialized_this ? CONST : VAR, false, Variable::THIS, | 319 subclass_constructor ? CONST : VAR, false, Variable::THIS, |
319 uninitialized_this ? kNeedsInitialization : kCreatedInitialized); | 320 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); |
320 var->AllocateTo(Variable::PARAMETER, -1); | 321 var->AllocateTo(Variable::PARAMETER, -1); |
321 receiver_ = var; | 322 receiver_ = var; |
323 | |
324 if (subclass_constructor) { | |
325 new_target_ = | |
326 variables_.Declare(this, ast_value_factory_->new_target_string(), VAR, | |
arv (Not doing code reviews)
2015/02/10 20:15:18
Shouldn't this be CONST?
Dmitry Lomov (no reviews)
2015/02/11 00:58:29
Done.
| |
327 false, Variable::NEW_TARGET, kCreatedInitialized); | |
328 new_target_->AllocateTo(Variable::PARAMETER, -2); | |
329 new_target_->set_is_used(); | |
330 } | |
322 } else { | 331 } else { |
323 DCHECK(outer_scope() != NULL); | 332 DCHECK(outer_scope() != NULL); |
324 receiver_ = outer_scope()->receiver(); | 333 receiver_ = outer_scope()->receiver(); |
325 } | 334 } |
326 | 335 |
327 if (is_function_scope()) { | 336 if (is_function_scope()) { |
328 // Declare 'arguments' variable which exists in all functions. | 337 // Declare 'arguments' variable which exists in all functions. |
329 // Note that it might never be accessed, in which case it won't be | 338 // Note that it might never be accessed, in which case it won't be |
330 // allocated during variable allocation. | 339 // allocated during variable allocation. |
331 variables_.Declare(this, | 340 variables_.Declare(this, |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1199 inner->asm_function_ = true; | 1208 inner->asm_function_ = true; |
1200 } | 1209 } |
1201 } | 1210 } |
1202 } | 1211 } |
1203 | 1212 |
1204 | 1213 |
1205 bool Scope::MustAllocate(Variable* var) { | 1214 bool Scope::MustAllocate(Variable* var) { |
1206 // Give var a read/write use if there is a chance it might be accessed | 1215 // Give var a read/write use if there is a chance it might be accessed |
1207 // via an eval() call. This is only possible if the variable has a | 1216 // via an eval() call. This is only possible if the variable has a |
1208 // visible name. | 1217 // visible name. |
1209 if ((var->is_this() || !var->raw_name()->IsEmpty()) && | 1218 if ((var->is_this() || var->is_new_target() || !var->raw_name()->IsEmpty()) && |
1210 (var->has_forced_context_allocation() || | 1219 (var->has_forced_context_allocation() || scope_calls_eval_ || |
1211 scope_calls_eval_ || | 1220 inner_scope_calls_eval_ || scope_contains_with_ || is_catch_scope() || |
1212 inner_scope_calls_eval_ || | 1221 is_block_scope() || is_module_scope() || is_script_scope())) { |
1213 scope_contains_with_ || | |
1214 is_catch_scope() || | |
1215 is_block_scope() || | |
1216 is_module_scope() || | |
1217 is_script_scope())) { | |
1218 var->set_is_used(); | 1222 var->set_is_used(); |
1219 if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned(); | 1223 if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned(); |
1220 } | 1224 } |
1221 // Global variables do not need to be allocated. | 1225 // Global variables do not need to be allocated. |
1222 return !var->IsGlobalObjectProperty() && var->is_used(); | 1226 return !var->IsGlobalObjectProperty() && var->is_used(); |
1223 } | 1227 } |
1224 | 1228 |
1225 | 1229 |
1226 bool Scope::MustAllocateInContext(Variable* var) { | 1230 bool Scope::MustAllocateInContext(Variable* var) { |
1227 // If var is accessed from an inner scope, or if there is a possibility | 1231 // If var is accessed from an inner scope, or if there is a possibility |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1438 } | 1442 } |
1439 | 1443 |
1440 | 1444 |
1441 int Scope::ContextLocalCount() const { | 1445 int Scope::ContextLocalCount() const { |
1442 if (num_heap_slots() == 0) return 0; | 1446 if (num_heap_slots() == 0) return 0; |
1443 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1447 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1444 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1448 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1445 } | 1449 } |
1446 | 1450 |
1447 } } // namespace v8::internal | 1451 } } // namespace v8::internal |
OLD | NEW |