Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: src/ast/scopes.cc

Issue 2520883002: [parser] Fix scopes in rewriting of for-of and destructuring assignments. (Closed)
Patch Set: Remove incorrect DCHECK. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 function_ = 629 function_ =
630 new (zone()) Variable(this, name, CONST, kind, kCreatedInitialized); 630 new (zone()) Variable(this, name, CONST, kind, kCreatedInitialized);
631 if (calls_sloppy_eval()) { 631 if (calls_sloppy_eval()) {
632 NonLocal(name, DYNAMIC); 632 NonLocal(name, DYNAMIC);
633 } else { 633 } else {
634 variables_.Add(zone(), function_); 634 variables_.Add(zone(), function_);
635 } 635 }
636 return function_; 636 return function_;
637 } 637 }
638 638
639 bool Scope::HasBeenRemoved() const {
640 // TODO(neis): Store this information somewhere instead of calculating it.
641
642 if (!is_block_scope() || is_declaration_scope()) return false;
643
644 Scope* parent = outer_scope();
645 if (parent == nullptr) {
646 DCHECK(is_script_scope());
647 return false;
648 }
649
650 Scope* sibling = parent->inner_scope();
651 for (; sibling != nullptr; sibling = sibling->sibling()) {
652 if (sibling == this) return false;
653 }
654
655 DCHECK_NULL(inner_scope_);
656 return true;
657 }
658
659 Scope* Scope::GetUnremovedScope() {
660 Scope* scope = this;
661 while (scope != nullptr && scope->HasBeenRemoved()) {
662 scope = scope->outer_scope();
663 }
664 DCHECK_NOT_NULL(scope);
665 return scope;
666 }
667
639 Scope* Scope::FinalizeBlockScope() { 668 Scope* Scope::FinalizeBlockScope() {
640 DCHECK(is_block_scope()); 669 DCHECK(is_block_scope());
641 670
642 if (variables_.occupancy() > 0 || 671 if (variables_.occupancy() > 0 ||
643 (is_declaration_scope() && calls_sloppy_eval())) { 672 (is_declaration_scope() && calls_sloppy_eval())) {
644 return this; 673 return this;
645 } 674 }
646 675
647 // Remove this scope from outer scope. 676 // Remove this scope from outer scope.
648 outer_scope()->RemoveInnerScope(this); 677 outer_scope()->RemoveInnerScope(this);
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 Variable* function = 2056 Variable* function =
2028 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 2057 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
2029 bool is_function_var_in_context = 2058 bool is_function_var_in_context =
2030 function != nullptr && function->IsContextSlot(); 2059 function != nullptr && function->IsContextSlot();
2031 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 2060 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
2032 (is_function_var_in_context ? 1 : 0); 2061 (is_function_var_in_context ? 1 : 0);
2033 } 2062 }
2034 2063
2035 } // namespace internal 2064 } // namespace internal
2036 } // namespace v8 2065 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698