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 cf48db0

Browse filesBrowse files
tniessentargos
authored andcommitted
src: use v8::Boolean(b) over b ? True() : False()
Simplify existing code by using v8::Boolean::New() instead of equivalent expressions that contain ternary operators. PR-URL: #47554 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent ba255ed commit cf48db0
Copy full SHA for cf48db0

File tree

Expand file treeCollapse file tree

8 files changed

+25
-33
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+25
-33
lines changed
Open diff view settings
Collapse file

‎src/api/environment.cc‎

Copy file name to clipboardExpand all lines: src/api/environment.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
namespace node {
2424
using errors::TryCatchScope;
2525
using v8::Array;
26+
using v8::Boolean;
2627
using v8::Context;
2728
using v8::EscapableHandleScope;
2829
using v8::Function;
@@ -667,7 +668,7 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
667668
context->AllowCodeGenerationFromStrings(false);
668669
context->SetEmbedderData(
669670
ContextEmbedderIndex::kAllowCodeGenerationFromStrings,
670-
is_code_generation_from_strings_allowed ? True(isolate) : False(isolate));
671+
Boolean::New(isolate, is_code_generation_from_strings_allowed));
671672

672673
if (per_process::cli_options->disable_proto == "") {
673674
return Just(true);
Collapse file

‎src/crypto/crypto_context.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_context.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace node {
2222

2323
using v8::Array;
2424
using v8::ArrayBufferView;
25+
using v8::Boolean;
2526
using v8::Context;
2627
using v8::DontDelete;
2728
using v8::Exception;
@@ -1191,7 +1192,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
11911192
return -1;
11921193
}
11931194

1194-
argv[2] = enc != 0 ? v8::True(env->isolate()) : v8::False(env->isolate());
1195+
argv[2] = Boolean::New(env->isolate(), enc != 0);
11951196

11961197
Local<Value> ret;
11971198
if (!node::MakeCallback(
Collapse file

‎src/crypto/crypto_hmac.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_hmac.cc
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace node {
1515

16+
using v8::Boolean;
1617
using v8::FunctionCallbackInfo;
1718
using v8::FunctionTemplate;
1819
using v8::HandleScope;
@@ -264,11 +265,10 @@ Maybe<bool> HmacTraits::EncodeOutput(
264265
*result = out->ToArrayBuffer(env);
265266
break;
266267
case SignConfiguration::kVerify:
267-
*result =
268+
*result = Boolean::New(
269+
env->isolate(),
268270
out->size() > 0 && out->size() == params.signature.size() &&
269-
memcmp(out->data(), params.signature.data(), out->size()) == 0
270-
? v8::True(env->isolate())
271-
: v8::False(env->isolate());
271+
memcmp(out->data(), params.signature.data(), out->size()) == 0);
272272
break;
273273
default:
274274
UNREACHABLE();
Collapse file

‎src/crypto/crypto_random.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_random.cc
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ namespace node {
1313

1414
using v8::ArrayBuffer;
1515
using v8::BackingStore;
16-
using v8::False;
16+
using v8::Boolean;
1717
using v8::FunctionCallbackInfo;
1818
using v8::Int32;
1919
using v8::Just;
2020
using v8::Local;
2121
using v8::Maybe;
2222
using v8::Nothing;
2323
using v8::Object;
24-
using v8::True;
2524
using v8::Uint32;
2625
using v8::Value;
2726

@@ -225,7 +224,7 @@ Maybe<bool> CheckPrimeTraits::EncodeOutput(
225224
const CheckPrimeConfig& params,
226225
ByteSource* out,
227226
v8::Local<v8::Value>* result) {
228-
*result = out->data<char>()[0] ? True(env->isolate()) : False(env->isolate());
227+
*result = Boolean::New(env->isolate(), out->data<char>()[0] != 0);
229228
return Just(true);
230229
}
231230

Collapse file

‎src/crypto/crypto_sig.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_sig.cc
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace node {
1313

1414
using v8::ArrayBuffer;
1515
using v8::BackingStore;
16+
using v8::Boolean;
1617
using v8::FunctionCallbackInfo;
1718
using v8::FunctionTemplate;
1819
using v8::HandleScope;
@@ -816,8 +817,7 @@ Maybe<bool> SignTraits::EncodeOutput(
816817
*result = out->ToArrayBuffer(env);
817818
break;
818819
case SignConfiguration::kVerify:
819-
*result = out->data<char>()[0] == 1 ? v8::True(env->isolate())
820-
: v8::False(env->isolate());
820+
*result = Boolean::New(env->isolate(), out->data<char>()[0] == 1);
821821
break;
822822
default:
823823
UNREACHABLE();
Collapse file

‎src/crypto/crypto_tls.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_tls.cc
+9-11Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ using v8::Array;
3939
using v8::ArrayBuffer;
4040
using v8::ArrayBufferView;
4141
using v8::BackingStore;
42+
using v8::Boolean;
4243
using v8::Context;
4344
using v8::DontDelete;
4445
using v8::Exception;
@@ -57,7 +58,6 @@ using v8::PropertyAttribute;
5758
using v8::ReadOnly;
5859
using v8::Signature;
5960
using v8::String;
60-
using v8::True;
6161
using v8::Uint32;
6262
using v8::Value;
6363

@@ -96,15 +96,14 @@ void OnClientHello(
9696

9797
if ((buf.IsEmpty() ||
9898
hello_obj->Set(env->context(), env->session_id_string(), buf)
99-
.IsNothing()) ||
99+
.IsNothing()) ||
100100
hello_obj->Set(env->context(), env->servername_string(), servername)
101101
.IsNothing() ||
102-
hello_obj->Set(
103-
env->context(),
104-
env->tls_ticket_string(),
105-
hello.has_ticket()
106-
? True(env->isolate())
107-
: False(env->isolate())).IsNothing()) {
102+
hello_obj
103+
->Set(env->context(),
104+
env->tls_ticket_string(),
105+
Boolean::New(env->isolate(), hello.has_ticket()))
106+
.IsNothing()) {
108107
return;
109108
}
110109

@@ -202,9 +201,8 @@ int SSLCertCallback(SSL* s, void* arg) {
202201
? String::Empty(env->isolate())
203202
: OneByteString(env->isolate(), servername, strlen(servername));
204203

205-
Local<Value> ocsp = (SSL_get_tlsext_status_type(s) == TLSEXT_STATUSTYPE_ocsp)
206-
? True(env->isolate())
207-
: False(env->isolate());
204+
Local<Value> ocsp = Boolean::New(
205+
env->isolate(), SSL_get_tlsext_status_type(s) == TLSEXT_STATUSTYPE_ocsp);
208206

209207
if (info->Set(env->context(), env->servername_string(), servername_str)
210208
.IsNothing() ||
Collapse file

‎src/node_http2.cc‎

Copy file name to clipboardExpand all lines: src/node_http2.cc
+3-10Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ using v8::BackingStore;
2828
using v8::Boolean;
2929
using v8::Context;
3030
using v8::EscapableHandleScope;
31-
using v8::False;
3231
using v8::Function;
3332
using v8::FunctionCallbackInfo;
3433
using v8::FunctionTemplate;
@@ -42,7 +41,6 @@ using v8::Number;
4241
using v8::Object;
4342
using v8::ObjectTemplate;
4443
using v8::String;
45-
using v8::True;
4644
using v8::Uint8Array;
4745
using v8::Undefined;
4846
using v8::Value;
@@ -332,10 +330,8 @@ void Http2Settings::Done(bool ack) {
332330
uint64_t end = uv_hrtime();
333331
double duration = (end - startTime_) / 1e6;
334332

335-
Local<Value> argv[] = {
336-
ack ? True(env()->isolate()) : False(env()->isolate()),
337-
Number::New(env()->isolate(), duration)
338-
};
333+
Local<Value> argv[] = {Boolean::New(env()->isolate(), ack),
334+
Number::New(env()->isolate(), duration)};
339335
MakeCallback(callback(), arraysize(argv), argv);
340336
}
341337

@@ -3131,10 +3127,7 @@ void Http2Ping::Done(bool ack, const uint8_t* payload) {
31313127
}
31323128

31333129
Local<Value> argv[] = {
3134-
ack ? True(isolate) : False(isolate),
3135-
Number::New(isolate, duration_ms),
3136-
buf
3137-
};
3130+
Boolean::New(isolate, ack), Number::New(isolate, duration_ms), buf};
31383131
MakeCallback(callback(), arraysize(argv), argv);
31393132
}
31403133

Collapse file

‎src/node_os.cc‎

Copy file name to clipboardExpand all lines: src/node_os.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
234234
result.emplace_back(family);
235235
result.emplace_back(FIXED_ONE_BYTE_STRING(isolate, mac));
236236
result.emplace_back(
237-
interfaces[i].is_internal ? True(isolate) : False(isolate));
237+
Boolean::New(env->isolate(), interfaces[i].is_internal));
238238
if (interfaces[i].address.address4.sin_family == AF_INET6) {
239239
uint32_t scopeid = interfaces[i].address.address6.sin6_scope_id;
240240
result.emplace_back(Integer::NewFromUnsigned(isolate, scopeid));

0 commit comments

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