src: use NULL check macros to check nullptr
PR-URL: https://github.com/nodejs/node/pull/25916
Refs: https://github.com/nodejs/node/pull/20914
Reviewed-By: Masashi Hirano <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
diff --git a/src/async_wrap.cc b/src/async_wrap.cc
index 8f20d4f..61455b2 100644
--- a/src/async_wrap.cc
+++ b/src/async_wrap.cc
@@ -206,7 +206,7 @@
obj->SetInternalField(PromiseWrap::kIsChainedPromiseField,
parent_wrap != nullptr ? v8::True(env->isolate())
: v8::False(env->isolate()));
- CHECK_EQ(promise->GetAlignedPointerFromInternalField(0), nullptr);
+ CHECK_NULL(promise->GetAlignedPointerFromInternalField(0));
promise->SetInternalField(0, obj);
return new PromiseWrap(env, obj, silent);
}
diff --git a/src/env-inl.h b/src/env-inl.h
index 748577a..60dafc0 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -667,7 +667,7 @@
}
inline void Environment::set_worker_context(worker::Worker* context) {
- CHECK_EQ(worker_context_, nullptr); // Should be set only once.
+ CHECK_NULL(worker_context_); // Should be set only once.
worker_context_ = context;
}
diff --git a/src/inspector/main_thread_interface.cc b/src/inspector/main_thread_interface.cc
index 15ffb49..1bcf651 100644
--- a/src/inspector/main_thread_interface.cc
+++ b/src/inspector/main_thread_interface.cc
@@ -307,7 +307,7 @@
void MainThreadInterface::AddObject(int id,
std::unique_ptr<Deletable> object) {
- CHECK_NE(nullptr, object);
+ CHECK_NOT_NULL(object);
managed_objects_[id] = std::move(object);
}
@@ -319,7 +319,7 @@
Deletable* pointer = GetObjectIfExists(id);
// This would mean the object is requested after it was disposed, which is
// a coding error.
- CHECK_NE(nullptr, pointer);
+ CHECK_NOT_NULL(pointer);
return pointer;
}
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index f625548..272f1a9 100644
--- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc
@@ -682,7 +682,7 @@
bool is_main) {
path_ = path;
debug_options_ = options;
- CHECK_NE(host_port, nullptr);
+ CHECK_NOT_NULL(host_port);
host_port_ = host_port;
client_ = std::make_shared<NodeInspectorClient>(parent_env_, is_main);
diff --git a/src/inspector_socket_server.cc b/src/inspector_socket_server.cc
index 1621b40..5e77ff5 100644
--- a/src/inspector_socket_server.cc
+++ b/src/inspector_socket_server.cc
@@ -352,7 +352,7 @@
}
bool InspectorSocketServer::Start() {
- CHECK_NE(delegate_, nullptr);
+ CHECK_NOT_NULL(delegate_);
CHECK_EQ(state_, ServerState::kNew);
std::unique_ptr<SocketServerDelegate> delegate_holder;
// We will return it if startup is successful
diff --git a/src/node.cc b/src/node.cc
index dfd691f..7d9075b 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -336,7 +336,7 @@
MaybeLocal<Value> StartExecution(Environment* env, const char* main_script_id) {
EscapableHandleScope scope(env->isolate());
- CHECK_NE(main_script_id, nullptr);
+ CHECK_NOT_NULL(main_script_id);
std::vector<Local<String>> parameters = {
env->process_string(),
diff --git a/src/node_api.cc b/src/node_api.cc
index 7d843c0..ff2e12f 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -1043,8 +1043,8 @@
napi_status
napi_get_threadsafe_function_context(napi_threadsafe_function func,
void** result) {
- CHECK(func != nullptr);
- CHECK(result != nullptr);
+ CHECK_NOT_NULL(func);
+ CHECK_NOT_NULL(result);
*result = reinterpret_cast<v8impl::ThreadSafeFunction*>(func)->Context();
return napi_ok;
@@ -1054,32 +1054,32 @@
napi_call_threadsafe_function(napi_threadsafe_function func,
void* data,
napi_threadsafe_function_call_mode is_blocking) {
- CHECK(func != nullptr);
+ CHECK_NOT_NULL(func);
return reinterpret_cast<v8impl::ThreadSafeFunction*>(func)->Push(data,
is_blocking);
}
napi_status
napi_acquire_threadsafe_function(napi_threadsafe_function func) {
- CHECK(func != nullptr);
+ CHECK_NOT_NULL(func);
return reinterpret_cast<v8impl::ThreadSafeFunction*>(func)->Acquire();
}
napi_status
napi_release_threadsafe_function(napi_threadsafe_function func,
napi_threadsafe_function_release_mode mode) {
- CHECK(func != nullptr);
+ CHECK_NOT_NULL(func);
return reinterpret_cast<v8impl::ThreadSafeFunction*>(func)->Release(mode);
}
napi_status
napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func) {
- CHECK(func != nullptr);
+ CHECK_NOT_NULL(func);
return reinterpret_cast<v8impl::ThreadSafeFunction*>(func)->Unref();
}
napi_status
napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func) {
- CHECK(func != nullptr);
+ CHECK_NOT_NULL(func);
return reinterpret_cast<v8impl::ThreadSafeFunction*>(func)->Ref();
}
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 056ebbc..78a8add 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -5408,7 +5408,7 @@
void CryptoJob::Run(std::unique_ptr<CryptoJob> job, Local<Value> wrap) {
CHECK(wrap->IsObject());
- CHECK_EQ(nullptr, job->async_wrap);
+ CHECK_NULL(job->async_wrap);
job->async_wrap.reset(Unwrap<AsyncWrap>(wrap.As<Object>()));
CHECK_EQ(false, job->async_wrap->persistent().IsWeak());
job->ScheduleWork();
diff --git a/src/node_http2.cc b/src/node_http2.cc
index 4e19432..1dd1f37 100644
--- a/src/node_http2.cc
+++ b/src/node_http2.cc
@@ -530,7 +530,7 @@
static void H2Free(void* ptr, void* user_data) {
if (ptr == nullptr) return; // free(null); happens quite often.
void* result = H2Realloc(ptr, 0, user_data);
- CHECK_EQ(result, nullptr);
+ CHECK_NULL(result);
}
static void* H2Realloc(void* ptr, size_t size, void* user_data) {
diff --git a/src/node_http_parser_impl.h b/src/node_http_parser_impl.h
index 7a955cc..7d5ea34 100644
--- a/src/node_http_parser_impl.h
+++ b/src/node_http_parser_impl.h
@@ -744,7 +744,7 @@
Local<String> reason;
if (err == HPE_USER) {
const char* colon = strchr(errno_reason, ':');
- CHECK_NE(colon, nullptr);
+ CHECK_NOT_NULL(colon);
code = OneByteString(env()->isolate(), errno_reason,
colon - errno_reason);
reason = OneByteString(env()->isolate(), colon + 1);
diff --git a/src/node_messaging.cc b/src/node_messaging.cc
index 9952043..896f43c 100644
--- a/src/node_messaging.cc
+++ b/src/node_messaging.cc
@@ -376,7 +376,7 @@
MessagePortData::MessagePortData(MessagePort* owner) : owner_(owner) { }
MessagePortData::~MessagePortData() {
- CHECK_EQ(owner_, nullptr);
+ CHECK_NULL(owner_);
Disentangle();
}
@@ -402,8 +402,8 @@
}
void MessagePortData::Entangle(MessagePortData* a, MessagePortData* b) {
- CHECK_EQ(a->sibling_, nullptr);
- CHECK_EQ(b->sibling_, nullptr);
+ CHECK_NULL(a->sibling_);
+ CHECK_NULL(b->sibling_);
a->sibling_ = b;
b->sibling_ = a;
a->sibling_mutex_ = b->sibling_mutex_;
diff --git a/src/node_native_module.cc b/src/node_native_module.cc
index 662aad3..2d3769e 100644
--- a/src/node_native_module.cc
+++ b/src/node_native_module.cc
@@ -270,7 +270,7 @@
// Generate new cache for next compilation
std::unique_ptr<ScriptCompiler::CachedData> new_cached_data(
ScriptCompiler::CreateCodeCacheForFunction(fun));
- CHECK_NE(new_cached_data, nullptr);
+ CHECK_NOT_NULL(new_cached_data);
// The old entry should've been erased by now so we can just emplace
code_cache_.emplace(id, std::move(new_cached_data));
diff --git a/src/node_platform.cc b/src/node_platform.cc
index 797d4d9..b930edb 100644
--- a/src/node_platform.cc
+++ b/src/node_platform.cc
@@ -241,14 +241,14 @@
}
void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
- CHECK_NE(flush_tasks_, nullptr);
+ CHECK_NOT_NULL(flush_tasks_);
foreground_tasks_.Push(std::move(task));
uv_async_send(flush_tasks_);
}
void PerIsolatePlatformData::PostDelayedTask(
std::unique_ptr<Task> task, double delay_in_seconds) {
- CHECK_NE(flush_tasks_, nullptr);
+ CHECK_NOT_NULL(flush_tasks_);
std::unique_ptr<DelayedTask> delayed(new DelayedTask());
delayed->task = std::move(task);
delayed->platform_data = shared_from_this();
diff --git a/src/node_union_bytes.h b/src/node_union_bytes.h
index 66d8509..33fada7 100644
--- a/src/node_union_bytes.h
+++ b/src/node_union_bytes.h
@@ -64,22 +64,22 @@
bool is_one_byte() const { return is_one_byte_; }
const uint16_t* two_bytes_data() const {
CHECK(!is_one_byte_);
- CHECK_NE(two_bytes_, nullptr);
+ CHECK_NOT_NULL(two_bytes_);
return two_bytes_;
}
const uint8_t* one_bytes_data() const {
CHECK(is_one_byte_);
- CHECK_NE(one_bytes_, nullptr);
+ CHECK_NOT_NULL(one_bytes_);
return one_bytes_;
}
v8::Local<v8::String> ToStringChecked(v8::Isolate* isolate) const {
if (is_one_byte_) {
- CHECK_NE(one_bytes_, nullptr);
+ CHECK_NOT_NULL(one_bytes_);
NonOwningExternalOneByteResource* source =
new NonOwningExternalOneByteResource(one_bytes_, length_);
return v8::String::NewExternalOneByte(isolate, source).ToLocalChecked();
} else {
- CHECK_NE(two_bytes_, nullptr);
+ CHECK_NOT_NULL(two_bytes_);
NonOwningExternalTwoByteResource* source =
new NonOwningExternalTwoByteResource(two_bytes_, length_);
return v8::String::NewExternalTwoByte(isolate, source).ToLocalChecked();
diff --git a/src/node_worker.cc b/src/node_worker.cc
index 2d960f6..3fd19de 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -92,7 +92,7 @@
CHECK_EQ(uv_loop_init(&loop_), 0);
isolate_ = NewIsolate(array_buffer_allocator_.get(), &loop_);
- CHECK_NE(isolate_, nullptr);
+ CHECK_NOT_NULL(isolate_);
{
// Enter an environment capable of executing code in the child Isolate
@@ -115,7 +115,7 @@
// TODO(addaleax): Use CreateEnvironment(), or generally another public API.
env_.reset(new Environment(isolate_data_.get(), context));
- CHECK_NE(env_, nullptr);
+ CHECK_NOT_NULL(env_);
env_->set_abort_on_uncaught_exception(false);
env_->set_worker_context(this);
thread_id_ = env_->thread_id();
@@ -153,7 +153,7 @@
"__metadata", "thread_name", "name",
TRACE_STR_COPY(name.c_str()));
MultiIsolatePlatform* platform = isolate_data_->platform();
- CHECK_NE(platform, nullptr);
+ CHECK_NOT_NULL(platform);
Debug(this, "Starting worker with id %llu", thread_id_);
{
@@ -339,7 +339,7 @@
CHECK(stopped_);
}
- CHECK_EQ(child_port_, nullptr);
+ CHECK_NULL(child_port_);
parent_port_ = nullptr;
}
@@ -369,7 +369,7 @@
CHECK(stopped_);
CHECK(thread_joined_);
- CHECK_EQ(child_port_, nullptr);
+ CHECK_NULL(child_port_);
// This has most likely already happened within the worker thread -- this
// is just in case Worker creation failed early.
@@ -509,7 +509,7 @@
Debug(this, "Worker %llu called Exit(%d)", thread_id_, code);
if (!stopped_) {
- CHECK_NE(env_, nullptr);
+ CHECK_NOT_NULL(env_);
stopped_ = true;
exit_code_ = code;
if (child_port_ != nullptr)
diff --git a/src/sharedarraybuffer_metadata.cc b/src/sharedarraybuffer_metadata.cc
index 671ad6d..4e6f5a3 100644
--- a/src/sharedarraybuffer_metadata.cc
+++ b/src/sharedarraybuffer_metadata.cc
@@ -75,7 +75,7 @@
CHECK(source->IsExternal());
SABLifetimePartner* partner =
Unwrap<SABLifetimePartner>(lifetime_partner.As<Object>());
- CHECK_NE(partner, nullptr);
+ CHECK_NOT_NULL(partner);
return partner->reference;
}