Index: src/compiler/pipeline.cc |
diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc |
index fbe764d8253c54cf8fa84235e684dbe18b81fd18..84305b3bb72d0720826fd7f5bf470de33b6f9391 100644 |
--- a/src/compiler/pipeline.cc |
+++ b/src/compiler/pipeline.cc |
@@ -781,6 +781,30 @@ struct GraphBuilderPhase { |
} |
}; |
+namespace { |
+ |
+Maybe<OuterContext> GetModuleContext(Handle<JSFunction> closure) { |
+ Context* current = closure->context(); |
+ size_t distance = 0; |
+ while (!current->IsNativeContext()) { |
+ if (current->IsModuleContext()) { |
+ return Just(OuterContext(handle(current), distance)); |
+ } |
+ current = current->previous(); |
+ distance++; |
+ } |
+ return Nothing<OuterContext>(); |
+} |
+ |
+Maybe<OuterContext> ChooseSpecializationContext(CompilationInfo* info) { |
+ if (info->is_function_context_specializing()) { |
+ DCHECK(info->has_context()); |
+ return Just(OuterContext(handle(info->context()), 0)); |
+ } |
+ return GetModuleContext(info->closure()); |
+} |
+ |
+} // anonymous namespace |
struct InliningPhase { |
static const char* phase_name() { return "inlining"; } |
@@ -797,9 +821,7 @@ struct InliningPhase { |
data->info()->dependencies()); |
JSContextSpecialization context_specialization( |
&graph_reducer, data->jsgraph(), |
- data->info()->is_function_context_specializing() |
- ? handle(data->info()->context()) |
- : MaybeHandle<Context>(), |
+ ChooseSpecializationContext(data->info()), |
data->info()->is_function_context_specializing() |
? data->info()->closure() |
: MaybeHandle<JSFunction>()); |