Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8b43388

Browse filesBrowse files
jasnelldanielleadams
authored andcommitted
src: reduce duplicated boilerplate with new env utility fn
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #36536 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 214dbac commit 8b43388
Copy full SHA for 8b43388

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

43 files changed

+95
-312
lines changed
Open diff view settings
Collapse file

‎src/README.md‎

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 numberDiff line numberDiff line change
@@ -405,11 +405,7 @@ void Initialize(Local<Object> target,
405405

406406
env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers);
407407

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);
413409
}
414410

415411
// Run the `Initialize` function when loading this module through
Collapse file

‎src/cares_wrap.cc‎

Copy file name to clipboardExpand all lines: src/cares_wrap.cc
+4-23Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,32 +2345,17 @@ void Initialize(Local<Object> target,
23452345
Local<FunctionTemplate> aiw =
23462346
BaseObject::MakeLazilyInitializedJSTemplate(env);
23472347
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);
23542349

23552350
Local<FunctionTemplate> niw =
23562351
BaseObject::MakeLazilyInitializedJSTemplate(env);
23572352
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);
23642354

23652355
Local<FunctionTemplate> qrw =
23662356
BaseObject::MakeLazilyInitializedJSTemplate(env);
23672357
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);
23742359

23752360
Local<FunctionTemplate> channel_wrap =
23762361
env->NewFunctionTemplate(ChannelWrap::New);
@@ -2397,11 +2382,7 @@ void Initialize(Local<Object> target,
23972382
env->SetProtoMethod(channel_wrap, "setLocalAddress", SetLocalAddress);
23982383
env->SetProtoMethod(channel_wrap, "cancel", Cancel);
23992384

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);
24052386
}
24062387

24072388
} // anonymous namespace
Collapse file

‎src/crypto/crypto_cipher.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_cipher.cc
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,7 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) {
265265
env->SetProtoMethodNoSideEffect(t, "getAuthTag", GetAuthTag);
266266
env->SetProtoMethod(t, "setAuthTag", SetAuthTag);
267267
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);
272269

273270
env->SetMethodNoSideEffect(target, "getSSLCiphers", GetSSLCiphers);
274271
env->SetMethodNoSideEffect(target, "getCiphers", GetCiphers);
Collapse file

‎src/crypto/crypto_context.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_context.cc
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
252252
t->InstanceTemplate()->SetInternalFieldCount(
253253
SecureContext::kInternalFieldCount);
254254
t->Inherit(BaseObject::GetConstructorTemplate(env));
255-
Local<String> secureContextString =
256-
FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext");
257-
t->SetClassName(secureContextString);
258255

259256
env->SetProtoMethod(t, "init", Init);
260257
env->SetProtoMethod(t, "setKey", SetKey);
@@ -313,8 +310,8 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
313310
Local<FunctionTemplate>(),
314311
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
315312

316-
target->Set(env->context(), secureContextString,
317-
t->GetFunction(env->context()).ToLocalChecked()).Check();
313+
env->SetConstructorFunction(target, "SecureContext", t);
314+
318315
env->set_secure_context_constructor_template(t);
319316

320317
env->SetMethodNoSideEffect(target, "getRootCertificates",
Collapse file

‎src/crypto/crypto_dh.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_dh.cc
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
9393
Local<FunctionTemplate>(),
9494
attributes);
9595

96-
target->Set(env->context(),
97-
name,
98-
t->GetFunction(env->context()).ToLocalChecked()).Check();
96+
env->SetConstructorFunction(target, name, t);
9997
};
10098

10199
make(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"), New);
Collapse file

‎src/crypto/crypto_ecdh.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_ecdh.cc
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
5252
env->SetProtoMethod(t, "setPublicKey", SetPublicKey);
5353
env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey);
5454

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);
5856

5957
env->SetMethodNoSideEffect(target, "ECDHConvertKey", ECDH::ConvertKey);
6058
env->SetMethodNoSideEffect(target, "getCurves", ECDH::GetCurves);
Collapse file

‎src/crypto/crypto_hash.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_hash.cc
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ void Hash::Initialize(Environment* env, Local<Object> target) {
5050
env->SetProtoMethod(t, "update", HashUpdate);
5151
env->SetProtoMethod(t, "digest", HashDigest);
5252

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);
5654

5755
env->SetMethodNoSideEffect(target, "getHashes", GetHashes);
5856

Collapse file

‎src/crypto/crypto_hmac.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_hmac.cc
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ void Hmac::Initialize(Environment* env, Local<Object> target) {
4848
env->SetProtoMethod(t, "update", HmacUpdate);
4949
env->SetProtoMethod(t, "digest", HmacDigest);
5050

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);
5452

5553
HmacJob::Initialize(env, target);
5654
}
Collapse file

‎src/crypto/crypto_sig.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_sig.cc
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ void Sign::Initialize(Environment* env, Local<Object> target) {
276276
env->SetProtoMethod(t, "update", SignUpdate);
277277
env->SetProtoMethod(t, "sign", SignFinal);
278278

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);
282280

283281
env->SetMethod(target, "signOneShot", Sign::SignSync);
284282

@@ -396,9 +394,7 @@ void Verify::Initialize(Environment* env, Local<Object> target) {
396394
env->SetProtoMethod(t, "update", VerifyUpdate);
397395
env->SetProtoMethod(t, "verify", VerifyFinal);
398396

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);
402398

403399
env->SetMethod(target, "verifyOneShot", Verify::VerifySync);
404400
}
Collapse file

‎src/crypto/crypto_util.h‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_util.h
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,11 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
349349
Environment* env,
350350
v8::Local<v8::Object> target) {
351351
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);
355352
job->Inherit(AsyncWrap::GetConstructorTemplate(env));
356353
job->InstanceTemplate()->SetInternalFieldCount(
357354
AsyncWrap::kInternalFieldCount);
358355
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);
363357
}
364358

365359
private:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.