Index: src/interpreter/bytecode-generator.cc |
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc |
index c7d333f0a534fc194c367304cbd8dafe99706248..76b97b9015b6eb4e8a55dcc2236d7e8a902368f7 100644 |
--- a/src/interpreter/bytecode-generator.cc |
+++ b/src/interpreter/bytecode-generator.cc |
@@ -674,6 +674,9 @@ void BytecodeGenerator::GenerateBytecodeBody() { |
// Visit declarations within the function scope. |
VisitDeclarations(scope()->declarations()); |
+ // Emit initializing assignments for module namespace imports (if any). |
+ VisitModuleNamespaceImports(); |
+ |
// Perform a stack-check before the body. |
builder()->StackCheck(info()->literal()->start_position()); |
@@ -873,6 +876,24 @@ void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
} |
} |
+void BytecodeGenerator::VisitModuleNamespaceImports() { |
+ if (!scope()->is_module_scope()) return; |
+ |
+ RegisterAllocationScope register_scope(this); |
+ Register module_request = register_allocator()->NewRegister(); |
+ |
+ ModuleDescriptor* descriptor = scope()->AsModuleScope()->module(); |
+ for (auto entry : descriptor->namespace_imports()) { |
+ builder() |
+ ->LoadLiteral(Smi::FromInt(entry->module_request)) |
+ .StoreAccumulatorInRegister(module_request) |
+ .CallRuntime(Runtime::kGetModuleNamespace, module_request); |
+ Variable* var = scope()->LookupLocal(entry->local_name); |
+ DCHECK_NOT_NULL(var); |
+ VisitVariableAssignment(var, Token::INIT, FeedbackVectorSlot::Invalid()); |
+ } |
+} |
+ |
void BytecodeGenerator::VisitDeclarations( |
ZoneList<Declaration*>* declarations) { |
RegisterAllocationScope register_scope(this); |