diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/handle_wrap.cc | 30 | ||||
-rw-r--r-- | src/handle_wrap.h | 1 | ||||
-rw-r--r-- | src/pipe_wrap.cc | 1 | ||||
-rw-r--r-- | src/tty_wrap.cc | 1 |
4 files changed, 27 insertions, 6 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 6e07643893..5b6594a3a9 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -64,8 +64,10 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) { UNWRAP - // Calling this function twice should never happen. - assert(wrap->unref == false); + // Calling unnecessarily is a no-op + if (wrap->unref) { + return v8::Undefined(); + } wrap->unref = true; uv_unref(uv_default_loop()); @@ -74,6 +76,24 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) { } +// Adds a reference to keep uv alive because of this thing. +Handle<Value> HandleWrap::Ref(const Arguments& args) { + HandleScope scope; + + UNWRAP + + // Calling multiple times is a no-op + if (!wrap->unref) { + return v8::Undefined(); + } + + wrap->unref = false; + uv_ref(uv_default_loop()); + + return v8::Undefined(); +} + + Handle<Value> HandleWrap::Close(const Arguments& args) { HandleScope scope; @@ -82,10 +102,8 @@ Handle<Value> HandleWrap::Close(const Arguments& args) { assert(!wrap->object_.IsEmpty()); uv_close(wrap->handle__, OnClose); - if (wrap->unref) { - uv_ref(uv_default_loop()); - wrap->unref = false; - } + + HandleWrap::Ref(args); wrap->StateChange(); diff --git a/src/handle_wrap.h b/src/handle_wrap.h index fc6d623ac6..b9cf31e8eb 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -49,6 +49,7 @@ class HandleWrap { static void Initialize(v8::Handle<v8::Object> target); static v8::Handle<v8::Value> Close(const v8::Arguments& args); static v8::Handle<v8::Value> Unref(const v8::Arguments& args); + static v8::Handle<v8::Value> Ref(const v8::Arguments& args); protected: HandleWrap(v8::Handle<v8::Object> object, uv_handle_t* handle); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index a2a4203a80..1870837bca 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -85,6 +85,7 @@ void PipeWrap::Initialize(Handle<Object> target) { NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close); NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref); + NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref); NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart); NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop); diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index b46e6c4e1f..486c2a70b4 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -69,6 +69,7 @@ class TTYWrap : StreamWrap { NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close); NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref); + NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref); NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart); NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop); |