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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 Expression* Scope::GetIllegalRedeclaration() { | 603 Expression* Scope::GetIllegalRedeclaration() { |
604 DCHECK(HasIllegalRedeclaration()); | 604 DCHECK(HasIllegalRedeclaration()); |
605 return illegal_redecl_; | 605 return illegal_redecl_; |
606 } | 606 } |
607 | 607 |
608 | 608 |
609 Declaration* Scope::CheckConflictingVarDeclarations() { | 609 Declaration* Scope::CheckConflictingVarDeclarations() { |
610 int length = decls_.length(); | 610 int length = decls_.length(); |
611 for (int i = 0; i < length; i++) { | 611 for (int i = 0; i < length; i++) { |
612 Declaration* decl = decls_[i]; | 612 Declaration* decl = decls_[i]; |
613 // We don't create a separate scope to hold the function name of a function | 613 if (decl->mode() != VAR && !is_block_scope()) continue; |
614 // expression, so we have to make sure not to consider it when checking for | |
615 // conflicts (since it's conceptually "outside" the declaration scope). | |
616 if (is_function_scope() && decl == function()) continue; | |
617 if (IsLexicalVariableMode(decl->mode()) && !is_block_scope()) continue; | |
618 const AstRawString* name = decl->proxy()->raw_name(); | 614 const AstRawString* name = decl->proxy()->raw_name(); |
619 | 615 |
620 // Iterate through all scopes until and including the declaration scope. | 616 // Iterate through all scopes until and including the declaration scope. |
621 Scope* previous = NULL; | 617 Scope* previous = NULL; |
622 Scope* current = decl->scope(); | 618 Scope* current = decl->scope(); |
623 // Lexical vs lexical conflicts within the same scope have already been | 619 // Lexical vs lexical conflicts within the same scope have already been |
624 // captured in Parser::Declare. The only conflicts we still need to check | 620 // captured in Parser::Declare. The only conflicts we still need to check |
625 // are lexical vs VAR, or any declarations within a declaration block scope | 621 // are lexical vs VAR, or any declarations within a declaration block scope |
626 // vs lexical declarations in its surrounding (function) scope. | 622 // vs lexical declarations in its surrounding (function) scope. |
627 if (IsLexicalVariableMode(decl->mode())) current = current->outer_scope_; | 623 if (decl->mode() != VAR) current = current->outer_scope_; |
628 do { | 624 do { |
629 // There is a conflict if there exists a non-VAR binding. | 625 // There is a conflict if there exists a non-VAR binding. |
630 Variable* other_var = current->variables_.Lookup(name); | 626 Variable* other_var = current->variables_.Lookup(name); |
631 if (other_var != NULL && IsLexicalVariableMode(other_var->mode())) { | 627 if (other_var != NULL && other_var->mode() != VAR) { |
632 return decl; | 628 return decl; |
633 } | 629 } |
634 previous = current; | 630 previous = current; |
635 current = current->outer_scope_; | 631 current = current->outer_scope_; |
636 } while (!previous->is_declaration_scope()); | 632 } while (!previous->is_declaration_scope()); |
637 } | 633 } |
638 return NULL; | 634 return NULL; |
639 } | 635 } |
640 | 636 |
641 | 637 |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1661 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1666 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1662 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1667 (is_function_var_in_context ? 1 : 0); | 1663 (is_function_var_in_context ? 1 : 0); |
1668 } | 1664 } |
1669 | 1665 |
1670 | 1666 |
1671 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1667 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1672 | 1668 |
1673 } // namespace internal | 1669 } // namespace internal |
1674 } // namespace v8 | 1670 } // namespace v8 |
OLD | NEW |