Skip to content

Commit 902120a

Browse files
tniessenMylesBorins
authored andcommitted
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 5e69e1a commit 902120a

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
@@ -1978,7 +1978,7 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
19781978
Environment* env = Environment::GetCurrent(args);
19791979
auto context = env->context();
19801980

1981-
CHECK_EQ(modpending, nullptr);
1981+
CHECK_NULL(modpending);
19821982

19831983
if (args.Length() < 2) {
19841984
env->ThrowError("process.dlopen needs at least 2 arguments.");
@@ -2245,8 +2245,8 @@ static Local<Object> InitModule(Environment* env,
22452245
Local<String> module) {
22462246
Local<Object> exports = Object::New(env->isolate());
22472247
// Internal bindings don't have a "module" object, only exports.
2248-
CHECK_EQ(mod->nm_register_func, nullptr);
2249-
CHECK_NE(mod->nm_context_register_func, nullptr);
2248+
CHECK_NULL(mod->nm_register_func);
2249+
CHECK_NOT_NULL(mod->nm_context_register_func);
22502250
Local<Value> unused = Undefined(env->isolate());
22512251
mod->nm_context_register_func(exports,
22522252
unused,
@@ -4093,7 +4093,7 @@ void AtExit(void (*cb)(void* arg), void* arg) {
40934093

40944094

40954095
void AtExit(Environment* env, void (*cb)(void* arg), void* arg) {
4096-
CHECK_NE(env, nullptr);
4096+
CHECK_NOT_NULL(env);
40974097
env->AtExit(cb, arg);
40984098
}
40994099

@@ -4354,7 +4354,7 @@ inline int Start(uv_loop_t* event_loop,
43544354

43554355
{
43564356
Mutex::ScopedLock scoped_lock(node_isolate_mutex);
4357-
CHECK_EQ(node_isolate, nullptr);
4357+
CHECK_NULL(node_isolate);
43584358
node_isolate = isolate;
43594359
}
43604360

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
@@ -654,7 +654,7 @@ class ContextifyScript : public BaseObject {
654654
ContextifyContext* sandbox =
655655
ContextifyContext::ContextFromContextifiedSandbox(
656656
env, args[6].As<Object>());
657-
CHECK_NE(sandbox, nullptr);
657+
CHECK_NOT_NULL(sandbox);
658658
parsing_context = sandbox->context();
659659
}
660660
} else {
@@ -784,7 +784,7 @@ class ContextifyScript : public BaseObject {
784784
// Get the context from the sandbox
785785
ContextifyContext* contextify_context =
786786
ContextifyContext::ContextFromContextifiedSandbox(env, sandbox);
787-
CHECK_NE(contextify_context, nullptr);
787+
CHECK_NOT_NULL(contextify_context);
788788

789789
if (contextify_context->context().IsEmpty())
790790
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);
@@ -3383,7 +3383,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
33833383

33843384

33853385
SignBase::Error SignBase::Init(const char* sign_type) {
3386-
CHECK_EQ(mdctx_, nullptr);
3386+
CHECK_NULL(mdctx_);
33873387
// Historically, "dss1" and "DSS1" were DSA aliases for SHA-1
33883388
// exposed through the public API.
33893389
if (strcmp(sign_type, "dss1") == 0 ||
@@ -4238,7 +4238,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<Value>& args,
42384238
BIGNUM* num =
42394239
BN_bin2bn(reinterpret_cast<unsigned char*>(Buffer::Data(args[0])),
42404240
Buffer::Length(args[0]), nullptr);
4241-
CHECK_NE(num, nullptr);
4241+
CHECK_NOT_NULL(num);
42424242
CHECK_EQ(1, set_field(dh->dh_.get(), num));
42434243
}
42444244

@@ -4496,7 +4496,7 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
44964496
USE(&mark_pop_error_on_return);
44974497

44984498
const BIGNUM* priv_key = EC_KEY_get0_private_key(ecdh->key_.get());
4499-
CHECK_NE(priv_key, nullptr);
4499+
CHECK_NOT_NULL(priv_key);
45004500

45014501
ECPointPointer pub(EC_POINT_new(ecdh->group_));
45024502
CHECK(pub);
@@ -5007,7 +5007,7 @@ void VerifySpkac(const FunctionCallbackInfo<Value>& args) {
50075007
return args.GetReturnValue().Set(verify_result);
50085008

50095009
char* data = Buffer::Data(args[0]);
5010-
CHECK_NE(data, nullptr);
5010+
CHECK_NOT_NULL(data);
50115011

50125012
verify_result = VerifySpkac(data, length);
50135013

@@ -5052,7 +5052,7 @@ void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
50525052
return args.GetReturnValue().SetEmptyString();
50535053

50545054
char* data = Buffer::Data(args[0]);
5055-
CHECK_NE(data, nullptr);
5055+
CHECK_NOT_NULL(data);
50565056

50575057
size_t pkey_size;
50585058
char* pkey = ExportPublicKey(data, length, &pkey_size);
@@ -5084,7 +5084,7 @@ void ExportChallenge(const FunctionCallbackInfo<Value>& args) {
50845084
return args.GetReturnValue().SetEmptyString();
50855085

50865086
char* data = Buffer::Data(args[0]);
5087-
CHECK_NE(data, nullptr);
5087+
CHECK_NOT_NULL(data);
50885088

50895089
OpenSSLBuffer cert = ExportChallenge(data, len);
50905090
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)