Skip to content

Commit e624713

Browse files
kiyomizumiaMylesBorins
authored andcommitted
src: add DCHECK macros
This adds check statements for debugging and refactors the code accordingly. PR-URL: #24359 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 508cbaa commit e624713

File tree

7 files changed

+44
-28
lines changed

7 files changed

+44
-28
lines changed

src/base_object-inl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ v8::Local<v8::Object> BaseObject::object() const {
6767

6868
v8::Local<v8::Object> BaseObject::object(v8::Isolate* isolate) const {
6969
v8::Local<v8::Object> handle = object();
70-
#ifdef DEBUG
71-
CHECK_EQ(handle->CreationContext()->GetIsolate(), isolate);
72-
CHECK_EQ(env_->isolate(), isolate);
73-
#endif
70+
71+
DCHECK_EQ(handle->CreationContext()->GetIsolate(), isolate);
72+
DCHECK_EQ(env_->isolate(), isolate);
73+
7474
return handle;
7575
}
7676

src/env-inl.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,20 +559,16 @@ inline void Environment::set_http2_state(
559559
}
560560

561561
bool Environment::debug_enabled(DebugCategory category) const {
562-
#ifdef DEBUG
563-
CHECK_GE(static_cast<int>(category), 0);
564-
CHECK_LT(static_cast<int>(category),
562+
DCHECK_GE(static_cast<int>(category), 0);
563+
DCHECK_LT(static_cast<int>(category),
565564
static_cast<int>(DebugCategory::CATEGORY_COUNT));
566-
#endif
567565
return debug_enabled_[static_cast<int>(category)];
568566
}
569567

570568
void Environment::set_debug_enabled(DebugCategory category, bool enabled) {
571-
#ifdef DEBUG
572-
CHECK_GE(static_cast<int>(category), 0);
573-
CHECK_LT(static_cast<int>(category),
569+
DCHECK_GE(static_cast<int>(category), 0);
570+
DCHECK_LT(static_cast<int>(category),
574571
static_cast<int>(DebugCategory::CATEGORY_COUNT));
575-
#endif
576572
debug_enabled_[static_cast<int>(category)] = enabled;
577573
}
578574

src/env.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,7 @@ void Environment::RunAndClearNativeImmediates() {
622622
};
623623
while (drain_list()) {}
624624

625-
#ifdef DEBUG
626-
CHECK_GE(immediate_info()->count(), count);
627-
#endif
625+
DCHECK_GE(immediate_info()->count(), count);
628626
immediate_info()->count_dec(count);
629627
immediate_info()->ref_count_dec(ref_count);
630628
}

src/inspector/node_string.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ extern size_t kNotFound;
7373
} // namespace inspector
7474
} // namespace node
7575

76-
#define DCHECK CHECK
77-
#define DCHECK_LT CHECK_LT
78-
76+
#ifndef DCHECK
77+
#define DCHECK CHECK
78+
#define DCHECK_LT CHECK_LT
79+
#endif // DCHECK
7980
#endif // SRC_INSPECTOR_NODE_STRING_H_

src/stream_base-inl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,8 @@ inline void StreamReq::Done(int status, const char* error_str) {
448448
}
449449

450450
inline void StreamReq::ResetObject(v8::Local<v8::Object> obj) {
451-
#ifdef DEBUG
452-
CHECK_GT(obj->InternalFieldCount(), StreamReq::kStreamReqField);
453-
#endif
451+
DCHECK_GT(obj->InternalFieldCount(), StreamReq::kStreamReqField);
452+
454453
obj->SetAlignedPointerInInternalField(0, nullptr); // BaseObject field.
455454
obj->SetAlignedPointerInInternalField(StreamReq::kStreamReqField, nullptr);
456455
}

src/stream_base.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,16 @@ void StreamBase::CallJSOnreadMethod(ssize_t nread,
292292
size_t offset) {
293293
Environment* env = env_;
294294

295-
#ifdef DEBUG
296-
CHECK_EQ(static_cast<int32_t>(nread), nread);
297-
CHECK_LE(offset, INT32_MAX);
295+
DCHECK_EQ(static_cast<int32_t>(nread), nread);
296+
DCHECK_LE(offset, INT32_MAX);
298297

299298
if (ab.IsEmpty()) {
300-
CHECK_EQ(offset, 0);
301-
CHECK_LE(nread, 0);
299+
DCHECK_EQ(offset, 0);
300+
DCHECK_LE(nread, 0);
302301
} else {
303-
CHECK_GE(nread, 0);
302+
DCHECK_GE(nread, 0);
304303
}
305-
#endif
304+
306305
env->stream_base_state()[kReadBytesOrError] = nread;
307306
env->stream_base_state()[kArrayBufferOffset] = offset;
308307

src/util.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ void DumpBacktrace(FILE* fp);
129129
#define CHECK_NOT_NULL(val) CHECK((val) != nullptr)
130130
#define CHECK_IMPLIES(a, b) CHECK(!(a) || (b))
131131

132+
#ifdef DEBUG
133+
#define DCHECK_EQ(a, b) CHECK((a) == (b))
134+
#define DCHECK_GE(a, b) CHECK((a) >= (b))
135+
#define DCHECK_GT(a, b) CHECK((a) > (b))
136+
#define DCHECK_LE(a, b) CHECK((a) <= (b))
137+
#define DCHECK_LT(a, b) CHECK((a) < (b))
138+
#define DCHECK_NE(a, b) CHECK((a) != (b))
139+
#define DCHECK_NULL(val) CHECK((val) == nullptr)
140+
#define DCHECK_NOT_NULL(val) CHECK((val) != nullptr)
141+
#define DCHECK_IMPLIES(a, b) CHECK(!(a) || (b))
142+
#else
143+
#define DCHECK_EQ(a, b)
144+
#define DCHECK_GE(a, b)
145+
#define DCHECK_GT(a, b)
146+
#define DCHECK_LE(a, b)
147+
#define DCHECK_LT(a, b)
148+
#define DCHECK_NE(a, b)
149+
#define DCHECK_NULL(val)
150+
#define DCHECK_NOT_NULL(val)
151+
#define DCHECK_IMPLIES(a, b)
152+
#endif
153+
154+
132155
#define UNREACHABLE() ABORT()
133156

134157
// TAILQ-style intrusive list node.

0 commit comments

Comments
 (0)