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

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

Issue 2458653002: [modules] Move MODULE variable back to Scopes, before resolution (Closed)
Patch Set: Addressed comments Created 4 years, 1 month 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 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 return decls_[j]; 1073 return decls_[j];
1074 } 1074 }
1075 } 1075 }
1076 DCHECK(false); 1076 DCHECK(false);
1077 } 1077 }
1078 } 1078 }
1079 return nullptr; 1079 return nullptr;
1080 } 1080 }
1081 1081
1082 void DeclarationScope::AllocateVariables(ParseInfo* info, AnalyzeMode mode) { 1082 void DeclarationScope::AllocateVariables(ParseInfo* info, AnalyzeMode mode) {
1083 // Module variables must be allocated before variable resolution
1084 // to ensure that AccessNeedsHoleCheck() can detect import variables.
1085 if (is_module_scope()) AsModuleScope()->AllocateModuleVariables();
1086
1083 ResolveVariablesRecursively(info); 1087 ResolveVariablesRecursively(info);
1084 AllocateVariablesRecursively(); 1088 AllocateVariablesRecursively();
1085 1089
1086 MaybeHandle<ScopeInfo> outer_scope; 1090 MaybeHandle<ScopeInfo> outer_scope;
1087 if (outer_scope_ != nullptr) outer_scope = outer_scope_->scope_info_; 1091 if (outer_scope_ != nullptr) outer_scope = outer_scope_->scope_info_;
1088 1092
1089 AllocateScopeInfosRecursively(info->isolate(), outer_scope); 1093 AllocateScopeInfosRecursively(info->isolate(), outer_scope);
1090 if (mode == AnalyzeMode::kDebugger) { 1094 if (mode == AnalyzeMode::kDebugger) {
1091 AllocateDebuggerScopeInfos(info->isolate(), outer_scope); 1095 AllocateDebuggerScopeInfos(info->isolate(), outer_scope);
1092 } 1096 }
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 1915
1912 if (new_target_ != nullptr && !MustAllocate(new_target_)) { 1916 if (new_target_ != nullptr && !MustAllocate(new_target_)) {
1913 new_target_ = nullptr; 1917 new_target_ = nullptr;
1914 } 1918 }
1915 1919
1916 if (this_function_ != nullptr && !MustAllocate(this_function_)) { 1920 if (this_function_ != nullptr && !MustAllocate(this_function_)) {
1917 this_function_ = nullptr; 1921 this_function_ = nullptr;
1918 } 1922 }
1919 } 1923 }
1920 1924
1921 void ModuleScope::AllocateModuleExports() { 1925 void ModuleScope::AllocateModuleVariables() {
1926 for (const auto& it : module()->regular_imports()) {
1927 Variable* var = LookupLocal(it.first);
1928 var->AllocateTo(VariableLocation::MODULE, Variable::kModuleImportIndex);
1929 }
1930
1922 for (const auto& it : module()->regular_exports()) { 1931 for (const auto& it : module()->regular_exports()) {
1923 Variable* var = LookupLocal(it.first); 1932 Variable* var = LookupLocal(it.first);
1924 var->AllocateTo(VariableLocation::MODULE, Variable::kModuleExportIndex); 1933 var->AllocateTo(VariableLocation::MODULE, Variable::kModuleExportIndex);
1925 } 1934 }
1926 } 1935 }
1927 1936
1928 void Scope::AllocateVariablesRecursively() { 1937 void Scope::AllocateVariablesRecursively() {
1929 DCHECK(!already_resolved_); 1938 DCHECK(!already_resolved_);
1930 DCHECK_EQ(0, num_stack_slots_); 1939 DCHECK_EQ(0, num_stack_slots_);
1931 // Don't allocate variables of preparsed scopes. 1940 // Don't allocate variables of preparsed scopes.
1932 if (is_declaration_scope() && AsDeclarationScope()->is_lazily_parsed()) { 1941 if (is_declaration_scope() && AsDeclarationScope()->is_lazily_parsed()) {
1933 return; 1942 return;
1934 } 1943 }
1935 1944
1936 // Allocate variables for inner scopes. 1945 // Allocate variables for inner scopes.
1937 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { 1946 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
1938 scope->AllocateVariablesRecursively(); 1947 scope->AllocateVariablesRecursively();
1939 } 1948 }
1940 1949
1941 DCHECK(!already_resolved_); 1950 DCHECK(!already_resolved_);
1942 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); 1951 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, num_heap_slots_);
1943 1952
1944 // Allocate variables for this scope. 1953 // Allocate variables for this scope.
1945 // Parameters must be allocated first, if any. 1954 // Parameters must be allocated first, if any.
1946 if (is_declaration_scope()) { 1955 if (is_declaration_scope()) {
1947 if (is_module_scope()) { 1956 if (is_function_scope()) {
1948 AsModuleScope()->AllocateModuleExports();
1949 } else if (is_function_scope()) {
1950 AsDeclarationScope()->AllocateParameterLocals(); 1957 AsDeclarationScope()->AllocateParameterLocals();
1951 } 1958 }
1952 AsDeclarationScope()->AllocateReceiver(); 1959 AsDeclarationScope()->AllocateReceiver();
1953 } 1960 }
1954 AllocateNonParameterLocalsAndDeclaredGlobals(); 1961 AllocateNonParameterLocalsAndDeclaredGlobals();
1955 1962
1956 // Force allocation of a context for this scope if necessary. For a 'with' 1963 // Force allocation of a context for this scope if necessary. For a 'with'
1957 // scope and for a function scope that makes an 'eval' call we need a context, 1964 // scope and for a function scope that makes an 'eval' call we need a context,
1958 // even if no local variables were statically allocated in the scope. 1965 // even if no local variables were statically allocated in the scope.
1959 // Likewise for modules. 1966 // Likewise for modules.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 Variable* function = 2025 Variable* function =
2019 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 2026 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
2020 bool is_function_var_in_context = 2027 bool is_function_var_in_context =
2021 function != nullptr && function->IsContextSlot(); 2028 function != nullptr && function->IsContextSlot();
2022 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 2029 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
2023 (is_function_var_in_context ? 1 : 0); 2030 (is_function_var_in_context ? 1 : 0);
2024 } 2031 }
2025 2032
2026 } // namespace internal 2033 } // namespace internal
2027 } // namespace v8 2034 } // 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