diff --git a/atom/common/api/atom_bindings.cc b/atom/common/api/atom_bindings.cc index ce19b185fb405..0dd1ceab607d0 100644 --- a/atom/common/api/atom_bindings.cc +++ b/atom/common/api/atom_bindings.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "atom/browser/browser.h" @@ -223,33 +224,34 @@ v8::Local AtomBindings::GetProcessMemoryInfo( v8::Isolate* isolate) { scoped_refptr promise = new util::Promise(isolate); - if (!Browser::Get()->is_ready()) { + if (mate::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) { promise->RejectWithErrorMessage( "Memory Info is available only after app ready"); return promise->GetHandle(); } + v8::Global context(isolate, isolate->GetCurrentContext()); memory_instrumentation::MemoryInstrumentation::GetInstance() - ->RequestGlobalDumpForPid( - base::GetCurrentProcId(), std::vector(), - base::Bind(&AtomBindings::DidReceiveMemoryDump, promise)); + ->RequestGlobalDumpForPid(base::GetCurrentProcId(), + std::vector(), + base::Bind(&AtomBindings::DidReceiveMemoryDump, + std::move(context), promise)); return promise->GetHandle(); } // static void AtomBindings::DidReceiveMemoryDump( + const v8::Global& context, scoped_refptr promise, bool success, std::unique_ptr global_dump) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - if (!isolate) - return; - + v8::Isolate* isolate = promise->isolate(); mate::Locker locker(isolate); v8::HandleScope handle_scope(isolate); v8::MicrotasksScope script_scope(isolate, v8::MicrotasksScope::kRunMicrotasks); - v8::Context::Scope context_scope(isolate->GetCurrentContext()); + v8::Context::Scope context_scope( + v8::Local::New(isolate, context)); if (!success) { promise->RejectWithErrorMessage("Failed to create memory dump"); diff --git a/atom/common/api/atom_bindings.h b/atom/common/api/atom_bindings.h index 3f15d0e37e50f..92cd9d2eb1758 100644 --- a/atom/common/api/atom_bindings.h +++ b/atom/common/api/atom_bindings.h @@ -63,6 +63,7 @@ class AtomBindings { static void OnCallNextTick(uv_async_t* handle); static void DidReceiveMemoryDump( + const v8::Global& context, scoped_refptr promise, bool success, std::unique_ptr dump);