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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)