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>
This commit is contained in:
parent
c700cc42da
commit
13493e99bf
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user