@@ -77,19 +77,15 @@ void StatWatcher::Initialize(Environment* env, Local<Object> target) {
7777
7878StatWatcher::StatWatcher (Environment* env, Local<Object> wrap, bool use_bigint)
7979 : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_STATWATCHER),
80- watcher_ (new uv_fs_poll_t ),
80+ watcher_ (nullptr ),
8181 use_bigint_(use_bigint) {
8282 MakeWeak ();
83- uv_fs_poll_init (env->event_loop (), watcher_);
84- watcher_->data = static_cast <void *>(this );
8583}
8684
8785
8886StatWatcher::~StatWatcher () {
89- if (IsActive ()) {
87+ if (IsActive ())
9088 Stop ();
91- }
92- env ()->CloseHandle (watcher_, [](uv_fs_poll_t * handle) { delete handle; });
9389}
9490
9591
@@ -123,7 +119,7 @@ void StatWatcher::New(const FunctionCallbackInfo<Value>& args) {
123119}
124120
125121bool StatWatcher::IsActive () {
126- return uv_is_active ( reinterpret_cast < uv_handle_t *>( watcher_)) != 0 ;
122+ return watcher_ != nullptr ;
127123}
128124
129125void StatWatcher::IsActive (const v8::FunctionCallbackInfo<v8::Value>& args) {
@@ -156,6 +152,9 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) {
156152 CHECK (args[2 ]->IsUint32 ());
157153 const uint32_t interval = args[2 ].As <Uint32>()->Value ();
158154
155+ wrap->watcher_ = new uv_fs_poll_t ();
156+ CHECK_EQ (0 , uv_fs_poll_init (wrap->env ()->event_loop (), wrap->watcher_ ));
157+ wrap->watcher_ ->data = static_cast <void *>(wrap);
159158 // Safe, uv_ref/uv_unref are idempotent.
160159 if (persistent)
161160 uv_ref (reinterpret_cast <uv_handle_t *>(wrap->watcher_ ));
@@ -187,7 +186,8 @@ void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) {
187186
188187
189188void StatWatcher::Stop () {
190- uv_fs_poll_stop (watcher_);
189+ env ()->CloseHandle (watcher_, [](uv_fs_poll_t * handle) { delete handle; });
190+ watcher_ = nullptr ;
191191 MakeWeak ();
192192}
193193
0 commit comments