diff options
author | James M Snell <jasnell@gmail.com> | 2020-12-15 22:52:17 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-01-03 23:58:09 +0300 |
commit | 28fe1ef63512acd40cfd1dd15918db494c92f45f (patch) | |
tree | fb65e10e0c966e2484a3f2151870738499d575b7 /src/cares_wrap.cc | |
parent | 7cfa1bee418696c1c97c1f2466520ab4f4cc8791 (diff) |
src: reduce duplicated boilerplate with new env utility fn
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/36536
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/cares_wrap.cc')
-rw-r--r-- | src/cares_wrap.cc | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 71766fa3917..2bf4211b118 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -2345,32 +2345,17 @@ void Initialize(Local<Object> target, Local<FunctionTemplate> aiw = BaseObject::MakeLazilyInitializedJSTemplate(env); aiw->Inherit(AsyncWrap::GetConstructorTemplate(env)); - Local<String> addrInfoWrapString = - FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap"); - aiw->SetClassName(addrInfoWrapString); - target->Set(env->context(), - addrInfoWrapString, - aiw->GetFunction(context).ToLocalChecked()).Check(); + env->SetConstructorFunction(target, "GetAddrInfoReqWrap", aiw); Local<FunctionTemplate> niw = BaseObject::MakeLazilyInitializedJSTemplate(env); niw->Inherit(AsyncWrap::GetConstructorTemplate(env)); - Local<String> nameInfoWrapString = - FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"); - niw->SetClassName(nameInfoWrapString); - target->Set(env->context(), - nameInfoWrapString, - niw->GetFunction(context).ToLocalChecked()).Check(); + env->SetConstructorFunction(target, "GetNameInfoReqWrap", niw); Local<FunctionTemplate> qrw = BaseObject::MakeLazilyInitializedJSTemplate(env); qrw->Inherit(AsyncWrap::GetConstructorTemplate(env)); - Local<String> queryWrapString = - FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"); - qrw->SetClassName(queryWrapString); - target->Set(env->context(), - queryWrapString, - qrw->GetFunction(context).ToLocalChecked()).Check(); + env->SetConstructorFunction(target, "QueryReqWrap", qrw); Local<FunctionTemplate> channel_wrap = env->NewFunctionTemplate(ChannelWrap::New); @@ -2397,11 +2382,7 @@ void Initialize(Local<Object> target, env->SetProtoMethod(channel_wrap, "setLocalAddress", SetLocalAddress); env->SetProtoMethod(channel_wrap, "cancel", Cancel); - Local<String> channelWrapString = - FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"); - channel_wrap->SetClassName(channelWrapString); - target->Set(env->context(), channelWrapString, - channel_wrap->GetFunction(context).ToLocalChecked()).Check(); + env->SetConstructorFunction(target, "ChannelWrap", channel_wrap); } } // anonymous namespace |