diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-09-23 20:24:33 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-10-03 23:43:42 +0300 |
commit | d527dde3600655eae7ce0ba5da9263ec4560cd11 (patch) | |
tree | cb9186b8b85a696ec7f916f40fcec935ba86fdc9 /src/handle_wrap.cc | |
parent | 2ebdba12297348649620e3d302b156c149d85a6e (diff) |
src: use JS inheritance for `AsyncWrap`
For all classes descending from `AsyncWrap`, use JS inheritance
instead of manually adding methods to the individual classes.
This allows cleanup of some code around transferring handles
over IPC.
PR-URL: https://github.com/nodejs/node/pull/23094
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/handle_wrap.cc')
-rw-r--r-- | src/handle_wrap.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 9281300146c..d4c5962c35e 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -130,13 +130,19 @@ void HandleWrap::OnClose(uv_handle_t* handle) { } } - -void HandleWrap::AddWrapMethods(Environment* env, - Local<FunctionTemplate> 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); +Local<FunctionTemplate> HandleWrap::GetConstructorTemplate(Environment* env) { + Local<FunctionTemplate> tmpl = env->handle_wrap_ctor_template(); + if (tmpl.IsEmpty()) { + tmpl = env->NewFunctionTemplate(nullptr); + tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "HandleWrap")); + tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env)); + env->SetProtoMethod(tmpl, "close", HandleWrap::Close); + env->SetProtoMethodNoSideEffect(tmpl, "hasRef", HandleWrap::HasRef); + env->SetProtoMethod(tmpl, "ref", HandleWrap::Ref); + env->SetProtoMethod(tmpl, "unref", HandleWrap::Unref); + env->set_handle_wrap_ctor_template(tmpl); + } + return tmpl; } |