Index: src/compiler/pipeline.cc |
diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc |
index 585923fa69d36c63e016846be502018fea6b65be..f274d00afbf6a58de3eda9aef47a5bc9e8fee541 100644 |
--- a/src/compiler/pipeline.cc |
+++ b/src/compiler/pipeline.cc |
@@ -781,6 +781,31 @@ struct GraphBuilderPhase { |
} |
}; |
+namespace { |
+ |
+Maybe<OuterContext> GetModuleContext(Handle<JSFunction> closure) { |
+ Context* current = closure->context(); |
+ size_t distance = 0; |
+ while (current != nullptr && !current->IsNativeContext() && |
+ !current->IsModuleContext()) { |
+ current = current->previous(); |
+ distance++; |
+ } |
+ if (current != nullptr && current->IsModuleContext()) { |
Michael Starzinger
2017/05/03 17:28:16
question: Can we ever hit the {nullptr} case here?
neis
2017/05/04 10:36:21
As discussed, I removed this condition.
|
+ return Just(OuterContext(handle(current), 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 +822,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>()); |