refactor: add a wrapper for wrangling uv handles. (#25332)

* refactor: add a wrapper for wrangling uv handles.

Part 1 of a fix for #25248, #22069.

Place the uv_asyncs owned by NodeBindings, ElectronBindings inside a new
UvHandle wrapper class which manages uv_handles' need for their closed()
callback to be invoked before the handles' memory can be freed.

* chore: make lint happy

* refactor: use DCHECK_EQ() instead of DCHECK()

* refactor: fix oops
This commit is contained in:
Charles Kerr 2020-09-13 19:53:50 -05:00 committed by GitHub
parent a3389d017f
commit 70e3aa0182
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 28 deletions

View file

@ -34,14 +34,12 @@
namespace electron {
ElectronBindings::ElectronBindings(uv_loop_t* loop) {
uv_async_init(loop, &call_next_tick_async_, OnCallNextTick);
call_next_tick_async_.data = this;
uv_async_init(loop, call_next_tick_async_.get(), OnCallNextTick);
call_next_tick_async_.get()->data = this;
metrics_ = base::ProcessMetrics::CreateCurrentProcessMetrics();
}
ElectronBindings::~ElectronBindings() {
uv_close(reinterpret_cast<uv_handle_t*>(&call_next_tick_async_), nullptr);
}
ElectronBindings::~ElectronBindings() {}
// static
void ElectronBindings::BindProcess(v8::Isolate* isolate,
@ -107,7 +105,7 @@ void ElectronBindings::ActivateUVLoop(v8::Isolate* isolate) {
return;
pending_next_ticks_.push_back(env);
uv_async_send(&call_next_tick_async_);
uv_async_send(call_next_tick_async_.get());
}
// static