Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Nov 28, 2018
1 parent 0c85253 commit ecad1ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions atom/common/api/atom_bindings.cc
Expand Up @@ -223,33 +223,34 @@ v8::Local<v8::Promise> AtomBindings::GetProcessMemoryInfo(
v8::Isolate* isolate) {
scoped_refptr<util::Promise> 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<v8::Context> context(isolate, isolate->GetCurrentContext());
memory_instrumentation::MemoryInstrumentation::GetInstance()
->RequestGlobalDumpForPid(
base::GetCurrentProcId(), std::vector<std::string>(),
base::Bind(&AtomBindings::DidReceiveMemoryDump, promise));
->RequestGlobalDumpForPid(base::GetCurrentProcId(),
std::vector<std::string>(),
base::Bind(&AtomBindings::DidReceiveMemoryDump,
std::move(context), promise));
return promise->GetHandle();
}

// static
void AtomBindings::DidReceiveMemoryDump(
const v8::Global<v8::Context>& context,
scoped_refptr<util::Promise> promise,
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> 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<v8::Context>::New(isolate, context));

if (!success) {
promise->RejectWithErrorMessage("Failed to create memory dump");
Expand Down
1 change: 1 addition & 0 deletions atom/common/api/atom_bindings.h
Expand Up @@ -63,6 +63,7 @@ class AtomBindings {
static void OnCallNextTick(uv_async_t* handle);

static void DidReceiveMemoryDump(
const v8::Global<v8::Context>& context,
scoped_refptr<util::Promise> promise,
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);
Expand Down

0 comments on commit ecad1ad

Please sign in to comment.