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/scopes.h" | 5 #include "src/scopes.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/messages.h" | 9 #include "src/messages.h" |
10 #include "src/parser.h" | 10 #include "src/parser.h" |
(...skipping 359 matching lines...) Loading... |
370 DCHECK(is_block_scope()); | 370 DCHECK(is_block_scope()); |
371 DCHECK(temps_.is_empty()); | 371 DCHECK(temps_.is_empty()); |
372 DCHECK(params_.is_empty()); | 372 DCHECK(params_.is_empty()); |
373 | 373 |
374 if (num_var_or_const() > 0 || | 374 if (num_var_or_const() > 0 || |
375 (is_declaration_scope() && calls_sloppy_eval())) { | 375 (is_declaration_scope() && calls_sloppy_eval())) { |
376 return this; | 376 return this; |
377 } | 377 } |
378 | 378 |
379 // Remove this scope from outer scope. | 379 // Remove this scope from outer scope. |
380 for (int i = 0; i < outer_scope_->inner_scopes_.length(); i++) { | 380 outer_scope()->RemoveInnerScope(this); |
381 if (outer_scope_->inner_scopes_[i] == this) { | |
382 outer_scope_->inner_scopes_.Remove(i); | |
383 break; | |
384 } | |
385 } | |
386 | 381 |
387 // Reparent inner scopes. | 382 // Reparent inner scopes. |
388 for (int i = 0; i < inner_scopes_.length(); i++) { | 383 for (int i = 0; i < inner_scopes_.length(); i++) { |
389 outer_scope()->AddInnerScope(inner_scopes_[i]); | 384 outer_scope()->AddInnerScope(inner_scopes_[i]); |
390 } | 385 } |
391 | 386 |
392 // Move unresolved variables | 387 // Move unresolved variables |
393 for (int i = 0; i < unresolved_.length(); i++) { | 388 for (int i = 0; i < unresolved_.length(); i++) { |
394 outer_scope()->unresolved_.Add(unresolved_[i], zone()); | 389 outer_scope()->unresolved_.Add(unresolved_[i], zone()); |
395 } | 390 } |
396 | 391 |
397 // Propagate usage flags to outer scope. | 392 // Propagate usage flags to outer scope. |
| 393 // TODO(adamk): Why doesn't this call PropagateScopeInfo()? |
398 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); | 394 if (uses_arguments()) outer_scope_->RecordArgumentsUsage(); |
399 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); | 395 if (uses_super_property()) outer_scope_->RecordSuperPropertyUsage(); |
400 if (scope_calls_eval_) outer_scope_->RecordEvalCall(); | 396 if (scope_calls_eval_) outer_scope_->RecordEvalCall(); |
401 | 397 |
402 return NULL; | 398 return NULL; |
403 } | 399 } |
404 | 400 |
405 | 401 |
| 402 void Scope::ResetOuterScope(Scope* outer_scope) { |
| 403 DCHECK_NOT_NULL(outer_scope_); |
| 404 outer_scope_->RemoveInnerScope(this); |
| 405 outer_scope_ = outer_scope; |
| 406 outer_scope_->AddInnerScope(this); |
| 407 // TODO(adamk): Do we need to propagate usage flags here? |
| 408 } |
| 409 |
| 410 |
406 Variable* Scope::LookupLocal(const AstRawString* name) { | 411 Variable* Scope::LookupLocal(const AstRawString* name) { |
407 Variable* result = variables_.Lookup(name); | 412 Variable* result = variables_.Lookup(name); |
408 if (result != NULL || scope_info_.is_null()) { | 413 if (result != NULL || scope_info_.is_null()) { |
409 return result; | 414 return result; |
410 } | 415 } |
411 Handle<String> name_handle = name->string(); | 416 Handle<String> name_handle = name->string(); |
412 // The Scope is backed up by ScopeInfo. This means it cannot operate in a | 417 // The Scope is backed up by ScopeInfo. This means it cannot operate in a |
413 // heap-independent mode, and all strings must be internalized immediately. So | 418 // heap-independent mode, and all strings must be internalized immediately. So |
414 // it's ok to get the Handle<String> here. | 419 // it's ok to get the Handle<String> here. |
415 // If we have a serialized scope info, we might find the variable there. | 420 // If we have a serialized scope info, we might find the variable there. |
(...skipping 125 matching lines...) Loading... |
541 Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { | 546 Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { |
542 DCHECK(is_script_scope()); | 547 DCHECK(is_script_scope()); |
543 return variables_.Declare(this, | 548 return variables_.Declare(this, |
544 name, | 549 name, |
545 DYNAMIC_GLOBAL, | 550 DYNAMIC_GLOBAL, |
546 Variable::NORMAL, | 551 Variable::NORMAL, |
547 kCreatedInitialized); | 552 kCreatedInitialized); |
548 } | 553 } |
549 | 554 |
550 | 555 |
551 void Scope::RemoveUnresolved(VariableProxy* var) { | 556 bool Scope::RemoveUnresolved(VariableProxy* var) { |
552 // Most likely (always?) any variable we want to remove | 557 // Most likely (always?) any variable we want to remove |
553 // was just added before, so we search backwards. | 558 // was just added before, so we search backwards. |
554 for (int i = unresolved_.length(); i-- > 0;) { | 559 for (int i = unresolved_.length(); i-- > 0;) { |
555 if (unresolved_[i] == var) { | 560 if (unresolved_[i] == var) { |
556 unresolved_.Remove(i); | 561 unresolved_.Remove(i); |
557 return; | 562 return true; |
558 } | 563 } |
559 } | 564 } |
| 565 return false; |
560 } | 566 } |
561 | 567 |
562 | 568 |
563 Variable* Scope::NewTemporary(const AstRawString* name) { | 569 Variable* Scope::NewTemporary(const AstRawString* name) { |
564 DCHECK(!already_resolved()); | 570 DCHECK(!already_resolved()); |
565 Scope* scope = this->ClosureScope(); | 571 Scope* scope = this->ClosureScope(); |
566 Variable* var = new(zone()) Variable(scope, | 572 Variable* var = new(zone()) Variable(scope, |
567 name, | 573 name, |
568 TEMPORARY, | 574 TEMPORARY, |
569 Variable::NORMAL, | 575 Variable::NORMAL, |
(...skipping 1088 matching lines...) Loading... |
1658 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1664 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1659 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1665 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1660 (is_function_var_in_context ? 1 : 0); | 1666 (is_function_var_in_context ? 1 : 0); |
1661 } | 1667 } |
1662 | 1668 |
1663 | 1669 |
1664 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1670 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1665 | 1671 |
1666 } // namespace internal | 1672 } // namespace internal |
1667 } // namespace v8 | 1673 } // namespace v8 |
OLD | NEW |