GeezerVison is showing github.com — src: reduce duplicated boilerplate with new env utility fn · nodejs/node@8b43388
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/README.md +1-5Lines changed: 1 addition & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -405,11 +405,7 @@ void Initialize(Local<Object> target, | 405 | 405 |
| 406 | 406 | env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers); | 407 | 407 |
| 408 | | - Local<String> channel_wrap_string = | 409 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"); | 410 | | - channel_wrap->SetClassName(channel_wrap_string); | 411 | | - target->Set(env->context(), channel_wrap_string, | 412 | | - channel_wrap->GetFunction(context).ToLocalChecked()).Check(); | | 408 | + env->SetConstructorFunction(target, "ChannelWrap", channel_wrap); | 413 | 409 | } | 414 | 410 |
| 415 | 411 | // Run the `Initialize` function when loading this module through | |
Collapse file Copy file name to clipboardExpand all lines: src/cares_wrap.cc +4-23Lines changed: 4 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2345,32 +2345,17 @@ void Initialize(Local<Object> target, | 2345 | 2345 | Local<FunctionTemplate> aiw = | 2346 | 2346 | BaseObject::MakeLazilyInitializedJSTemplate(env); | 2347 | 2347 | aiw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 2348 | | - Local<String> addrInfoWrapString = | 2349 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap"); | 2350 | | - aiw->SetClassName(addrInfoWrapString); | 2351 | | - target->Set(env->context(), | 2352 | | - addrInfoWrapString, | 2353 | | - aiw->GetFunction(context).ToLocalChecked()).Check(); | | 2348 | + env->SetConstructorFunction(target, "GetAddrInfoReqWrap", aiw); | 2354 | 2349 |
| 2355 | 2350 | Local<FunctionTemplate> niw = | 2356 | 2351 | BaseObject::MakeLazilyInitializedJSTemplate(env); | 2357 | 2352 | niw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 2358 | | - Local<String> nameInfoWrapString = | 2359 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"); | 2360 | | - niw->SetClassName(nameInfoWrapString); | 2361 | | - target->Set(env->context(), | 2362 | | - nameInfoWrapString, | 2363 | | - niw->GetFunction(context).ToLocalChecked()).Check(); | | 2353 | + env->SetConstructorFunction(target, "GetNameInfoReqWrap", niw); | 2364 | 2354 |
| 2365 | 2355 | Local<FunctionTemplate> qrw = | 2366 | 2356 | BaseObject::MakeLazilyInitializedJSTemplate(env); | 2367 | 2357 | qrw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 2368 | | - Local<String> queryWrapString = | 2369 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"); | 2370 | | - qrw->SetClassName(queryWrapString); | 2371 | | - target->Set(env->context(), | 2372 | | - queryWrapString, | 2373 | | - qrw->GetFunction(context).ToLocalChecked()).Check(); | | 2358 | + env->SetConstructorFunction(target, "QueryReqWrap", qrw); | 2374 | 2359 |
| 2375 | 2360 | Local<FunctionTemplate> channel_wrap = | 2376 | 2361 | env->NewFunctionTemplate(ChannelWrap::New); | @@ -2397,11 +2382,7 @@ void Initialize(Local<Object> target, | 2397 | 2382 | env->SetProtoMethod(channel_wrap, "setLocalAddress", SetLocalAddress); | 2398 | 2383 | env->SetProtoMethod(channel_wrap, "cancel", Cancel); | 2399 | 2384 |
| 2400 | | - Local<String> channelWrapString = | 2401 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"); | 2402 | | - channel_wrap->SetClassName(channelWrapString); | 2403 | | - target->Set(env->context(), channelWrapString, | 2404 | | - channel_wrap->GetFunction(context).ToLocalChecked()).Check(); | | 2385 | + env->SetConstructorFunction(target, "ChannelWrap", channel_wrap); | 2405 | 2386 | } | 2406 | 2387 |
| 2407 | 2388 | } // anonymous namespace | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_cipher.cc +1-4Lines changed: 1 addition & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -265,10 +265,7 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) { | 265 | 265 | env->SetProtoMethodNoSideEffect(t, "getAuthTag", GetAuthTag); | 266 | 266 | env->SetProtoMethod(t, "setAuthTag", SetAuthTag); | 267 | 267 | env->SetProtoMethod(t, "setAAD", SetAAD); | 268 | | - | 269 | | - target->Set(env->context(), | 270 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "CipherBase"), | 271 | | - t->GetFunction(env->context()).ToLocalChecked()).Check(); | | 268 | + env->SetConstructorFunction(target, "CipherBase", t); | 272 | 269 |
| 273 | 270 | env->SetMethodNoSideEffect(target, "getSSLCiphers", GetSSLCiphers); | 274 | 271 | env->SetMethodNoSideEffect(target, "getCiphers", GetCiphers); | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_context.cc +2-5Lines changed: 2 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -252,9 +252,6 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) { | 252 | 252 | t->InstanceTemplate()->SetInternalFieldCount( | 253 | 253 | SecureContext::kInternalFieldCount); | 254 | 254 | t->Inherit(BaseObject::GetConstructorTemplate(env)); | 255 | | - Local<String> secureContextString = | 256 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"); | 257 | | - t->SetClassName(secureContextString); | 258 | 255 |
| 259 | 256 | env->SetProtoMethod(t, "init", Init); | 260 | 257 | env->SetProtoMethod(t, "setKey", SetKey); | @@ -313,8 +310,8 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) { | 313 | 310 | Local<FunctionTemplate>(), | 314 | 311 | static_cast<PropertyAttribute>(ReadOnly | DontDelete)); | 315 | 312 |
| 316 | | - target->Set(env->context(), secureContextString, | 317 | | - t->GetFunction(env->context()).ToLocalChecked()).Check(); | | 313 | + env->SetConstructorFunction(target, "SecureContext", t); | | 314 | + | 318 | 315 | env->set_secure_context_constructor_template(t); | 319 | 316 |
| 320 | 317 | env->SetMethodNoSideEffect(target, "getRootCertificates", | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_dh.cc +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,9 +93,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) { | 93 | 93 | Local<FunctionTemplate>(), | 94 | 94 | attributes); | 95 | 95 |
| 96 | | - target->Set(env->context(), | 97 | | - name, | 98 | | - t->GetFunction(env->context()).ToLocalChecked()).Check(); | | 96 | + env->SetConstructorFunction(target, name, t); | 99 | 97 | }; | 100 | 98 |
| 101 | 99 | make(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"), New); | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_ecdh.cc +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,9 +52,7 @@ void ECDH::Initialize(Environment* env, Local<Object> target) { | 52 | 52 | env->SetProtoMethod(t, "setPublicKey", SetPublicKey); | 53 | 53 | env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey); | 54 | 54 |
| 55 | | - target->Set(env->context(), | 56 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH"), | 57 | | - t->GetFunction(env->context()).ToLocalChecked()).Check(); | | 55 | + env->SetConstructorFunction(target, "ECDH", t); | 58 | 56 |
| 59 | 57 | env->SetMethodNoSideEffect(target, "ECDHConvertKey", ECDH::ConvertKey); | 60 | 58 | env->SetMethodNoSideEffect(target, "getCurves", ECDH::GetCurves); | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_hash.cc +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,9 +50,7 @@ void Hash::Initialize(Environment* env, Local<Object> target) { | 50 | 50 | env->SetProtoMethod(t, "update", HashUpdate); | 51 | 51 | env->SetProtoMethod(t, "digest", HashDigest); | 52 | 52 |
| 53 | | - target->Set(env->context(), | 54 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "Hash"), | 55 | | - t->GetFunction(env->context()).ToLocalChecked()).Check(); | | 53 | + env->SetConstructorFunction(target, "Hash", t); | 56 | 54 |
| 57 | 55 | env->SetMethodNoSideEffect(target, "getHashes", GetHashes); | 58 | 56 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_hmac.cc +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,9 +48,7 @@ void Hmac::Initialize(Environment* env, Local<Object> target) { | 48 | 48 | env->SetProtoMethod(t, "update", HmacUpdate); | 49 | 49 | env->SetProtoMethod(t, "digest", HmacDigest); | 50 | 50 |
| 51 | | - target->Set(env->context(), | 52 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "Hmac"), | 53 | | - t->GetFunction(env->context()).ToLocalChecked()).Check(); | | 51 | + env->SetConstructorFunction(target, "Hmac", t); | 54 | 52 |
| 55 | 53 | HmacJob::Initialize(env, target); | 56 | 54 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_sig.cc +2-6Lines changed: 2 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -276,9 +276,7 @@ void Sign::Initialize(Environment* env, Local<Object> target) { | 276 | 276 | env->SetProtoMethod(t, "update", SignUpdate); | 277 | 277 | env->SetProtoMethod(t, "sign", SignFinal); | 278 | 278 |
| 279 | | - target->Set(env->context(), | 280 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "Sign"), | 281 | | - t->GetFunction(env->context()).ToLocalChecked()).Check(); | | 279 | + env->SetConstructorFunction(target, "Sign", t); | 282 | 280 |
| 283 | 281 | env->SetMethod(target, "signOneShot", Sign::SignSync); | 284 | 282 |
| @@ -396,9 +394,7 @@ void Verify::Initialize(Environment* env, Local<Object> target) { | 396 | 394 | env->SetProtoMethod(t, "update", VerifyUpdate); | 397 | 395 | env->SetProtoMethod(t, "verify", VerifyFinal); | 398 | 396 |
| 399 | | - target->Set(env->context(), | 400 | | - FIXED_ONE_BYTE_STRING(env->isolate(), "Verify"), | 401 | | - t->GetFunction(env->context()).ToLocalChecked()).Check(); | | 397 | + env->SetConstructorFunction(target, "Verify", t); | 402 | 398 |
| 403 | 399 | env->SetMethod(target, "verifyOneShot", Verify::VerifySync); | 404 | 400 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_util.h +1-7Lines changed: 1 addition & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -349,17 +349,11 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork { | 349 | 349 | Environment* env, | 350 | 350 | v8::Local<v8::Object> target) { | 351 | 351 | v8::Local<v8::FunctionTemplate> job = env->NewFunctionTemplate(new_fn); | 352 | | - v8::Local<v8::String> class_name = | 353 | | - OneByteString(env->isolate(), CryptoJobTraits::JobName); | 354 | | - job->SetClassName(class_name); | 355 | 352 | job->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 356 | 353 | job->InstanceTemplate()->SetInternalFieldCount( | 357 | 354 | AsyncWrap::kInternalFieldCount); | 358 | 355 | env->SetProtoMethod(job, "run", Run); | 359 | | - target->Set( | 360 | | - env->context(), | 361 | | - class_name, | 362 | | - job->GetFunction(env->context()).ToLocalChecked()).Check(); | | 356 | + env->SetConstructorFunction(target, CryptoJobTraits::JobName, job); | 363 | 357 | } | 364 | 358 |
| 365 | 359 | private: | |
|