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

Unified Diff: src/ast/scopes.cc

Issue 2277253003: [modules] Partial scope info support of modules (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@modules-refactor
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
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index 1aaf5c5321b46403c08fc32effe192070f407e80..2f1d4599d9f47a13bb9801dd2f380f4458151aac 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -7,6 +7,7 @@
#include <set>
#include "src/accessors.h"
+#include "src/ast/scopeinfo.h"
#include "src/bootstrapper.h"
#include "src/messages.h"
#include "src/parsing/parse-info.h"
@@ -144,6 +145,24 @@ ModuleScope::ModuleScope(DeclarationScope* script_scope,
DeclareThis(ast_value_factory);
}
+ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info,
+ AstValueFactory* avfactory)
+ : DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) {
+ Zone* zone = avfactory->zone();
+ ModuleInfo* module_info = scope_info->ModuleDescriptorInfo();
+
+ set_language_mode(STRICT);
+ module_descriptor_ = new (zone) ModuleDescriptor(zone);
+
+ // Deserialize regular exports.
+ Handle<FixedArray> regular_exports = handle(module_info->regular_exports());
+ for (int i = 0, n = regular_exports->length(); i < n; ++i) {
+ Handle<FixedArray> serialized_entry(regular_exports->get(i), isolate);
+ module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize(
+ isolate, avfactory, serialized_entry));
+ }
+}
+
Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info)
: zone_(zone),
outer_scope_(nullptr),
@@ -300,6 +319,11 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
} else {
outer_scope = new (zone) Scope(zone, BLOCK_SCOPE, scope_info);
}
+ } else if (context->IsModuleContext()) {
+ ScopeInfo* scope_info = context->closure()->shared()->scope_info();
+ DCHECK_EQ(scope_info->scope_type(), MODULE_SCOPE);
+ outer_scope = new (zone) ModuleScope(
+ isolate, Handle<ScopeInfo>(scope_info), ast_value_factory);
} else {
DCHECK(context->IsCatchContext());
String* name = context->catch_name();
@@ -427,6 +451,11 @@ void Scope::Analyze(ParseInfo* info) {
scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->already_resolved_);
+ // For modules, we want to start variable allocation on the surrounding script
+ // scope.
+ if (scope->is_module_scope())
adamk 2016/08/25 16:19:43 Please add braces if this doesn't fit on one line
neis 2016/08/26 09:52:07 Done.
+ scope = scope->outer_scope()->AsDeclarationScope();
+
scope->AllocateVariables(info);
#ifdef DEBUG
@@ -627,7 +656,8 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name) {
}
if (index < 0 && scope_type() == MODULE_SCOPE) {
location = VariableLocation::MODULE;
- index = -1; // TODO(neis): Find module variables in scope info.
+ index = ScopeInfo::ModuleIndex(scope_info_, name_handle, &mode, &init_flag,
+ &maybe_assigned_flag);
}
if (index < 0) return nullptr; // Nowhere found.
@@ -807,10 +837,12 @@ Declaration* Scope::CheckLexDeclarationsConflictingWith(
void Scope::CollectVariables(ZoneList<Variable*>* stack_locals,
ZoneList<Variable*>* context_locals,
- ZoneList<Variable*>* context_globals) {
+ ZoneList<Variable*>* context_globals,
+ ZoneList<Variable*>* module_vars) {
DCHECK(stack_locals != NULL);
DCHECK(context_locals != NULL);
DCHECK(context_globals != NULL);
+ DCHECK(module_vars != NULL || scope_type() != MODULE_SCOPE);
// Collect temporaries which are always allocated on the stack, unless the
// context as a whole has forced context allocation.
@@ -833,12 +865,14 @@ void Scope::CollectVariables(ZoneList<Variable*>* stack_locals,
for (int i = 0; i < ordered_variables_.length(); i++) {
Variable* var = ordered_variables_[i];
- if (var->IsStackLocal()) {
+ if (var->IsStackLocal()) { // XXX use switch
adamk 2016/08/25 16:19:43 Remove this comment before landing (or switch to a
neis 2016/08/26 09:52:07 Turned it into a switch (above as well).
stack_locals->Add(var, zone());
} else if (var->IsContextSlot()) {
context_locals->Add(var, zone());
} else if (var->IsGlobalSlot()) {
context_globals->Add(var, zone());
+ } else if (var->location() == VariableLocation::MODULE) {
+ module_vars->Add(var, zone());
}
}
}

Powered by Google App Engine
This is Rietveld 408576698