| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2ff1644 commit 0c4353a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -301,22 +301,30 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel, | |||
| 301 | 301 | ||
| 302 | 302 | class InspectorTimer { | |
| 303 | 303 | public: | |
| 304 | - InspectorTimer(uv_loop_t* loop, | ||
| 304 | + InspectorTimer(Environment* env, | ||
| 305 | 305 | double interval_s, | |
| 306 | 306 | V8InspectorClient::TimerCallback callback, | |
| 307 | - void* data) : timer_(), | ||
| 307 | + void* data) : env_(env), | ||
| 308 | 308 | callback_(callback), | |
| 309 | 309 | data_(data) { | |
| 310 | - uv_timer_init(loop, &timer_); | ||
| 310 | + uv_timer_init(env->event_loop(), &timer_); | ||
| 311 | 311 | int64_t interval_ms = 1000 * interval_s; | |
| 312 | 312 | uv_timer_start(&timer_, OnTimer, interval_ms, interval_ms); | |
| 313 | + timer_.data = this; | ||
| 314 | + | ||
| 315 | + env->AddCleanupHook(CleanupHook, this); | ||
| 313 | 316 | } | |
| 314 | 317 | ||
| 315 | 318 | InspectorTimer(const InspectorTimer&) = delete; | |
| 316 | 319 | ||
| 317 | 320 | void Stop() { | |
| 318 | - uv_timer_stop(&timer_); | ||
| 319 | - uv_close(reinterpret_cast<uv_handle_t*>(&timer_), TimerClosedCb); | ||
| 321 | + env_->RemoveCleanupHook(CleanupHook, this); | ||
| 322 | + | ||
| 323 | + if (timer_.data == this) { | ||
| 324 | + timer_.data = nullptr; | ||
| 325 | + uv_timer_stop(&timer_); | ||
| 326 | + env_->CloseHandle(reinterpret_cast<uv_handle_t*>(&timer_), TimerClosedCb); | ||
| 327 | + } | ||
| 320 | 328 | } | |
| 321 | 329 | ||
| 322 | 330 | private: | |
@@ -325,6 +333,10 @@ class InspectorTimer { | |||
| 325 | 333 | timer->callback_(timer->data_); | |
| 326 | 334 | } | |
| 327 | 335 | ||
| 336 | + static void CleanupHook(void* data) { | ||
| 337 | + static_cast<InspectorTimer*>(data)->Stop(); | ||
| 338 | + } | ||
| 339 | + | ||
| 328 | 340 | static void TimerClosedCb(uv_handle_t* uvtimer) { | |
| 329 | 341 | std::unique_ptr<InspectorTimer> timer( | |
| 330 | 342 | node::ContainerOf(&InspectorTimer::timer_, | |
@@ -334,6 +346,7 @@ class InspectorTimer { | |||
| 334 | 346 | ||
| 335 | 347 | ~InspectorTimer() {} | |
| 336 | 348 | ||
| 349 | + Environment* env_; | ||
| 337 | 350 | uv_timer_t timer_; | |
| 338 | 351 | V8InspectorClient::TimerCallback callback_; | |
| 339 | 352 | void* data_; | |
@@ -343,9 +356,9 @@ class InspectorTimer { | |||
| 343 | 356 | ||
| 344 | 357 | class InspectorTimerHandle { | |
| 345 | 358 | public: | |
| 346 | - InspectorTimerHandle(uv_loop_t* loop, double interval_s, | ||
| 359 | + InspectorTimerHandle(Environment* env, double interval_s, | ||
| 347 | 360 | V8InspectorClient::TimerCallback callback, void* data) { | |
| 348 | - timer_ = new InspectorTimer(loop, interval_s, callback, data); | ||
| 361 | + timer_ = new InspectorTimer(env, interval_s, callback, data); | ||
| 349 | 362 | } | |
| 350 | 363 | ||
| 351 | 364 | InspectorTimerHandle(const InspectorTimerHandle&) = delete; | |
@@ -540,7 +553,7 @@ class NodeInspectorClient : public V8InspectorClient { | |||
| 540 | 553 | TimerCallback callback, | |
| 541 | 554 | void* data) override { | |
| 542 | 555 | timers_.emplace(std::piecewise_construct, std::make_tuple(data), | |
| 543 | - std::make_tuple(env_->event_loop(), interval_s, callback, | ||
| 556 | + std::make_tuple(env_, interval_s, callback, | ||
| 544 | 557 | data)); | |
| 545 | 558 | } | |
| 546 | 559 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments