diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 4eca5cc53a490b..900b6b922df2be 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -241,37 +241,26 @@ class ContextifyContext { static void RunInDebugContext(const FunctionCallbackInfo& args) { - // Ensure that the debug context has an Environment assigned in case - // a fatal error is raised. The fatal exception handler in node.cc - // is not equipped to deal with contexts that don't have one and - // can't easily be taught that due to a deficiency in the V8 API: - // there is no way for the embedder to tell if the data index is - // in use. - struct ScopedEnvironment { - ScopedEnvironment(Local context, Environment* env) - : context_(context) { - const int index = Environment::kContextEmbedderDataIndex; - context->SetAlignedPointerInEmbedderData(index, env); - } - ~ScopedEnvironment() { - const int index = Environment::kContextEmbedderDataIndex; - context_->SetAlignedPointerInEmbedderData(index, nullptr); - } - Local context_; - }; - Local script_source(args[0]->ToString(args.GetIsolate())); if (script_source.IsEmpty()) return; // Exception pending. Local debug_context = Debug::GetDebugContext(); + Environment* env = Environment::GetCurrent(args); if (debug_context.IsEmpty()) { // Force-load the debug context. Debug::GetMirror(args.GetIsolate()->GetCurrentContext(), args[0]); debug_context = Debug::GetDebugContext(); CHECK(!debug_context.IsEmpty()); + // Ensure that the debug context has an Environment assigned in case + // a fatal error is raised. The fatal exception handler in node.cc + // is not equipped to deal with contexts that don't have one and + // can't easily be taught that due to a deficiency in the V8 API: + // there is no way for the embedder to tell if the data index is + // in use. + const int index = Environment::kContextEmbedderDataIndex; + debug_context->SetAlignedPointerInEmbedderData(index, env); } - Environment* env = Environment::GetCurrent(args); - ScopedEnvironment env_scope(debug_context, env); + Context::Scope context_scope(debug_context); Local