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/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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 scope->CheckScopePositions(); | 593 scope->CheckScopePositions(); |
594 scope->CheckZones(); | 594 scope->CheckZones(); |
595 #endif | 595 #endif |
596 } | 596 } |
597 | 597 |
598 void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { | 598 void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { |
599 DCHECK(!already_resolved_); | 599 DCHECK(!already_resolved_); |
600 DCHECK(is_declaration_scope()); | 600 DCHECK(is_declaration_scope()); |
601 DCHECK(has_this_declaration()); | 601 DCHECK(has_this_declaration()); |
602 | 602 |
603 bool subclass_constructor = IsSubclassConstructor(function_kind_); | 603 bool derived_constructor = IsDerivedConstructor(function_kind_); |
604 Variable* var = Declare( | 604 Variable* var = |
605 zone(), ast_value_factory->this_string(), | 605 Declare(zone(), ast_value_factory->this_string(), |
606 subclass_constructor ? CONST : VAR, THIS_VARIABLE, | 606 derived_constructor ? CONST : VAR, THIS_VARIABLE, |
607 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); | 607 derived_constructor ? kNeedsInitialization : kCreatedInitialized); |
608 receiver_ = var; | 608 receiver_ = var; |
609 } | 609 } |
610 | 610 |
611 void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) { | 611 void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) { |
612 DCHECK(is_function_scope()); | 612 DCHECK(is_function_scope()); |
613 DCHECK(!is_arrow_scope()); | 613 DCHECK(!is_arrow_scope()); |
614 | 614 |
615 arguments_ = LookupLocal(ast_value_factory->arguments_string()); | 615 arguments_ = LookupLocal(ast_value_factory->arguments_string()); |
616 if (arguments_ == nullptr) { | 616 if (arguments_ == nullptr) { |
617 // Declare 'arguments' variable which exists in all non arrow functions. | 617 // Declare 'arguments' variable which exists in all non arrow functions. |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 // The check cannot be skipped on non-linear scopes, namely switch | 1735 // The check cannot be skipped on non-linear scopes, namely switch |
1736 // scopes, to ensure tests are done in cases like the following: | 1736 // scopes, to ensure tests are done in cases like the following: |
1737 // switch (1) { case 0: let x = 2; case 1: f(x); } | 1737 // switch (1) { case 0: let x = 2; case 1: f(x); } |
1738 // The scope of the variable needs to be checked, in case the use is | 1738 // The scope of the variable needs to be checked, in case the use is |
1739 // in a sub-block which may be linear. | 1739 // in a sub-block which may be linear. |
1740 if (var->scope()->GetDeclarationScope() != scope->GetDeclarationScope()) { | 1740 if (var->scope()->GetDeclarationScope() != scope->GetDeclarationScope()) { |
1741 return true; | 1741 return true; |
1742 } | 1742 } |
1743 | 1743 |
1744 if (var->is_this()) { | 1744 if (var->is_this()) { |
1745 DCHECK( | 1745 DCHECK(IsDerivedConstructor(scope->GetDeclarationScope()->function_kind())); |
1746 IsSubclassConstructor(scope->GetDeclarationScope()->function_kind())); | |
1747 // TODO(littledan): implement 'this' hole check elimination. | 1746 // TODO(littledan): implement 'this' hole check elimination. |
1748 return true; | 1747 return true; |
1749 } | 1748 } |
1750 | 1749 |
1751 // We should always have valid source positions. | 1750 // We should always have valid source positions. |
1752 DCHECK(var->initializer_position() != kNoSourcePosition); | 1751 DCHECK(var->initializer_position() != kNoSourcePosition); |
1753 DCHECK(proxy->position() != kNoSourcePosition); | 1752 DCHECK(proxy->position() != kNoSourcePosition); |
1754 | 1753 |
1755 return var->scope()->is_nonlinear() || | 1754 return var->scope()->is_nonlinear() || |
1756 var->initializer_position() >= proxy->position(); | 1755 var->initializer_position() >= proxy->position(); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2122 Variable* function = | 2121 Variable* function = |
2123 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2122 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
2124 bool is_function_var_in_context = | 2123 bool is_function_var_in_context = |
2125 function != nullptr && function->IsContextSlot(); | 2124 function != nullptr && function->IsContextSlot(); |
2126 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2125 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
2127 (is_function_var_in_context ? 1 : 0); | 2126 (is_function_var_in_context ? 1 : 0); |
2128 } | 2127 } |
2129 | 2128 |
2130 } // namespace internal | 2129 } // namespace internal |
2131 } // namespace v8 | 2130 } // namespace v8 |
OLD | NEW |