diff --git a/atom/common/api/object_life_monitor.cc b/atom/common/api/object_life_monitor.cc index 9b7c7fe6d05f..916ad8a5177a 100644 --- a/atom/common/api/object_life_monitor.cc +++ b/atom/common/api/object_life_monitor.cc @@ -31,16 +31,16 @@ ObjectLifeMonitor::ObjectLifeMonitor(v8::Isolate* isolate, // static void ObjectLifeMonitor::OnObjectGC( const v8::WeakCallbackInfo& data) { - // Usually FirstWeakCallback should do nothing other than reset |object_| - // and then set a second weak callback to run later. We can sidestep that, - // because posting a task to the current message loop is all but free - but - // DO NOT add any more work to this method. The only acceptable place to add - // code is RunCallback. ObjectLifeMonitor* self = data.GetParameter(); self->target_.Reset(); - base::MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&ObjectLifeMonitor::RunCallback, - self->weak_ptr_factory_.GetWeakPtr())); + self->RunCallback(); + data.SetSecondPassCallback(Free); +} + +// static +void ObjectLifeMonitor::Free( + const v8::WeakCallbackInfo& data) { + delete data.GetParameter(); } void ObjectLifeMonitor::RunCallback() { @@ -50,7 +50,6 @@ void ObjectLifeMonitor::RunCallback() { v8::Context::Scope context_scope(context); v8::Local::New(isolate_, destructor_)->Call( context->Global(), 0, nullptr); - delete this; } } // namespace atom diff --git a/atom/common/api/object_life_monitor.h b/atom/common/api/object_life_monitor.h index 4c932b94c7be..82d923fcedb7 100644 --- a/atom/common/api/object_life_monitor.h +++ b/atom/common/api/object_life_monitor.h @@ -23,6 +23,7 @@ class ObjectLifeMonitor { v8::Local destructor); static void OnObjectGC(const v8::WeakCallbackInfo& data); + static void Free(const v8::WeakCallbackInfo& data); void RunCallback();