| 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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 594 |
| 595 | 595 |
| 596 Declaration* Scope::CheckConflictingVarDeclarations() { | 596 Declaration* Scope::CheckConflictingVarDeclarations() { |
| 597 int length = decls_.length(); | 597 int length = decls_.length(); |
| 598 for (int i = 0; i < length; i++) { | 598 for (int i = 0; i < length; i++) { |
| 599 Declaration* decl = decls_[i]; | 599 Declaration* decl = decls_[i]; |
| 600 if (decl->mode() != VAR && !is_block_scope()) continue; | 600 if (decl->mode() != VAR && !is_block_scope()) continue; |
| 601 const AstRawString* name = decl->proxy()->raw_name(); | 601 const AstRawString* name = decl->proxy()->raw_name(); |
| 602 | 602 |
| 603 // Iterate through all scopes until and including the declaration scope. | 603 // Iterate through all scopes until and including the declaration scope. |
| 604 // If the declaration scope is a (declaration) block scope, also continue | |
| 605 // (that is to handle the special inner scope of functions with | |
| 606 // destructuring parameters, which may not shadow any variables from | |
| 607 // the surrounding function scope). | |
| 608 Scope* previous = NULL; | 604 Scope* previous = NULL; |
| 609 Scope* current = decl->scope(); | 605 Scope* current = decl->scope(); |
| 610 // Lexical vs lexical conflicts within the same scope have already been | 606 // Lexical vs lexical conflicts within the same scope have already been |
| 611 // captured in Parser::Declare. The only conflicts we still need to check | 607 // captured in Parser::Declare. The only conflicts we still need to check |
| 612 // are lexical vs VAR, or any declarations within a declaration block scope | 608 // are lexical vs VAR, or any declarations within a declaration block scope |
| 613 // vs lexical declarations in its surrounding (function) scope. | 609 // vs lexical declarations in its surrounding (function) scope. |
| 614 if (decl->mode() != VAR) current = current->outer_scope_; | 610 if (decl->mode() != VAR) current = current->outer_scope_; |
| 615 do { | 611 do { |
| 616 // There is a conflict if there exists a non-VAR binding. | 612 // There is a conflict if there exists a non-VAR binding. |
| 617 Variable* other_var = current->variables_.Lookup(name); | 613 Variable* other_var = current->variables_.Lookup(name); |
| 618 if (other_var != NULL && other_var->mode() != VAR) { | 614 if (other_var != NULL && other_var->mode() != VAR) { |
| 619 return decl; | 615 return decl; |
| 620 } | 616 } |
| 621 previous = current; | 617 previous = current; |
| 622 current = current->outer_scope_; | 618 current = current->outer_scope_; |
| 623 } while (!previous->is_declaration_scope() || previous->is_block_scope()); | 619 } while (!previous->is_declaration_scope()); |
| 624 } | 620 } |
| 625 return NULL; | 621 return NULL; |
| 626 } | 622 } |
| 627 | 623 |
| 628 | 624 |
| 629 class VarAndOrder { | 625 class VarAndOrder { |
| 630 public: | 626 public: |
| 631 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { } | 627 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { } |
| 632 Variable* var() const { return var_; } | 628 Variable* var() const { return var_; } |
| 633 int order() const { return order_; } | 629 int order() const { return order_; } |
| (...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1649 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1645 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
| 1650 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1646 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1651 (is_function_var_in_context ? 1 : 0); | 1647 (is_function_var_in_context ? 1 : 0); |
| 1652 } | 1648 } |
| 1653 | 1649 |
| 1654 | 1650 |
| 1655 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1651 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1656 | 1652 |
| 1657 } // namespace internal | 1653 } // namespace internal |
| 1658 } // namespace v8 | 1654 } // namespace v8 |
| OLD | NEW |