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 71fb476

Browse filesBrowse files
tniessenMoLow
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 175b78b commit 71fb476
Copy full SHA for 71fb476

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
@@ -20,6 +20,7 @@
2020
namespace node {
2121
using errors::TryCatchScope;
2222
using v8::Array;
23+
using v8::Boolean;
2324
using v8::Context;
2425
using v8::EscapableHandleScope;
2526
using v8::Function;
@@ -602,7 +603,7 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
602603
context->AllowCodeGenerationFromStrings(false);
603604
context->SetEmbedderData(
604605
ContextEmbedderIndex::kAllowCodeGenerationFromStrings,
605-
is_code_generation_from_strings_allowed ? True(isolate) : False(isolate));
606+
Boolean::New(isolate, is_code_generation_from_strings_allowed));
606607

607608
if (per_process::cli_options->disable_proto == "") {
608609
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;
@@ -1192,7 +1193,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
11921193
return -1;
11931194
}
11941195

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

11971198
Local<Value> ret;
11981199
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;
@@ -266,11 +267,10 @@ Maybe<bool> HmacTraits::EncodeOutput(
266267
*result = out->ToArrayBuffer(env);
267268
break;
268269
case SignConfiguration::kVerify:
269-
*result =
270+
*result = Boolean::New(
271+
env->isolate(),
270272
out->size() > 0 && out->size() == params.signature.size() &&
271-
memcmp(out->data(), params.signature.data(), out->size()) == 0
272-
? v8::True(env->isolate())
273-
: v8::False(env->isolate());
273+
memcmp(out->data(), params.signature.data(), out->size()) == 0);
274274
break;
275275
default:
276276
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;
@@ -820,8 +821,7 @@ Maybe<bool> SignTraits::EncodeOutput(
820821
*result = out->ToArrayBuffer(env);
821822
break;
822823
case SignConfiguration::kVerify:
823-
*result = out->data<char>()[0] == 1 ? v8::True(env->isolate())
824-
: v8::False(env->isolate());
824+
*result = Boolean::New(env->isolate(), out->data<char>()[0] == 1);
825825
break;
826826
default:
827827
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.