Index: src/deoptimizer.cc |
diff --git a/src/deoptimizer.cc b/src/deoptimizer.cc |
index 108e547f2b95e6197a6d282bb432f7d06dde5ca2..aab69c3422abb5450248ddc7cd695fa9192b2f81 100644 |
--- a/src/deoptimizer.cc |
+++ b/src/deoptimizer.cc |
@@ -264,11 +264,16 @@ void Deoptimizer::VisitAllOptimizedFunctions( |
AssertNoAllocation no_allocation; |
// Run through the list of all global contexts and deoptimize. |
- Object* global = Isolate::Current()->heap()->global_contexts_list(); |
- while (!global->IsUndefined()) { |
- VisitAllOptimizedFunctionsForGlobalObject(Context::cast(global)->global(), |
- visitor); |
- global = Context::cast(global)->get(Context::NEXT_CONTEXT_LINK); |
+ Object* context = Isolate::Current()->heap()->global_contexts_list(); |
+ while (!context->IsUndefined()) { |
+ // GC can happen when the context is not fully initialized, |
+ // so the global field of the context can be undefined. |
+ Object* global = Context::cast(context)->get(Context::GLOBAL_INDEX); |
+ if (!global->IsUndefined()) { |
+ VisitAllOptimizedFunctionsForGlobalObject(JSObject::cast(global), |
+ visitor); |
+ } |
+ context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); |
} |
} |