diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 4c2a33aa84459d..9281300146c4f3 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -29,6 +29,7 @@ namespace node { using v8::Context; using v8::FunctionCallbackInfo; +using v8::FunctionTemplate; using v8::HandleScope; using v8::Local; using v8::Object; @@ -130,4 +131,13 @@ void HandleWrap::OnClose(uv_handle_t* handle) { } +void HandleWrap::AddWrapMethods(Environment* env, + Local t) { + env->SetProtoMethod(t, "close", HandleWrap::Close); + env->SetProtoMethodNoSideEffect(t, "hasRef", HandleWrap::HasRef); + env->SetProtoMethod(t, "ref", HandleWrap::Ref); + env->SetProtoMethod(t, "unref", HandleWrap::Unref); +} + + } // namespace node diff --git a/src/handle_wrap.h b/src/handle_wrap.h index bd7ef4000bad6f..443d28bf523933 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -73,6 +73,9 @@ class HandleWrap : public AsyncWrap { virtual void Close( v8::Local close_callback = v8::Local()); + static void AddWrapMethods(Environment* env, + v8::Local constructor); + protected: HandleWrap(Environment* env, v8::Local object, diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 712add06d3e2bc..24a99c8bc66358 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -718,15 +718,12 @@ MaybeLocal GetMessagePortConstructor( m->InstanceTemplate()->SetInternalFieldCount(1); AsyncWrap::AddWrapMethods(env, m); + HandleWrap::AddWrapMethods(env, m); env->SetProtoMethod(m, "postMessage", MessagePort::PostMessage); env->SetProtoMethod(m, "start", MessagePort::Start); env->SetProtoMethod(m, "stop", MessagePort::Stop); env->SetProtoMethod(m, "drain", MessagePort::Drain); - env->SetProtoMethod(m, "close", HandleWrap::Close); - env->SetProtoMethod(m, "unref", HandleWrap::Unref); - env->SetProtoMethod(m, "ref", HandleWrap::Ref); - env->SetProtoMethod(m, "hasRef", HandleWrap::HasRef); env->set_message_port_constructor_template(m); } diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index 767bc024e46be1..5e47476fd97a0c 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -52,11 +52,9 @@ void StatWatcher::Initialize(Environment* env, Local target) { t->SetClassName(statWatcherString); AsyncWrap::AddWrapMethods(env, t); + HandleWrap::AddWrapMethods(env, t); + env->SetProtoMethod(t, "start", StatWatcher::Start); - env->SetProtoMethod(t, "close", HandleWrap::Close); - env->SetProtoMethod(t, "ref", HandleWrap::Ref); - env->SetProtoMethod(t, "unref", HandleWrap::Unref); - env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); target->Set(statWatcherString, t->GetFunction()); } diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index e2cc114479d5a1..a6044b6b267e47 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -77,12 +77,7 @@ void PipeWrap::Initialize(Local target, t->InstanceTemplate()->SetInternalFieldCount(1); AsyncWrap::AddWrapMethods(env, t); - - env->SetProtoMethod(t, "close", HandleWrap::Close); - env->SetProtoMethod(t, "unref", HandleWrap::Unref); - env->SetProtoMethod(t, "ref", HandleWrap::Ref); - env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); - + HandleWrap::AddWrapMethods(env, t); LibuvStreamWrap::AddMethods(env, t); env->SetProtoMethod(t, "bind", Bind); diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 54345b231bccce..1931e8107ff67e 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -58,16 +58,11 @@ class ProcessWrap : public HandleWrap { constructor->SetClassName(processString); AsyncWrap::AddWrapMethods(env, constructor); - - env->SetProtoMethod(constructor, "close", HandleWrap::Close); + HandleWrap::AddWrapMethods(env, constructor); env->SetProtoMethod(constructor, "spawn", Spawn); env->SetProtoMethod(constructor, "kill", Kill); - env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); - env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); - env->SetProtoMethod(constructor, "hasRef", HandleWrap::HasRef); - target->Set(processString, constructor->GetFunction()); } diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index 5117d3ab1d1988..e245ad924c61fc 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -52,10 +52,8 @@ class SignalWrap : public HandleWrap { constructor->SetClassName(signalString); AsyncWrap::AddWrapMethods(env, constructor); - env->SetProtoMethod(constructor, "close", HandleWrap::Close); - env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); - env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); - env->SetProtoMethod(constructor, "hasRef", HandleWrap::HasRef); + HandleWrap::AddWrapMethods(env, constructor); + env->SetProtoMethod(constructor, "start", Start); env->SetProtoMethod(constructor, "stop", Stop); diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index aa130d22e02689..805e566bfab08b 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -86,13 +86,7 @@ void TCPWrap::Initialize(Local target, t->InstanceTemplate()->Set(env->onconnection_string(), Null(env->isolate())); AsyncWrap::AddWrapMethods(env, t, AsyncWrap::kFlagHasReset); - - env->SetProtoMethod(t, "close", HandleWrap::Close); - - env->SetProtoMethod(t, "ref", HandleWrap::Ref); - env->SetProtoMethod(t, "unref", HandleWrap::Unref); - env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); - + HandleWrap::AddWrapMethods(env, t); LibuvStreamWrap::AddMethods(env, t); env->SetProtoMethod(t, "open", Open); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index b87430dad8adc7..9da209bef48577 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -55,11 +55,7 @@ class TimerWrap : public HandleWrap { env->SetTemplateMethod(constructor, "now", Now); AsyncWrap::AddWrapMethods(env, constructor); - - env->SetProtoMethod(constructor, "close", HandleWrap::Close); - env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); - env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); - env->SetProtoMethod(constructor, "hasRef", HandleWrap::HasRef); + HandleWrap::AddWrapMethods(env, constructor); env->SetProtoMethod(constructor, "start", Start); diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 83b6e34d630e73..39d7ca1474ff8a 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -54,12 +54,7 @@ void TTYWrap::Initialize(Local target, t->InstanceTemplate()->SetInternalFieldCount(1); AsyncWrap::AddWrapMethods(env, t); - - env->SetProtoMethod(t, "close", HandleWrap::Close); - env->SetProtoMethod(t, "unref", HandleWrap::Unref); - env->SetProtoMethod(t, "ref", HandleWrap::Ref); - env->SetProtoMethodNoSideEffect(t, "hasRef", HandleWrap::HasRef); - + HandleWrap::AddWrapMethods(env, t); LibuvStreamWrap::AddMethods(env, t); env->SetProtoMethodNoSideEffect(t, "getWindowSize", TTYWrap::GetWindowSize); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 1d1ded449bd221..2ef6732213ca36 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -115,7 +115,6 @@ void UDPWrap::Initialize(Local target, env->SetProtoMethod(t, "send", Send); env->SetProtoMethod(t, "bind6", Bind6); env->SetProtoMethod(t, "send6", Send6); - env->SetProtoMethod(t, "close", Close); env->SetProtoMethod(t, "recvStart", RecvStart); env->SetProtoMethod(t, "recvStop", RecvStop); env->SetProtoMethod(t, "getsockname", @@ -129,11 +128,8 @@ void UDPWrap::Initialize(Local target, env->SetProtoMethod(t, "setTTL", SetTTL); env->SetProtoMethod(t, "bufferSize", BufferSize); - env->SetProtoMethod(t, "ref", HandleWrap::Ref); - env->SetProtoMethod(t, "unref", HandleWrap::Unref); - env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); - AsyncWrap::AddWrapMethods(env, t); + HandleWrap::AddWrapMethods(env, t); target->Set(udpString, t->GetFunction()); env->set_udp_constructor_function(t->GetFunction());