Skip to content

Commit c9f809e

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 c6bfa66 commit c9f809e

File tree

7 files changed

+44
-28
lines changed

7 files changed

+44
-28
lines changed

Diff for: src/base_object-inl.h

+4-4
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

Diff for: src/env-inl.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -549,20 +549,16 @@ inline void Environment::set_http2_state(
549549
}
550550

551551
bool Environment::debug_enabled(DebugCategory category) const {
552-
#ifdef DEBUG
553-
CHECK_GE(static_cast<int>(category), 0);
554-
CHECK_LT(static_cast<int>(category),
552+
DCHECK_GE(static_cast<int>(category), 0);
553+
DCHECK_LT(static_cast<int>(category),
555554
static_cast<int>(DebugCategory::CATEGORY_COUNT));
556-
#endif
557555
return debug_enabled_[static_cast<int>(category)];
558556
}
559557

560558
void Environment::set_debug_enabled(DebugCategory category, bool enabled) {
561-
#ifdef DEBUG
562-
CHECK_GE(static_cast<int>(category), 0);
563-
CHECK_LT(static_cast<int>(category),
559+
DCHECK_GE(static_cast<int>(category), 0);
560+
DCHECK_LT(static_cast<int>(category),
564561
static_cast<int>(DebugCategory::CATEGORY_COUNT));
565-
#endif
566562
debug_enabled_[static_cast<int>(category)] = enabled;
567563
}
568564

Diff for: src/env.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,7 @@ void Environment::RunAndClearNativeImmediates() {
617617
};
618618
while (drain_list()) {}
619619

620-
#ifdef DEBUG
621-
CHECK_GE(immediate_info()->count(), count);
622-
#endif
620+
DCHECK_GE(immediate_info()->count(), count);
623621
immediate_info()->count_dec(count);
624622
immediate_info()->ref_count_dec(ref_count);
625623
}

Diff for: src/inspector/node_string.h

+4-3
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_

Diff for: src/stream_base-inl.h

+2-3
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
}

Diff for: src/stream_base.cc

+6-7
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

Diff for: src/util.h

+23
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)