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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Tobias Nießen
2023-04-16 20:26:06 +02:00
committed by GitHub
parent 070c9a8974
commit 4f5bb1a75a
8 changed files with 25 additions and 33 deletions

View File

@@ -23,6 +23,7 @@
namespace node {
using errors::TryCatchScope;
using v8::Array;
using v8::Boolean;
using v8::Context;
using v8::EscapableHandleScope;
using v8::Function;
@@ -667,7 +668,7 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
context->AllowCodeGenerationFromStrings(false);
context->SetEmbedderData(
ContextEmbedderIndex::kAllowCodeGenerationFromStrings,
is_code_generation_from_strings_allowed ? True(isolate) : False(isolate));
Boolean::New(isolate, is_code_generation_from_strings_allowed));
if (per_process::cli_options->disable_proto == "") {
return Just(true);

View File

@@ -22,6 +22,7 @@ namespace node {
using v8::Array;
using v8::ArrayBufferView;
using v8::Boolean;
using v8::Context;
using v8::DontDelete;
using v8::Exception;
@@ -1191,7 +1192,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
return -1;
}
argv[2] = enc != 0 ? v8::True(env->isolate()) : v8::False(env->isolate());
argv[2] = Boolean::New(env->isolate(), enc != 0);
Local<Value> ret;
if (!node::MakeCallback(

View File

@@ -13,6 +13,7 @@
namespace node {
using v8::Boolean;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
@@ -264,11 +265,10 @@ Maybe<bool> HmacTraits::EncodeOutput(
*result = out->ToArrayBuffer(env);
break;
case SignConfiguration::kVerify:
*result =
*result = Boolean::New(
env->isolate(),
out->size() > 0 && out->size() == params.signature.size() &&
memcmp(out->data(), params.signature.data(), out->size()) == 0
? v8::True(env->isolate())
: v8::False(env->isolate());
memcmp(out->data(), params.signature.data(), out->size()) == 0);
break;
default:
UNREACHABLE();

View File

@@ -13,7 +13,7 @@ namespace node {
using v8::ArrayBuffer;
using v8::BackingStore;
using v8::False;
using v8::Boolean;
using v8::FunctionCallbackInfo;
using v8::Int32;
using v8::Just;
@@ -21,7 +21,6 @@ using v8::Local;
using v8::Maybe;
using v8::Nothing;
using v8::Object;
using v8::True;
using v8::Uint32;
using v8::Value;
@@ -225,7 +224,7 @@ Maybe<bool> CheckPrimeTraits::EncodeOutput(
const CheckPrimeConfig& params,
ByteSource* out,
v8::Local<v8::Value>* result) {
*result = out->data<char>()[0] ? True(env->isolate()) : False(env->isolate());
*result = Boolean::New(env->isolate(), out->data<char>()[0] != 0);
return Just(true);
}

View File

@@ -13,6 +13,7 @@ namespace node {
using v8::ArrayBuffer;
using v8::BackingStore;
using v8::Boolean;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
@@ -816,8 +817,7 @@ Maybe<bool> SignTraits::EncodeOutput(
*result = out->ToArrayBuffer(env);
break;
case SignConfiguration::kVerify:
*result = out->data<char>()[0] == 1 ? v8::True(env->isolate())
: v8::False(env->isolate());
*result = Boolean::New(env->isolate(), out->data<char>()[0] == 1);
break;
default:
UNREACHABLE();

View File

@@ -39,6 +39,7 @@ using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
using v8::Boolean;
using v8::Context;
using v8::DontDelete;
using v8::Exception;
@@ -57,7 +58,6 @@ using v8::PropertyAttribute;
using v8::ReadOnly;
using v8::Signature;
using v8::String;
using v8::True;
using v8::Uint32;
using v8::Value;
@@ -96,15 +96,14 @@ void OnClientHello(
if ((buf.IsEmpty() ||
hello_obj->Set(env->context(), env->session_id_string(), buf)
.IsNothing()) ||
.IsNothing()) ||
hello_obj->Set(env->context(), env->servername_string(), servername)
.IsNothing() ||
hello_obj->Set(
env->context(),
env->tls_ticket_string(),
hello.has_ticket()
? True(env->isolate())
: False(env->isolate())).IsNothing()) {
hello_obj
->Set(env->context(),
env->tls_ticket_string(),
Boolean::New(env->isolate(), hello.has_ticket()))
.IsNothing()) {
return;
}
@@ -202,9 +201,8 @@ int SSLCertCallback(SSL* s, void* arg) {
? String::Empty(env->isolate())
: OneByteString(env->isolate(), servername, strlen(servername));
Local<Value> ocsp = (SSL_get_tlsext_status_type(s) == TLSEXT_STATUSTYPE_ocsp)
? True(env->isolate())
: False(env->isolate());
Local<Value> ocsp = Boolean::New(
env->isolate(), SSL_get_tlsext_status_type(s) == TLSEXT_STATUSTYPE_ocsp);
if (info->Set(env->context(), env->servername_string(), servername_str)
.IsNothing() ||

View File

@@ -28,7 +28,6 @@ using v8::BackingStore;
using v8::Boolean;
using v8::Context;
using v8::EscapableHandleScope;
using v8::False;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
@@ -42,7 +41,6 @@ using v8::Number;
using v8::Object;
using v8::ObjectTemplate;
using v8::String;
using v8::True;
using v8::Uint8Array;
using v8::Undefined;
using v8::Value;
@@ -332,10 +330,8 @@ void Http2Settings::Done(bool ack) {
uint64_t end = uv_hrtime();
double duration = (end - startTime_) / 1e6;
Local<Value> argv[] = {
ack ? True(env()->isolate()) : False(env()->isolate()),
Number::New(env()->isolate(), duration)
};
Local<Value> argv[] = {Boolean::New(env()->isolate(), ack),
Number::New(env()->isolate(), duration)};
MakeCallback(callback(), arraysize(argv), argv);
}
@@ -3131,10 +3127,7 @@ void Http2Ping::Done(bool ack, const uint8_t* payload) {
}
Local<Value> argv[] = {
ack ? True(isolate) : False(isolate),
Number::New(isolate, duration_ms),
buf
};
Boolean::New(isolate, ack), Number::New(isolate, duration_ms), buf};
MakeCallback(callback(), arraysize(argv), argv);
}

View File

@@ -234,7 +234,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
result.emplace_back(family);
result.emplace_back(FIXED_ONE_BYTE_STRING(isolate, mac));
result.emplace_back(
interfaces[i].is_internal ? True(isolate) : False(isolate));
Boolean::New(env->isolate(), interfaces[i].is_internal));
if (interfaces[i].address.address4.sin_family == AF_INET6) {
uint32_t scopeid = interfaces[i].address.address6.sin6_scope_id;
result.emplace_back(Integer::NewFromUnsigned(isolate, scopeid));