Skip to content

Commit 5fdff38

Browse files
bnoordhuisindutny
authored andcommitted
src: replace assert() with CHECK()
Mechanically replace assert() statements with UNREACHABLE(), CHECK(), or CHECK_{EQ,NE,LT,GT,LE,GE}() statements. The exceptions are src/node.h and src/node_object_wrap.h because they are public headers. PR-URL: node-forward/node#16 Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent 75a461d commit 5fdff38

36 files changed

Lines changed: 348 additions & 359 deletions

src/async-wrap-inl.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
#include "env-inl.h"
3030
#include "util.h"
3131
#include "util-inl.h"
32-
3332
#include "v8.h"
34-
#include <assert.h>
3533

3634
namespace node {
3735

@@ -74,7 +72,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
7472
const v8::Handle<v8::Function> cb,
7573
int argc,
7674
v8::Handle<v8::Value>* argv) {
77-
assert(env()->context() == env()->isolate()->GetCurrentContext());
75+
CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
7876

7977
v8::Local<v8::Object> context = object();
8078
v8::Local<v8::Object> process = env()->process_object();
@@ -169,7 +167,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
169167
if (env()->using_domains())
170168
return MakeDomainCallback(cb, argc, argv);
171169

172-
assert(env()->context() == env()->isolate()->GetCurrentContext());
170+
CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
173171

174172
v8::Local<v8::Object> context = object();
175173
v8::Local<v8::Object> process = env()->process_object();
@@ -235,7 +233,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
235233
v8::Handle<v8::Value>* argv) {
236234
v8::Local<v8::Value> cb_v = object()->Get(symbol);
237235
v8::Local<v8::Function> cb = cb_v.As<v8::Function>();
238-
assert(cb->IsFunction());
236+
CHECK(cb->IsFunction());
239237

240238
return MakeCallback(cb, argc, argv);
241239
}
@@ -247,7 +245,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
247245
v8::Handle<v8::Value>* argv) {
248246
v8::Local<v8::Value> cb_v = object()->Get(index);
249247
v8::Local<v8::Function> cb = cb_v.As<v8::Function>();
250-
assert(cb->IsFunction());
248+
CHECK(cb->IsFunction());
251249

252250
return MakeCallback(cb, argc, argv);
253251
}

src/base-object-inl.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@
2727
#include "util-inl.h"
2828
#include "v8.h"
2929

30-
#include <assert.h>
31-
3230
namespace node {
3331

3432
inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
3533
: handle_(env->isolate(), handle),
3634
env_(env) {
37-
assert(!handle.IsEmpty());
35+
CHECK_EQ(false, handle.IsEmpty());
3836
}
3937

4038

4139
inline BaseObject::~BaseObject() {
42-
assert(handle_.IsEmpty());
40+
CHECK(handle_.IsEmpty());
4341
}
4442

4543

@@ -71,7 +69,7 @@ template <typename Type>
7169
inline void BaseObject::MakeWeak(Type* ptr) {
7270
v8::HandleScope scope(env_->isolate());
7371
v8::Local<v8::Object> handle = object();
74-
assert(handle->InternalFieldCount() > 0);
72+
CHECK_GT(handle->InternalFieldCount(), 0);
7573
Wrap<Type>(handle, ptr);
7674
handle_.MarkIndependent();
7775
handle_.SetWeak<Type>(ptr, WeakCallback<Type>);

src/cares_wrap.cc

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "util.h"
3232
#include "uv.h"
3333

34-
#include <assert.h>
3534
#include <errno.h>
3635
#include <stdlib.h>
3736
#include <string.h>
@@ -85,7 +84,7 @@ RB_GENERATE_STATIC(ares_task_list, ares_task_t, node, cmp_ares_tasks)
8584
/* call back into c-ares for possibly processing timeouts. */
8685
static void ares_timeout(uv_timer_t* handle) {
8786
Environment* env = Environment::from_cares_timer_handle(handle);
88-
assert(!RB_EMPTY(env->cares_task_list()));
87+
CHECK_EQ(false, RB_EMPTY(env->cares_task_list()));
8988
ares_process_fd(env->cares_channel(), ARES_SOCKET_BAD, ARES_SOCKET_BAD);
9089
}
9190

@@ -159,7 +158,7 @@ static void ares_sockstate_cb(void* data,
159158
/* If this is the first socket then start the timer. */
160159
uv_timer_t* timer_handle = env->cares_timer_handle();
161160
if (!uv_is_active(reinterpret_cast<uv_handle_t*>(timer_handle))) {
162-
assert(RB_EMPTY(env->cares_task_list()));
161+
CHECK(RB_EMPTY(env->cares_task_list()));
163162
uv_timer_start(timer_handle, ares_timeout, 1000, 1000);
164163
}
165164

@@ -184,8 +183,8 @@ static void ares_sockstate_cb(void* data,
184183
/* read == 0 and write == 0 this is c-ares's way of notifying us that */
185184
/* the socket is now closed. We must free the data associated with */
186185
/* socket. */
187-
assert(task &&
188-
"When an ares socket is closed we should have a handle for it");
186+
CHECK(task &&
187+
"When an ares socket is closed we should have a handle for it");
189188

190189
RB_REMOVE(ares_task_list, env->cares_task_list(), task);
191190
uv_close(reinterpret_cast<uv_handle_t*>(&task->poll_watcher),
@@ -233,18 +232,18 @@ class QueryWrap : public AsyncWrap {
233232
}
234233

235234
virtual ~QueryWrap() {
236-
assert(!persistent().IsEmpty());
235+
CHECK_EQ(false, persistent().IsEmpty());
237236
persistent().Reset();
238237
}
239238

240239
// Subclasses should implement the appropriate Send method.
241240
virtual int Send(const char* name) {
242-
assert(0);
241+
UNREACHABLE();
243242
return 0;
244243
}
245244

246245
virtual int Send(const char* name, int family) {
247-
assert(0);
246+
UNREACHABLE();
248247
return 0;
249248
}
250249

@@ -301,7 +300,7 @@ class QueryWrap : public AsyncWrap {
301300
}
302301

303302
void ParseError(int status) {
304-
assert(status != ARES_SUCCESS);
303+
CHECK_NE(status, ARES_SUCCESS);
305304
HandleScope handle_scope(env()->isolate());
306305
Context::Scope context_scope(env()->context());
307306
Local<Value> arg;
@@ -344,11 +343,11 @@ class QueryWrap : public AsyncWrap {
344343

345344
// Subclasses should implement the appropriate Parse method.
346345
virtual void Parse(unsigned char* buf, int len) {
347-
assert(0);
346+
UNREACHABLE();
348347
};
349348

350349
virtual void Parse(struct hostent* host) {
351-
assert(0);
350+
UNREACHABLE();
352351
};
353352
};
354353

@@ -843,9 +842,9 @@ template <class Wrap>
843842
static void Query(const FunctionCallbackInfo<Value>& args) {
844843
Environment* env = Environment::GetCurrent(args.GetIsolate());
845844

846-
assert(!args.IsConstructCall());
847-
assert(args[0]->IsObject());
848-
assert(args[1]->IsString());
845+
CHECK_EQ(false, args.IsConstructCall());
846+
CHECK(args[0]->IsObject());
847+
CHECK(args[1]->IsString());
849848

850849
Local<Object> req_wrap_obj = args[0].As<Object>();
851850
Local<String> string = args[1].As<String>();
@@ -894,7 +893,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
894893
// strings for each IP and filling the results array.
895894
address = res;
896895
while (address) {
897-
assert(address->ai_socktype == SOCK_STREAM);
896+
CHECK_EQ(address->ai_socktype, SOCK_STREAM);
898897

899898
// Ignore random ai_family types.
900899
if (address->ai_family == AF_INET) {
@@ -921,7 +920,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
921920
// Iterate over the IPv6 responses putting them in the array.
922921
address = res;
923922
while (address) {
924-
assert(address->ai_socktype == SOCK_STREAM);
923+
CHECK_EQ(address->ai_socktype, SOCK_STREAM);
925924

926925
// Ignore random ai_family types.
927926
if (address->ai_family == AF_INET6) {
@@ -1008,9 +1007,9 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) {
10081007
static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
10091008
Environment* env = Environment::GetCurrent(args.GetIsolate());
10101009

1011-
assert(args[0]->IsObject());
1012-
assert(args[1]->IsString());
1013-
assert(args[2]->IsInt32());
1010+
CHECK(args[0]->IsObject());
1011+
CHECK(args[1]->IsString());
1012+
CHECK(args[2]->IsInt32());
10141013
Local<Object> req_wrap_obj = args[0].As<Object>();
10151014
node::Utf8Value hostname(args[1]);
10161015

@@ -1028,7 +1027,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
10281027
family = AF_INET6;
10291028
break;
10301029
default:
1031-
assert(0 && "bad address family");
1030+
CHECK(0 && "bad address family");
10321031
abort();
10331032
}
10341033

@@ -1097,7 +1096,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
10971096
ares_addr_node* servers;
10981097

10991098
int r = ares_get_servers(env->cares_channel(), &servers);
1100-
assert(r == ARES_SUCCESS);
1099+
CHECK_EQ(r, ARES_SUCCESS);
11011100

11021101
ares_addr_node* cur = servers;
11031102

@@ -1106,7 +1105,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
11061105

11071106
const void* caddr = static_cast<const void*>(&cur->addr);
11081107
int err = uv_inet_ntop(cur->family, caddr, ip, sizeof(ip));
1109-
assert(err == 0);
1108+
CHECK_EQ(err, 0);
11101109

11111110
Local<String> addr = OneByteString(env->isolate(), ip);
11121111
server_array->Set(i, addr);
@@ -1121,7 +1120,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
11211120
static void SetServers(const FunctionCallbackInfo<Value>& args) {
11221121
Environment* env = Environment::GetCurrent(args.GetIsolate());
11231122

1124-
assert(args[0]->IsArray());
1123+
CHECK(args[0]->IsArray());
11251124

11261125
Local<Array> arr = Local<Array>::Cast(args[0]);
11271126

@@ -1138,12 +1137,12 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
11381137
int err;
11391138

11401139
for (uint32_t i = 0; i < len; i++) {
1141-
assert(arr->Get(i)->IsArray());
1140+
CHECK(arr->Get(i)->IsArray());
11421141

11431142
Local<Array> elm = Local<Array>::Cast(arr->Get(i));
11441143

1145-
assert(elm->Get(0)->Int32Value());
1146-
assert(elm->Get(1)->IsString());
1144+
CHECK(elm->Get(0)->Int32Value());
1145+
CHECK(elm->Get(1)->IsString());
11471146

11481147
int fam = elm->Get(0)->Int32Value();
11491148
node::Utf8Value ip(elm->Get(1));
@@ -1160,7 +1159,7 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
11601159
err = uv_inet_pton(AF_INET6, *ip, &cur->addr);
11611160
break;
11621161
default:
1163-
assert(0 && "Bad address family.");
1162+
CHECK(0 && "Bad address family.");
11641163
abort();
11651164
}
11661165

@@ -1213,7 +1212,7 @@ static void Initialize(Handle<Object> target,
12131212
Environment* env = Environment::GetCurrent(context);
12141213

12151214
int r = ares_library_init(ARES_LIB_INIT_ALL);
1216-
assert(r == ARES_SUCCESS);
1215+
CHECK_EQ(r, ARES_SUCCESS);
12171216

12181217
struct ares_options options;
12191218
memset(&options, 0, sizeof(options));
@@ -1225,7 +1224,7 @@ static void Initialize(Handle<Object> target,
12251224
r = ares_init_options(env->cares_channel_ptr(),
12261225
&options,
12271226
ARES_OPT_FLAGS | ARES_OPT_SOCK_STATE_CB);
1228-
assert(r == ARES_SUCCESS);
1227+
CHECK_EQ(r, ARES_SUCCESS);
12291228

12301229
/* Initialize the timeout timer. The timer won't be started until the */
12311230
/* first socket is opened. */

src/fs_event_wrap.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ FSEventWrap::FSEventWrap(Environment* env, Handle<Object> object)
7474

7575

7676
FSEventWrap::~FSEventWrap() {
77-
assert(initialized_ == false);
77+
CHECK_EQ(initialized_, false);
7878
}
7979

8080

@@ -95,7 +95,7 @@ void FSEventWrap::Initialize(Handle<Object> target,
9595

9696

9797
void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) {
98-
assert(args.IsConstructCall());
98+
CHECK(args.IsConstructCall());
9999
Environment* env = Environment::GetCurrent(args.GetIsolate());
100100
new FSEventWrap(env, args.This());
101101
}
@@ -144,7 +144,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
144144
HandleScope handle_scope(env->isolate());
145145
Context::Scope context_scope(env->context());
146146

147-
assert(wrap->persistent().IsEmpty() == false);
147+
CHECK_EQ(wrap->persistent().IsEmpty(), false);
148148

149149
// We're in a bind here. libuv can set both UV_RENAME and UV_CHANGE but
150150
// the Node API only lets us pass a single event to JS land.
@@ -165,7 +165,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
165165
} else if (events & UV_CHANGE) {
166166
event_string = env->change_string();
167167
} else {
168-
assert(0 && "bad fs events flag");
168+
CHECK(0 && "bad fs events flag");
169169
abort();
170170
}
171171

src/handle_wrap.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
6969
if (wrap == NULL || wrap->handle__ == NULL)
7070
return;
7171

72-
assert(!wrap->persistent().IsEmpty());
72+
CHECK_EQ(false, wrap->persistent().IsEmpty());
7373
uv_close(wrap->handle__, OnClose);
7474
wrap->handle__ = NULL;
7575

@@ -95,7 +95,7 @@ HandleWrap::HandleWrap(Environment* env,
9595

9696

9797
HandleWrap::~HandleWrap() {
98-
assert(persistent().IsEmpty());
98+
CHECK(persistent().IsEmpty());
9999
QUEUE_REMOVE(&handle_wrap_queue_);
100100
}
101101

@@ -106,10 +106,10 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
106106
HandleScope scope(env->isolate());
107107

108108
// The wrap object should still be there.
109-
assert(wrap->persistent().IsEmpty() == false);
109+
CHECK_EQ(wrap->persistent().IsEmpty(), false);
110110

111111
// But the handle pointer should be gone.
112-
assert(wrap->handle__ == NULL);
112+
CHECK_EQ(wrap->handle__, NULL);
113113

114114
HandleScope handle_scope(env->isolate());
115115
Context::Scope context_scope(env->context());

0 commit comments

Comments
 (0)