Skip to content

Commit 39f2096

Browse files
committed
src: add CHECK_NULL/CHECK_NOT_NULL macros
This change introduces CHECK_NULL and CHECK_NOT_NULL macros similar to their definition in v8 and replaces instances of CHECK/CHECK_EQ/CHECK_NE with these where it seems appropriate. PR-URL: #20914 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 13493e9 commit 39f2096

33 files changed

+124
-122
lines changed

src/async_wrap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static void PromiseHook(PromiseHookType type, Local<Promise> promise,
310310
}
311311
}
312312

313-
CHECK_NE(wrap, nullptr);
313+
CHECK_NOT_NULL(wrap);
314314
if (type == PromiseHookType::kBefore) {
315315
env->async_hooks()->push_async_ids(
316316
wrap->get_async_id(), wrap->get_trigger_async_id());

src/connection_wrap.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template <typename WrapType, typename UVType>
3434
void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
3535
int status) {
3636
WrapType* wrap_data = static_cast<WrapType*>(handle->data);
37-
CHECK_NE(wrap_data, nullptr);
37+
CHECK_NOT_NULL(wrap_data);
3838
CHECK_EQ(&wrap_data->handle_, reinterpret_cast<UVType*>(handle));
3939

4040
Environment* env = wrap_data->env();
@@ -78,7 +78,7 @@ template <typename WrapType, typename UVType>
7878
void ConnectionWrap<WrapType, UVType>::AfterConnect(uv_connect_t* req,
7979
int status) {
8080
ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data);
81-
CHECK_NE(req_wrap, nullptr);
81+
CHECK_NOT_NULL(req_wrap);
8282
WrapType* wrap = static_cast<WrapType*>(req->handle->data);
8383
CHECK_EQ(req_wrap->env(), wrap->env());
8484
Environment* env = wrap->env();

src/env-inl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -473,22 +473,22 @@ inline double Environment::get_default_trigger_async_id() {
473473
}
474474

475475
inline double* Environment::heap_statistics_buffer() const {
476-
CHECK_NE(heap_statistics_buffer_, nullptr);
476+
CHECK_NOT_NULL(heap_statistics_buffer_);
477477
return heap_statistics_buffer_;
478478
}
479479

480480
inline void Environment::set_heap_statistics_buffer(double* pointer) {
481-
CHECK_EQ(heap_statistics_buffer_, nullptr); // Should be set only once.
481+
CHECK_NULL(heap_statistics_buffer_); // Should be set only once.
482482
heap_statistics_buffer_ = pointer;
483483
}
484484

485485
inline double* Environment::heap_space_statistics_buffer() const {
486-
CHECK_NE(heap_space_statistics_buffer_, nullptr);
486+
CHECK_NOT_NULL(heap_space_statistics_buffer_);
487487
return heap_space_statistics_buffer_;
488488
}
489489

490490
inline void Environment::set_heap_space_statistics_buffer(double* pointer) {
491-
CHECK_EQ(heap_space_statistics_buffer_, nullptr); // Should be set only once.
491+
CHECK_NULL(heap_space_statistics_buffer_); // Should be set only once.
492492
heap_space_statistics_buffer_ = pointer;
493493
}
494494

@@ -497,7 +497,7 @@ inline char* Environment::http_parser_buffer() const {
497497
}
498498

499499
inline void Environment::set_http_parser_buffer(char* buffer) {
500-
CHECK_EQ(http_parser_buffer_, nullptr); // Should be set only once.
500+
CHECK_NULL(http_parser_buffer_); // Should be set only once.
501501
http_parser_buffer_ = buffer;
502502
}
503503

src/env.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ IsolateData::~IsolateData() {
8080
v8::CpuProfiler* IsolateData::GetCpuProfiler() {
8181
if (cpu_profiler_ != nullptr) return cpu_profiler_;
8282
cpu_profiler_ = v8::CpuProfiler::New(isolate());
83-
CHECK_NE(cpu_profiler_, nullptr);
83+
CHECK_NOT_NULL(cpu_profiler_);
8484
return cpu_profiler_;
8585
}
8686

src/fs_event_wrap.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ FSEventWrap::~FSEventWrap() {
8888

8989
void FSEventWrap::GetInitialized(const FunctionCallbackInfo<Value>& args) {
9090
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.This());
91-
CHECK(wrap != nullptr);
91+
CHECK_NOT_NULL(wrap);
9292
args.GetReturnValue().Set(wrap->initialized_);
9393
}
9494

@@ -133,14 +133,14 @@ void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
133133
Environment* env = Environment::GetCurrent(args);
134134

135135
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.This());
136-
CHECK_NE(wrap, nullptr);
136+
CHECK_NOT_NULL(wrap);
137137
CHECK(!wrap->initialized_);
138138

139139
const int argc = args.Length();
140140
CHECK_GE(argc, 4);
141141

142142
BufferValue path(env->isolate(), args[0]);
143-
CHECK_NE(*path, nullptr);
143+
CHECK_NOT_NULL(*path);
144144

145145
unsigned int flags = 0;
146146
if (args[2]->IsTrue())
@@ -233,7 +233,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
233233

234234
void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
235235
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder());
236-
CHECK_NE(wrap, nullptr);
236+
CHECK_NOT_NULL(wrap);
237237
CHECK(wrap->initialized_);
238238

239239
wrap->initialized_ = false;

src/inspector_agent.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class InspectorTimerHandle {
317317
InspectorTimerHandle(const InspectorTimerHandle&) = delete;
318318

319319
~InspectorTimerHandle() {
320-
CHECK_NE(timer_, nullptr);
320+
CHECK_NOT_NULL(timer_);
321321
timer_->Stop();
322322
timer_ = nullptr;
323323
}
@@ -562,7 +562,7 @@ bool Agent::StartIoThread(bool wait_for_connect) {
562562
if (io_ != nullptr)
563563
return true;
564564

565-
CHECK_NE(client_, nullptr);
565+
CHECK_NOT_NULL(client_);
566566

567567
io_ = std::unique_ptr<InspectorIo>(
568568
new InspectorIo(parent_env_, platform_, path_, debug_options_,
@@ -613,7 +613,7 @@ std::unique_ptr<InspectorSession> Agent::Connect(
613613
}
614614

615615
void Agent::WaitForDisconnect() {
616-
CHECK_NE(client_, nullptr);
616+
CHECK_NOT_NULL(client_);
617617
// TODO(addaleax): Maybe this should use an at-exit hook for the Environment
618618
// or something similar?
619619
client_->contextDestroyed(parent_env_->context());

src/inspector_io.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ std::string ScriptPath(uv_loop_t* loop, const std::string& script_name) {
3434
uv_fs_t req;
3535
req.ptr = nullptr;
3636
if (0 == uv_fs_realpath(loop, &req, script_name.c_str(), nullptr)) {
37-
CHECK_NE(req.ptr, nullptr);
37+
CHECK_NOT_NULL(req.ptr);
3838
script_path = std::string(static_cast<char*>(req.ptr));
3939
}
4040
uv_fs_req_cleanup(&req);

src/inspector_socket.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ class HttpHandler : public ProtocolHandler {
599599
ProtocolHandler::ProtocolHandler(InspectorSocket* inspector,
600600
TcpHolder::Pointer tcp)
601601
: inspector_(inspector), tcp_(std::move(tcp)) {
602-
CHECK_NE(nullptr, tcp_);
602+
CHECK_NOT_NULL(tcp_);
603603
tcp_->SetHandler(this);
604604
}
605605

src/js_stream.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int JSStream::DoWrite(WriteWrap* w,
104104
uv_buf_t* bufs,
105105
size_t count,
106106
uv_stream_t* send_handle) {
107-
CHECK_EQ(send_handle, nullptr);
107+
CHECK_NULL(send_handle);
108108

109109
HandleScope scope(env()->isolate());
110110
Context::Scope context_scope(env()->context());

src/module_wrap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
106106
ContextifyContext* sandbox =
107107
ContextifyContext::ContextFromContextifiedSandbox(
108108
env, args[2].As<Object>());
109-
CHECK_NE(sandbox, nullptr);
109+
CHECK_NOT_NULL(sandbox);
110110
context = sandbox->context();
111111
}
112112

src/node.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,7 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
19641964
Environment* env = Environment::GetCurrent(args);
19651965
auto context = env->context();
19661966

1967-
CHECK_EQ(modpending, nullptr);
1967+
CHECK_NULL(modpending);
19681968

19691969
if (args.Length() < 2) {
19701970
env->ThrowError("process.dlopen needs at least 2 arguments.");
@@ -2231,8 +2231,8 @@ static Local<Object> InitModule(Environment* env,
22312231
Local<String> module) {
22322232
Local<Object> exports = Object::New(env->isolate());
22332233
// Internal bindings don't have a "module" object, only exports.
2234-
CHECK_EQ(mod->nm_register_func, nullptr);
2235-
CHECK_NE(mod->nm_context_register_func, nullptr);
2234+
CHECK_NULL(mod->nm_register_func);
2235+
CHECK_NOT_NULL(mod->nm_context_register_func);
22362236
Local<Value> unused = Undefined(env->isolate());
22372237
mod->nm_context_register_func(exports,
22382238
unused,
@@ -4075,7 +4075,7 @@ void AtExit(void (*cb)(void* arg), void* arg) {
40754075

40764076

40774077
void AtExit(Environment* env, void (*cb)(void* arg), void* arg) {
4078-
CHECK_NE(env, nullptr);
4078+
CHECK_NOT_NULL(env);
40794079
env->AtExit(cb, arg);
40804080
}
40814081

@@ -4336,7 +4336,7 @@ inline int Start(uv_loop_t* event_loop,
43364336

43374337
{
43384338
Mutex::ScopedLock scoped_lock(node_isolate_mutex);
4339-
CHECK_EQ(node_isolate, nullptr);
4339+
CHECK_NULL(node_isolate);
43404340
node_isolate = isolate;
43414341
}
43424342

src/node_buffer.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ CallbackInfo::CallbackInfo(Isolate* isolate,
140140
ArrayBuffer::Contents obj_c = object->GetContents();
141141
CHECK_EQ(data_, static_cast<char*>(obj_c.Data()));
142142
if (object->ByteLength() != 0)
143-
CHECK_NE(data_, nullptr);
143+
CHECK_NOT_NULL(data_);
144144

145145
persistent_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
146146
persistent_.SetWrapperClassId(BUFFER_ID);
@@ -329,7 +329,7 @@ MaybeLocal<Object> Copy(Environment* env, const char* data, size_t length) {
329329

330330
void* new_data;
331331
if (length > 0) {
332-
CHECK_NE(data, nullptr);
332+
CHECK_NOT_NULL(data);
333333
new_data = node::UncheckedMalloc(length);
334334
if (new_data == nullptr)
335335
return Local<Object>();
@@ -408,7 +408,7 @@ MaybeLocal<Object> New(Isolate* isolate, char* data, size_t length) {
408408

409409
MaybeLocal<Object> New(Environment* env, char* data, size_t length) {
410410
if (length > 0) {
411-
CHECK_NE(data, nullptr);
411+
CHECK_NOT_NULL(data);
412412
CHECK(length <= kMaxLength);
413413
}
414414

src/node_contextify.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ class ContextifyScript : public BaseObject {
655655
ContextifyContext* sandbox =
656656
ContextifyContext::ContextFromContextifiedSandbox(
657657
env, args[6].As<Object>());
658-
CHECK_NE(sandbox, nullptr);
658+
CHECK_NOT_NULL(sandbox);
659659
parsing_context = sandbox->context();
660660
}
661661
} else {
@@ -785,7 +785,7 @@ class ContextifyScript : public BaseObject {
785785
// Get the context from the sandbox
786786
ContextifyContext* contextify_context =
787787
ContextifyContext::ContextFromContextifiedSandbox(env, sandbox);
788-
CHECK_NE(contextify_context, nullptr);
788+
CHECK_NOT_NULL(contextify_context);
789789

790790
if (contextify_context->context().IsEmpty())
791791
return;

src/node_crypto.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static X509_STORE* NewRootCertStore() {
730730
BIO_free(bp);
731731

732732
// Parse errors from the built-in roots are fatal.
733-
CHECK_NE(x509, nullptr);
733+
CHECK_NOT_NULL(x509);
734734

735735
root_certs_vector.push_back(x509);
736736
}
@@ -1578,7 +1578,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
15781578
int rv;
15791579

15801580
ext = X509_get_ext(cert, index);
1581-
CHECK_NE(ext, nullptr);
1581+
CHECK_NOT_NULL(ext);
15821582

15831583
if (!SafeX509ExtPrint(bio.get(), ext)) {
15841584
rv = X509V3_EXT_print(bio.get(), ext, 0, 0);
@@ -3377,7 +3377,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
33773377

33783378

33793379
SignBase::Error SignBase::Init(const char* sign_type) {
3380-
CHECK_EQ(mdctx_, nullptr);
3380+
CHECK_NULL(mdctx_);
33813381
// Historically, "dss1" and "DSS1" were DSA aliases for SHA-1
33823382
// exposed through the public API.
33833383
if (strcmp(sign_type, "dss1") == 0 ||
@@ -4232,7 +4232,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<Value>& args,
42324232
BIGNUM* num =
42334233
BN_bin2bn(reinterpret_cast<unsigned char*>(Buffer::Data(args[0])),
42344234
Buffer::Length(args[0]), nullptr);
4235-
CHECK_NE(num, nullptr);
4235+
CHECK_NOT_NULL(num);
42364236
CHECK_EQ(1, set_field(dh->dh_.get(), num));
42374237
}
42384238

@@ -4490,7 +4490,7 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
44904490
USE(&mark_pop_error_on_return);
44914491

44924492
const BIGNUM* priv_key = EC_KEY_get0_private_key(ecdh->key_.get());
4493-
CHECK_NE(priv_key, nullptr);
4493+
CHECK_NOT_NULL(priv_key);
44944494

44954495
ECPointPointer pub(EC_POINT_new(ecdh->group_));
44964496
CHECK(pub);
@@ -5001,7 +5001,7 @@ void VerifySpkac(const FunctionCallbackInfo<Value>& args) {
50015001
return args.GetReturnValue().Set(verify_result);
50025002

50035003
char* data = Buffer::Data(args[0]);
5004-
CHECK_NE(data, nullptr);
5004+
CHECK_NOT_NULL(data);
50055005

50065006
verify_result = VerifySpkac(data, length);
50075007

@@ -5046,7 +5046,7 @@ void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
50465046
return args.GetReturnValue().SetEmptyString();
50475047

50485048
char* data = Buffer::Data(args[0]);
5049-
CHECK_NE(data, nullptr);
5049+
CHECK_NOT_NULL(data);
50505050

50515051
size_t pkey_size;
50525052
char* pkey = ExportPublicKey(data, length, &pkey_size);
@@ -5078,7 +5078,7 @@ void ExportChallenge(const FunctionCallbackInfo<Value>& args) {
50785078
return args.GetReturnValue().SetEmptyString();
50795079

50805080
char* data = Buffer::Data(args[0]);
5081-
CHECK_NE(data, nullptr);
5081+
CHECK_NOT_NULL(data);
50825082

50835083
OpenSSLBuffer cert = ExportChallenge(data, len);
50845084
if (!cert)

src/node_crypto.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ class ECDH : public BaseObject {
621621
key_(std::move(key)),
622622
group_(EC_KEY_get0_group(key_.get())) {
623623
MakeWeak();
624-
CHECK_NE(group_, nullptr);
624+
CHECK_NOT_NULL(group_);
625625
}
626626

627627
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);

src/node_crypto_bio.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ NodeBIO::~NodeBIO() {
518518

519519

520520
NodeBIO* NodeBIO::FromBIO(BIO* bio) {
521-
CHECK_NE(BIO_get_data(bio), nullptr);
521+
CHECK_NOT_NULL(BIO_get_data(bio));
522522
return static_cast<NodeBIO*>(BIO_get_data(bio));
523523
}
524524

src/node_crypto_clienthello-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void ClientHelloParser::Start(ClientHelloParser::OnHelloCb onhello_cb,
6565
return;
6666
Reset();
6767

68-
CHECK_NE(onhello_cb, nullptr);
68+
CHECK_NOT_NULL(onhello_cb);
6969

7070
state_ = kWaiting;
7171
onhello_cb_ = onhello_cb;

0 commit comments

Comments
 (0)