Skip to content

Commit

Permalink
src: add CHECK_IMPLIES macro
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
tniessen committed May 26, 2018
1 parent c700cc4 commit 13493e9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/callback_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 13493e9

Please sign in to comment.