diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index a3c0e42375a9e1..13ebffdc04935a 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -525,7 +525,7 @@ class NodeInspectorClient : public V8InspectorClient { void* data) override { auto result = timers_.emplace(std::piecewise_construct, std::make_tuple(data), - std::make_tuple(env_, callback, data)); + std::make_tuple(env_, [=]() { callback(data); })); CHECK(result.second); uint64_t interval = 1000 * interval_s; result.first->second.Update(interval, interval); diff --git a/src/quic/node_quic_session.cc b/src/quic/node_quic_session.cc index b47321e222e9c1..81f204330d14c4 100644 --- a/src/quic/node_quic_session.cc +++ b/src/quic/node_quic_session.cc @@ -1431,8 +1431,8 @@ QuicSession::QuicSession( socket_(socket), alpn_(alpn), hostname_(hostname), - idle_(socket->env(), [this](void* data) { OnIdleTimeout(); }), - retransmit_(socket->env(), [this](void* data) { MaybeTimeout(); }), + idle_(socket->env(), [this]() { OnIdleTimeout(); }), + retransmit_(socket->env(), [this]() { MaybeTimeout(); }), dcid_(dcid), state_(env()->isolate()), quic_state_(socket->quic_state()) { diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 618c50c82e2cbd..919b629348c2bf 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -5,10 +5,9 @@ namespace node { -TimerWrap::TimerWrap(Environment* env, TimerCb fn, void* user_data) +TimerWrap::TimerWrap(Environment* env, const TimerCb& fn) : env_(env), - fn_(fn), - user_data_(user_data) { + fn_(fn) { uv_timer_init(env->event_loop(), &timer_); timer_.data = this; } @@ -45,14 +44,13 @@ void TimerWrap::Unref() { void TimerWrap::OnTimeout(uv_timer_t* timer) { TimerWrap* t = ContainerOf(&TimerWrap::timer_, timer); - t->fn_(t->user_data_); + t->fn_(); } TimerWrapHandle::TimerWrapHandle( Environment* env, - TimerWrap::TimerCb fn, - void* user_data) { - timer_ = new TimerWrap(env, fn, user_data); + const TimerWrap::TimerCb& fn) { + timer_ = new TimerWrap(env, fn); env->AddCleanupHook(CleanupHook, this); } diff --git a/src/timer_wrap.h b/src/timer_wrap.h index c75e17b776beef..263562f2a135bd 100644 --- a/src/timer_wrap.h +++ b/src/timer_wrap.h @@ -14,9 +14,9 @@ namespace node { // Utility class that makes working with libuv timers a bit easier. class TimerWrap final : public MemoryRetainer { public: - using TimerCb = std::function; + using TimerCb = std::function; - TimerWrap(Environment* env, TimerCb fn, void* user_data); + TimerWrap(Environment* env, const TimerCb& fn); TimerWrap(const TimerWrap&) = delete; inline Environment* env() const { return env_; } @@ -43,7 +43,6 @@ class TimerWrap final : public MemoryRetainer { Environment* env_; TimerCb fn_; uv_timer_t timer_; - void* user_data_ = nullptr; friend std::unique_ptr::deleter_type; }; @@ -52,8 +51,7 @@ class TimerWrapHandle : public MemoryRetainer { public: TimerWrapHandle( Environment* env, - TimerWrap::TimerCb fn, - void* user_data = nullptr); + const TimerWrap::TimerCb& fn); TimerWrapHandle(const TimerWrapHandle&) = delete;