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

Unified Diff: src/ast/scopes.cc

Issue 2252223002: Introduce ModuleScope subclass of DeclarationScope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | src/globals.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index c6f7e0c15e82f926d30f761a74ba7010660e9c48..7df1a00b2966c91c4919de3bcf171fcf3bea174e 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -111,10 +111,14 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
params_(4, zone),
sloppy_block_function_map_(zone) {
SetDefaults();
- if (scope_type == MODULE_SCOPE) {
- module_descriptor_ = new (zone) ModuleDescriptor(zone);
- language_mode_ = STRICT;
- }
+}
+
+ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope,
+ AstValueFactory* ast_value_factory)
+ : DeclarationScope(zone, script_scope, MODULE_SCOPE) {
+ module_descriptor_ = new (zone) ModuleDescriptor(zone);
+ set_language_mode(STRICT);
+ DeclareThis(ast_value_factory);
}
Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
@@ -181,7 +185,6 @@ void DeclarationScope::SetDefaults() {
arity_ = 0;
rest_parameter_ = nullptr;
rest_index_ = -1;
- module_descriptor_ = nullptr;
}
void Scope::SetDefaults() {
@@ -366,6 +369,16 @@ const DeclarationScope* Scope::AsDeclarationScope() const {
return static_cast<const DeclarationScope*>(this);
}
+ModuleScope* Scope::AsModuleScope() {
+ DCHECK(is_module_scope());
+ return static_cast<ModuleScope*>(this);
+}
+
+const ModuleScope* Scope::AsModuleScope() const {
+ DCHECK(is_module_scope());
+ return static_cast<const ModuleScope*>(this);
+}
+
int Scope::num_parameters() const {
return is_declaration_scope() ? AsDeclarationScope()->num_parameters() : 0;
}
@@ -1690,7 +1703,7 @@ void DeclarationScope::AllocateLocals() {
}
}
-void DeclarationScope::AllocateModuleVariables() {
+void ModuleScope::AllocateModuleVariables() {
for (auto it = module()->regular_imports().begin();
it != module()->regular_imports().end(); ++it) {
Variable* var = LookupLocal(it->second->local_name);
@@ -1721,7 +1734,7 @@ void Scope::AllocateVariablesRecursively() {
// Parameters must be allocated first, if any.
if (is_declaration_scope()) {
if (is_module_scope()) {
- AsDeclarationScope()->AllocateModuleVariables();
+ AsModuleScope()->AllocateModuleVariables();
} else if (is_function_scope()) {
AsDeclarationScope()->AllocateParameterLocals();
}
« no previous file with comments | « src/ast/scopes.h ('k') | src/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698