Skip to content

Commit 5e69e1a

Browse files
tniessenMylesBorins
authored andcommitted
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: #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 bfe6dc3 commit 5e69e1a

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

src/callback_scope.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
4444
async_context_(asyncContext),
4545
object_(object),
4646
callback_scope_(env) {
47-
if (expect == kRequireResource) {
48-
CHECK(!object.IsEmpty());
49-
}
47+
CHECK_IMPLIES(expect == kRequireResource, !object.IsEmpty());
5048

5149
if (!env->can_call_into_js()) {
5250
failed_ = true;

src/inspector_io.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ bool InspectorIo::Start() {
197197
}
198198

199199
void InspectorIo::Stop() {
200-
CHECK(state_ == State::kAccepting || !sessions_.empty());
200+
CHECK_IMPLIES(sessions_.empty(), state_ == State::kAccepting);
201201
Write(TransportAction::kKill, 0, StringView());
202202
int err = uv_thread_join(&thread_);
203203
CHECK_EQ(err, 0);

src/tls_wrap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ void TLSWrap::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
676676
if (!hello_parser_.IsEnded()) {
677677
size_t avail = 0;
678678
uint8_t* data = reinterpret_cast<uint8_t*>(enc_in->Peek(&avail));
679-
CHECK(avail == 0 || data != nullptr);
679+
CHECK_IMPLIES(data == nullptr, avail == 0);
680680
return hello_parser_.Parse(data, avail);
681681
}
682682

src/util-inl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,21 @@ inline T* UncheckedCalloc(size_t n) {
365365
template <typename T>
366366
inline T* Realloc(T* pointer, size_t n) {
367367
T* ret = UncheckedRealloc(pointer, n);
368-
if (n > 0) CHECK_NE(ret, nullptr);
368+
CHECK_IMPLIES(n > 0, ret != nullptr);
369369
return ret;
370370
}
371371

372372
template <typename T>
373373
inline T* Malloc(size_t n) {
374374
T* ret = UncheckedMalloc<T>(n);
375-
if (n > 0) CHECK_NE(ret, nullptr);
375+
CHECK_IMPLIES(n > 0, ret != nullptr);
376376
return ret;
377377
}
378378

379379
template <typename T>
380380
inline T* Calloc(size_t n) {
381381
T* ret = UncheckedCalloc<T>(n);
382-
if (n > 0) CHECK_NE(ret, nullptr);
382+
CHECK_IMPLIES(n > 0, ret != nullptr);
383383
return ret;
384384
}
385385

src/util.h

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void DumpBacktrace(FILE* fp);
129129
#define CHECK_LE(a, b) CHECK((a) <= (b))
130130
#define CHECK_LT(a, b) CHECK((a) < (b))
131131
#define CHECK_NE(a, b) CHECK((a) != (b))
132+
#define CHECK_IMPLIES(a, b) CHECK(!(a) || (b))
132133

133134
#define UNREACHABLE() ABORT()
134135

0 commit comments

Comments
 (0)