summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2018-05-20 17:05:25 +0200
committerTobias Nießen <tniessen@tnie.de>2018-05-26 12:29:12 +0200
commit13493e99bfd208bc6e5381a918384049384cc2ed (patch)
treec544ab44d19bf906f1f09421cbe347396d365922 /src
parentc700cc42da9cf73af9fec2098520a6c0a631d901 (diff)
downloadandroid-node-v8-13493e99bfd208bc6e5381a918384049384cc2ed.tar.gz
android-node-v8-13493e99bfd208bc6e5381a918384049384cc2ed.tar.bz2
android-node-v8-13493e99bfd208bc6e5381a918384049384cc2ed.zip
src: add CHECK_IMPLIES macro
This change introduces the CHECK_IMPLIES macro similar to its definition in v8 and replaces instances of CHECK with CHECK_IMPLIES where it seems appropriate. PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src')
-rw-r--r--src/callback_scope.cc4
-rw-r--r--src/inspector_io.cc2
-rw-r--r--src/tls_wrap.cc2
-rw-r--r--src/util-inl.h6
-rw-r--r--src/util.h1
5 files changed, 7 insertions, 8 deletions
diff --git a/src/callback_scope.cc b/src/callback_scope.cc
index 5e7a27cf01..9eac7beb03 100644
--- a/src/callback_scope.cc
+++ b/src/callback_scope.cc
@@ -44,9 +44,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
async_context_(asyncContext),
object_(object),
callback_scope_(env) {
- if (expect == kRequireResource) {
- CHECK(!object.IsEmpty());
- }
+ CHECK_IMPLIES(expect == kRequireResource, !object.IsEmpty());
if (!env->can_call_into_js()) {
failed_ = true;
diff --git a/src/inspector_io.cc b/src/inspector_io.cc
index ce18e98973..2934512478 100644
--- a/src/inspector_io.cc
+++ b/src/inspector_io.cc
@@ -197,7 +197,7 @@ bool InspectorIo::Start() {
}
void InspectorIo::Stop() {
- CHECK(state_ == State::kAccepting || !sessions_.empty());
+ CHECK_IMPLIES(sessions_.empty(), state_ == State::kAccepting);
Write(TransportAction::kKill, 0, StringView());
int err = uv_thread_join(&thread_);
CHECK_EQ(err, 0);
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc
index 5d84a10da2..8ecb4880d3 100644
--- a/src/tls_wrap.cc
+++ b/src/tls_wrap.cc
@@ -676,7 +676,7 @@ void TLSWrap::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
if (!hello_parser_.IsEnded()) {
size_t avail = 0;
uint8_t* data = reinterpret_cast<uint8_t*>(enc_in->Peek(&avail));
- CHECK(avail == 0 || data != nullptr);
+ CHECK_IMPLIES(data == nullptr, avail == 0);
return hello_parser_.Parse(data, avail);
}
diff --git a/src/util-inl.h b/src/util-inl.h
index 41a22c97ef..ff0d47c078 100644
--- a/src/util-inl.h
+++ b/src/util-inl.h
@@ -365,21 +365,21 @@ inline T* UncheckedCalloc(size_t n) {
template <typename T>
inline T* Realloc(T* pointer, size_t n) {
T* ret = UncheckedRealloc(pointer, n);
- if (n > 0) CHECK_NE(ret, nullptr);
+ CHECK_IMPLIES(n > 0, ret != nullptr);
return ret;
}
template <typename T>
inline T* Malloc(size_t n) {
T* ret = UncheckedMalloc<T>(n);
- if (n > 0) CHECK_NE(ret, nullptr);
+ CHECK_IMPLIES(n > 0, ret != nullptr);
return ret;
}
template <typename T>
inline T* Calloc(size_t n) {
T* ret = UncheckedCalloc<T>(n);
- if (n > 0) CHECK_NE(ret, nullptr);
+ CHECK_IMPLIES(n > 0, ret != nullptr);
return ret;
}
diff --git a/src/util.h b/src/util.h
index 1f43ba3f7b..ff77ccc0b8 100644
--- a/src/util.h
+++ b/src/util.h
@@ -129,6 +129,7 @@ void DumpBacktrace(FILE* fp);
#define CHECK_LE(a, b) CHECK((a) <= (b))
#define CHECK_LT(a, b) CHECK((a) < (b))
#define CHECK_NE(a, b) CHECK((a) != (b))
+#define CHECK_IMPLIES(a, b) CHECK(!(a) || (b))
#define UNREACHABLE() ABORT()