// static
void ObjectLifeMonitor::OnObjectGC(
const v8::WeakCallbackInfo<ObjectLifeMonitor>& 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<ObjectLifeMonitor>& data) {
+ delete data.GetParameter();
}
void ObjectLifeMonitor::RunCallback() {
v8::Context::Scope context_scope(context);
v8::Local<v8::Function>::New(isolate_, destructor_)->Call(
context->Global(), 0, nullptr);
- delete this;
}
} // namespace atom