Skip to content

Commit

Permalink
src: use NULL check macros to check nullptr
Browse files Browse the repository at this point in the history
PR-URL: #25916
Refs: #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]>
  • Loading branch information
ZYSzys authored and targos committed Feb 10, 2019
1 parent c47eb93 commit 5de1034
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ PromiseWrap* PromiseWrap::New(Environment* env,
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ inline worker::Worker* Environment::worker_context() const {
}

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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/inspector/main_thread_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ std::shared_ptr<MainThreadHandle> MainThreadInterface::GetHandle() {

void MainThreadInterface::AddObject(int id,
std::unique_ptr<Deletable> object) {
CHECK_NE(nullptr, object);
CHECK_NOT_NULL(object);
managed_objects_[id] = std::move(object);
}

Expand All @@ -319,7 +319,7 @@ Deletable* MainThreadInterface::GetObject(int id) {
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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ bool Agent::Start(const std::string& path,
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);
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ std::string InspectorSocketServer::GetFrontendURL(bool is_compat,
}

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
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void MarkBootstrapComplete(const FunctionCallbackInfo<Value>& args) {

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(),
Expand Down
14 changes: 7 additions & 7 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,8 @@ napi_create_threadsafe_function(napi_env env,
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;
Expand All @@ -1054,32 +1054,32 @@ napi_status
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();
}
2 changes: 1 addition & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5383,7 +5383,7 @@ void CryptoJob::AfterThreadPoolWork(int status) {

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();
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class Http2Session::MemoryAllocatorInfo {
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_http_parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ class Parser : public AsyncWrap, public StreamListener {
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);
Expand Down
6 changes: 3 additions & 3 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void Message::MemoryInfo(MemoryTracker* tracker) const {
MessagePortData::MessagePortData(MessagePort* owner) : owner_(owner) { }

MessagePortData::~MessagePortData() {
CHECK_EQ(owner_, nullptr);
CHECK_NULL(owner_);
Disentangle();
}

Expand All @@ -402,8 +402,8 @@ bool MessagePortData::IsSiblingClosed() const {
}

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_;
Expand Down
2 changes: 1 addition & 1 deletion src/node_native_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ MaybeLocal<Function> NativeModuleLoader::LookupAndCompile(
// 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));
Expand Down
4 changes: 2 additions & 2 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {
}

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();
Expand Down
8 changes: 4 additions & 4 deletions src/node_union_bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ class UnionBytes {
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();
Expand Down
12 changes: 6 additions & 6 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Worker::Worker(Environment* env,

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
Expand All @@ -115,7 +115,7 @@ Worker::Worker(Environment* env,

// 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();
Expand Down Expand Up @@ -153,7 +153,7 @@ void Worker::Run() {
"__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_);
{
Expand Down Expand Up @@ -339,7 +339,7 @@ void Worker::OnThreadStopped() {
CHECK(stopped_);
}

CHECK_EQ(child_port_, nullptr);
CHECK_NULL(child_port_);
parent_port_ = nullptr;
}

Expand Down Expand Up @@ -369,7 +369,7 @@ Worker::~Worker() {

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.
Expand Down Expand Up @@ -509,7 +509,7 @@ void Worker::Exit(int code) {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/sharedarraybuffer_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SharedArrayBufferMetadata::ForSharedArrayBuffer(
CHECK(source->IsExternal());
SABLifetimePartner* partner =
Unwrap<SABLifetimePartner>(lifetime_partner.As<Object>());
CHECK_NE(partner, nullptr);
CHECK_NOT_NULL(partner);
return partner->reference;
}

Expand Down

0 comments on commit 5de1034

Please sign in to comment.