Browse Source

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: https://github.com/node-forward/node/pull/16
Reviewed-By: Fedor Indutny <fedor@indutny.com>
archived-io.js-v0.12
Ben Noordhuis 10 years ago
committed by Fedor Indutny
parent
commit
5fdff3854a
  1. 10
      src/async-wrap-inl.h
  2. 8
      src/base-object-inl.h
  3. 57
      src/cares_wrap.cc
  4. 8
      src/fs_event_wrap.cc
  5. 8
      src/handle_wrap.cc
  6. 53
      src/node.cc
  7. 25
      src/node_buffer.cc
  8. 4
      src/node_contextify.cc
  9. 48
      src/node_crypto.cc
  10. 4
      src/node_crypto.h
  11. 32
      src/node_crypto_bio.cc
  12. 5
      src/node_crypto_bio.h
  13. 5
      src/node_crypto_clienthello-inl.h
  14. 15
      src/node_file.cc
  15. 26
      src/node_http_parser.cc
  16. 1
      src/node_internals.h
  17. 7
      src/node_stat_watcher.cc
  18. 1
      src/node_watchdog.cc
  19. 2
      src/node_win32_etw_provider-inl.h
  20. 2
      src/node_win32_etw_provider.cc
  21. 50
      src/node_zlib.cc
  22. 24
      src/pipe_wrap.cc
  23. 10
      src/process_wrap.cc
  24. 4
      src/req_wrap.h
  25. 4
      src/signal_wrap.cc
  26. 35
      src/smalloc.cc
  27. 64
      src/spawn_sync.cc
  28. 44
      src/stream_wrap.cc
  29. 6
      src/stream_wrap.h
  30. 23
      src/string_bytes.cc
  31. 40
      src/tcp_wrap.cc
  32. 4
      src/timer_wrap.cc
  33. 24
      src/tls_wrap.cc
  34. 10
      src/tty_wrap.cc
  35. 34
      src/udp_wrap.cc
  36. 10
      src/util-inl.h

10
src/async-wrap-inl.h

@ -29,9 +29,7 @@
#include "env-inl.h" #include "env-inl.h"
#include "util.h" #include "util.h"
#include "util-inl.h" #include "util-inl.h"
#include "v8.h" #include "v8.h"
#include <assert.h>
namespace node { namespace node {
@ -74,7 +72,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
const v8::Handle<v8::Function> cb, const v8::Handle<v8::Function> cb,
int argc, int argc,
v8::Handle<v8::Value>* argv) { v8::Handle<v8::Value>* argv) {
assert(env()->context() == env()->isolate()->GetCurrentContext()); CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
v8::Local<v8::Object> context = object(); v8::Local<v8::Object> context = object();
v8::Local<v8::Object> process = env()->process_object(); v8::Local<v8::Object> process = env()->process_object();
@ -169,7 +167,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
if (env()->using_domains()) if (env()->using_domains())
return MakeDomainCallback(cb, argc, argv); return MakeDomainCallback(cb, argc, argv);
assert(env()->context() == env()->isolate()->GetCurrentContext()); CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
v8::Local<v8::Object> context = object(); v8::Local<v8::Object> context = object();
v8::Local<v8::Object> process = env()->process_object(); v8::Local<v8::Object> process = env()->process_object();
@ -235,7 +233,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
v8::Handle<v8::Value>* argv) { v8::Handle<v8::Value>* argv) {
v8::Local<v8::Value> cb_v = object()->Get(symbol); v8::Local<v8::Value> cb_v = object()->Get(symbol);
v8::Local<v8::Function> cb = cb_v.As<v8::Function>(); v8::Local<v8::Function> cb = cb_v.As<v8::Function>();
assert(cb->IsFunction()); CHECK(cb->IsFunction());
return MakeCallback(cb, argc, argv); return MakeCallback(cb, argc, argv);
} }
@ -247,7 +245,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
v8::Handle<v8::Value>* argv) { v8::Handle<v8::Value>* argv) {
v8::Local<v8::Value> cb_v = object()->Get(index); v8::Local<v8::Value> cb_v = object()->Get(index);
v8::Local<v8::Function> cb = cb_v.As<v8::Function>(); v8::Local<v8::Function> cb = cb_v.As<v8::Function>();
assert(cb->IsFunction()); CHECK(cb->IsFunction());
return MakeCallback(cb, argc, argv); return MakeCallback(cb, argc, argv);
} }

8
src/base-object-inl.h

@ -27,19 +27,17 @@
#include "util-inl.h" #include "util-inl.h"
#include "v8.h" #include "v8.h"
#include <assert.h>
namespace node { namespace node {
inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle) inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
: handle_(env->isolate(), handle), : handle_(env->isolate(), handle),
env_(env) { env_(env) {
assert(!handle.IsEmpty()); CHECK_EQ(false, handle.IsEmpty());
} }
inline BaseObject::~BaseObject() { inline BaseObject::~BaseObject() {
assert(handle_.IsEmpty()); CHECK(handle_.IsEmpty());
} }
@ -71,7 +69,7 @@ template <typename Type>
inline void BaseObject::MakeWeak(Type* ptr) { inline void BaseObject::MakeWeak(Type* ptr) {
v8::HandleScope scope(env_->isolate()); v8::HandleScope scope(env_->isolate());
v8::Local<v8::Object> handle = object(); v8::Local<v8::Object> handle = object();
assert(handle->InternalFieldCount() > 0); CHECK_GT(handle->InternalFieldCount(), 0);
Wrap<Type>(handle, ptr); Wrap<Type>(handle, ptr);
handle_.MarkIndependent(); handle_.MarkIndependent();
handle_.SetWeak<Type>(ptr, WeakCallback<Type>); handle_.SetWeak<Type>(ptr, WeakCallback<Type>);

57
src/cares_wrap.cc

@ -31,7 +31,6 @@
#include "util.h" #include "util.h"
#include "uv.h" #include "uv.h"
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -85,7 +84,7 @@ RB_GENERATE_STATIC(ares_task_list, ares_task_t, node, cmp_ares_tasks)
/* call back into c-ares for possibly processing timeouts. */ /* call back into c-ares for possibly processing timeouts. */
static void ares_timeout(uv_timer_t* handle) { static void ares_timeout(uv_timer_t* handle) {
Environment* env = Environment::from_cares_timer_handle(handle); Environment* env = Environment::from_cares_timer_handle(handle);
assert(!RB_EMPTY(env->cares_task_list())); CHECK_EQ(false, RB_EMPTY(env->cares_task_list()));
ares_process_fd(env->cares_channel(), ARES_SOCKET_BAD, ARES_SOCKET_BAD); ares_process_fd(env->cares_channel(), ARES_SOCKET_BAD, ARES_SOCKET_BAD);
} }
@ -159,7 +158,7 @@ static void ares_sockstate_cb(void* data,
/* If this is the first socket then start the timer. */ /* If this is the first socket then start the timer. */
uv_timer_t* timer_handle = env->cares_timer_handle(); uv_timer_t* timer_handle = env->cares_timer_handle();
if (!uv_is_active(reinterpret_cast<uv_handle_t*>(timer_handle))) { if (!uv_is_active(reinterpret_cast<uv_handle_t*>(timer_handle))) {
assert(RB_EMPTY(env->cares_task_list())); CHECK(RB_EMPTY(env->cares_task_list()));
uv_timer_start(timer_handle, ares_timeout, 1000, 1000); uv_timer_start(timer_handle, ares_timeout, 1000, 1000);
} }
@ -184,8 +183,8 @@ static void ares_sockstate_cb(void* data,
/* read == 0 and write == 0 this is c-ares's way of notifying us that */ /* read == 0 and write == 0 this is c-ares's way of notifying us that */
/* the socket is now closed. We must free the data associated with */ /* the socket is now closed. We must free the data associated with */
/* socket. */ /* socket. */
assert(task && CHECK(task &&
"When an ares socket is closed we should have a handle for it"); "When an ares socket is closed we should have a handle for it");
RB_REMOVE(ares_task_list, env->cares_task_list(), task); RB_REMOVE(ares_task_list, env->cares_task_list(), task);
uv_close(reinterpret_cast<uv_handle_t*>(&task->poll_watcher), uv_close(reinterpret_cast<uv_handle_t*>(&task->poll_watcher),
@ -233,18 +232,18 @@ class QueryWrap : public AsyncWrap {
} }
virtual ~QueryWrap() { virtual ~QueryWrap() {
assert(!persistent().IsEmpty()); CHECK_EQ(false, persistent().IsEmpty());
persistent().Reset(); persistent().Reset();
} }
// Subclasses should implement the appropriate Send method. // Subclasses should implement the appropriate Send method.
virtual int Send(const char* name) { virtual int Send(const char* name) {
assert(0); UNREACHABLE();
return 0; return 0;
} }
virtual int Send(const char* name, int family) { virtual int Send(const char* name, int family) {
assert(0); UNREACHABLE();
return 0; return 0;
} }
@ -301,7 +300,7 @@ class QueryWrap : public AsyncWrap {
} }
void ParseError(int status) { void ParseError(int status) {
assert(status != ARES_SUCCESS); CHECK_NE(status, ARES_SUCCESS);
HandleScope handle_scope(env()->isolate()); HandleScope handle_scope(env()->isolate());
Context::Scope context_scope(env()->context()); Context::Scope context_scope(env()->context());
Local<Value> arg; Local<Value> arg;
@ -344,11 +343,11 @@ class QueryWrap : public AsyncWrap {
// Subclasses should implement the appropriate Parse method. // Subclasses should implement the appropriate Parse method.
virtual void Parse(unsigned char* buf, int len) { virtual void Parse(unsigned char* buf, int len) {
assert(0); UNREACHABLE();
}; };
virtual void Parse(struct hostent* host) { virtual void Parse(struct hostent* host) {
assert(0); UNREACHABLE();
}; };
}; };
@ -843,9 +842,9 @@ template <class Wrap>
static void Query(const FunctionCallbackInfo<Value>& args) { static void Query(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(!args.IsConstructCall()); CHECK_EQ(false, args.IsConstructCall());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsString()); CHECK(args[1]->IsString());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
Local<String> string = args[1].As<String>(); Local<String> string = args[1].As<String>();
@ -894,7 +893,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
// strings for each IP and filling the results array. // strings for each IP and filling the results array.
address = res; address = res;
while (address) { while (address) {
assert(address->ai_socktype == SOCK_STREAM); CHECK_EQ(address->ai_socktype, SOCK_STREAM);
// Ignore random ai_family types. // Ignore random ai_family types.
if (address->ai_family == AF_INET) { if (address->ai_family == AF_INET) {
@ -921,7 +920,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
// Iterate over the IPv6 responses putting them in the array. // Iterate over the IPv6 responses putting them in the array.
address = res; address = res;
while (address) { while (address) {
assert(address->ai_socktype == SOCK_STREAM); CHECK_EQ(address->ai_socktype, SOCK_STREAM);
// Ignore random ai_family types. // Ignore random ai_family types.
if (address->ai_family == AF_INET6) { if (address->ai_family == AF_INET6) {
@ -1008,9 +1007,9 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) {
static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) { static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsString()); CHECK(args[1]->IsString());
assert(args[2]->IsInt32()); CHECK(args[2]->IsInt32());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value hostname(args[1]); node::Utf8Value hostname(args[1]);
@ -1028,7 +1027,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
family = AF_INET6; family = AF_INET6;
break; break;
default: default:
assert(0 && "bad address family"); CHECK(0 && "bad address family");
abort(); abort();
} }
@ -1097,7 +1096,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
ares_addr_node* servers; ares_addr_node* servers;
int r = ares_get_servers(env->cares_channel(), &servers); int r = ares_get_servers(env->cares_channel(), &servers);
assert(r == ARES_SUCCESS); CHECK_EQ(r, ARES_SUCCESS);
ares_addr_node* cur = servers; ares_addr_node* cur = servers;
@ -1106,7 +1105,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
const void* caddr = static_cast<const void*>(&cur->addr); const void* caddr = static_cast<const void*>(&cur->addr);
int err = uv_inet_ntop(cur->family, caddr, ip, sizeof(ip)); int err = uv_inet_ntop(cur->family, caddr, ip, sizeof(ip));
assert(err == 0); CHECK_EQ(err, 0);
Local<String> addr = OneByteString(env->isolate(), ip); Local<String> addr = OneByteString(env->isolate(), ip);
server_array->Set(i, addr); server_array->Set(i, addr);
@ -1121,7 +1120,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
static void SetServers(const FunctionCallbackInfo<Value>& args) { static void SetServers(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(args[0]->IsArray()); CHECK(args[0]->IsArray());
Local<Array> arr = Local<Array>::Cast(args[0]); Local<Array> arr = Local<Array>::Cast(args[0]);
@ -1138,12 +1137,12 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
int err; int err;
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < len; i++) {
assert(arr->Get(i)->IsArray()); CHECK(arr->Get(i)->IsArray());
Local<Array> elm = Local<Array>::Cast(arr->Get(i)); Local<Array> elm = Local<Array>::Cast(arr->Get(i));
assert(elm->Get(0)->Int32Value()); CHECK(elm->Get(0)->Int32Value());
assert(elm->Get(1)->IsString()); CHECK(elm->Get(1)->IsString());
int fam = elm->Get(0)->Int32Value(); int fam = elm->Get(0)->Int32Value();
node::Utf8Value ip(elm->Get(1)); node::Utf8Value ip(elm->Get(1));
@ -1160,7 +1159,7 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
err = uv_inet_pton(AF_INET6, *ip, &cur->addr); err = uv_inet_pton(AF_INET6, *ip, &cur->addr);
break; break;
default: default:
assert(0 && "Bad address family."); CHECK(0 && "Bad address family.");
abort(); abort();
} }
@ -1213,7 +1212,7 @@ static void Initialize(Handle<Object> target,
Environment* env = Environment::GetCurrent(context); Environment* env = Environment::GetCurrent(context);
int r = ares_library_init(ARES_LIB_INIT_ALL); int r = ares_library_init(ARES_LIB_INIT_ALL);
assert(r == ARES_SUCCESS); CHECK_EQ(r, ARES_SUCCESS);
struct ares_options options; struct ares_options options;
memset(&options, 0, sizeof(options)); memset(&options, 0, sizeof(options));
@ -1225,7 +1224,7 @@ static void Initialize(Handle<Object> target,
r = ares_init_options(env->cares_channel_ptr(), r = ares_init_options(env->cares_channel_ptr(),
&options, &options,
ARES_OPT_FLAGS | ARES_OPT_SOCK_STATE_CB); ARES_OPT_FLAGS | ARES_OPT_SOCK_STATE_CB);
assert(r == ARES_SUCCESS); CHECK_EQ(r, ARES_SUCCESS);
/* Initialize the timeout timer. The timer won't be started until the */ /* Initialize the timeout timer. The timer won't be started until the */
/* first socket is opened. */ /* first socket is opened. */

8
src/fs_event_wrap.cc

@ -74,7 +74,7 @@ FSEventWrap::FSEventWrap(Environment* env, Handle<Object> object)
FSEventWrap::~FSEventWrap() { FSEventWrap::~FSEventWrap() {
assert(initialized_ == false); CHECK_EQ(initialized_, false);
} }
@ -95,7 +95,7 @@ void FSEventWrap::Initialize(Handle<Object> target,
void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) { void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) {
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
new FSEventWrap(env, args.This()); new FSEventWrap(env, args.This());
} }
@ -144,7 +144,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());
assert(wrap->persistent().IsEmpty() == false); CHECK_EQ(wrap->persistent().IsEmpty(), false);
// We're in a bind here. libuv can set both UV_RENAME and UV_CHANGE but // We're in a bind here. libuv can set both UV_RENAME and UV_CHANGE but
// the Node API only lets us pass a single event to JS land. // 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,
} else if (events & UV_CHANGE) { } else if (events & UV_CHANGE) {
event_string = env->change_string(); event_string = env->change_string();
} else { } else {
assert(0 && "bad fs events flag"); CHECK(0 && "bad fs events flag");
abort(); abort();
} }

8
src/handle_wrap.cc

@ -69,7 +69,7 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
if (wrap == NULL || wrap->handle__ == NULL) if (wrap == NULL || wrap->handle__ == NULL)
return; return;
assert(!wrap->persistent().IsEmpty()); CHECK_EQ(false, wrap->persistent().IsEmpty());
uv_close(wrap->handle__, OnClose); uv_close(wrap->handle__, OnClose);
wrap->handle__ = NULL; wrap->handle__ = NULL;
@ -95,7 +95,7 @@ HandleWrap::HandleWrap(Environment* env,
HandleWrap::~HandleWrap() { HandleWrap::~HandleWrap() {
assert(persistent().IsEmpty()); CHECK(persistent().IsEmpty());
QUEUE_REMOVE(&handle_wrap_queue_); QUEUE_REMOVE(&handle_wrap_queue_);
} }
@ -106,10 +106,10 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
HandleScope scope(env->isolate()); HandleScope scope(env->isolate());
// The wrap object should still be there. // The wrap object should still be there.
assert(wrap->persistent().IsEmpty() == false); CHECK_EQ(wrap->persistent().IsEmpty(), false);
// But the handle pointer should be gone. // But the handle pointer should be gone.
assert(wrap->handle__ == NULL); CHECK_EQ(wrap->handle__, NULL);
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());

53
src/node.cc

@ -58,7 +58,6 @@
#include "v8-profiler.h" #include "v8-profiler.h"
#include "zlib.h" #include "zlib.h"
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <limits.h> // PATH_MAX #include <limits.h> // PATH_MAX
#include <locale.h> #include <locale.h>
@ -911,10 +910,10 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
void SetupAsyncListener(const FunctionCallbackInfo<Value>& args) { void SetupAsyncListener(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsFunction()); CHECK(args[1]->IsFunction());
assert(args[2]->IsFunction()); CHECK(args[2]->IsFunction());
assert(args[3]->IsFunction()); CHECK(args[3]->IsFunction());
env->set_async_listener_run_function(args[1].As<Function>()); env->set_async_listener_run_function(args[1].As<Function>());
env->set_async_listener_load_function(args[2].As<Function>()); env->set_async_listener_load_function(args[2].As<Function>());
@ -955,8 +954,8 @@ void SetupDomainUse(const FunctionCallbackInfo<Value>& args) {
process_object->Set(env->tick_callback_string(), tick_callback_function); process_object->Set(env->tick_callback_string(), tick_callback_function);
env->set_tick_callback_function(tick_callback_function); env->set_tick_callback_function(tick_callback_function);
assert(args[0]->IsArray()); CHECK(args[0]->IsArray());
assert(args[1]->IsObject()); CHECK(args[1]->IsObject());
env->set_domain_array(args[0].As<Array>()); env->set_domain_array(args[0].As<Array>());
@ -980,9 +979,9 @@ void RunMicrotasks(const FunctionCallbackInfo<Value>& args) {
void SetupNextTick(const FunctionCallbackInfo<Value>& args) { void SetupNextTick(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsFunction()); CHECK(args[1]->IsFunction());
assert(args[2]->IsObject()); CHECK(args[2]->IsObject());
// Values use to cross communicate with processNextTick. // Values use to cross communicate with processNextTick.
Local<Object> tick_info_obj = args[0].As<Object>(); Local<Object> tick_info_obj = args[0].As<Object>();
@ -1007,7 +1006,7 @@ Handle<Value> MakeDomainCallback(Environment* env,
int argc, int argc,
Handle<Value> argv[]) { Handle<Value> argv[]) {
// If you hit this assertion, you forgot to enter the v8::Context first. // If you hit this assertion, you forgot to enter the v8::Context first.
assert(env->context() == env->isolate()->GetCurrentContext()); CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
Local<Object> process = env->process_object(); Local<Object> process = env->process_object();
Local<Object> object, domain; Local<Object> object, domain;
@ -1118,7 +1117,7 @@ Handle<Value> MakeCallback(Environment* env,
return MakeDomainCallback(env, recv, callback, argc, argv); return MakeDomainCallback(env, recv, callback, argc, argv);
// If you hit this assertion, you forgot to enter the v8::Context first. // If you hit this assertion, you forgot to enter the v8::Context first.
assert(env->context() == env->isolate()->GetCurrentContext()); CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
Local<Object> process = env->process_object(); Local<Object> process = env->process_object();
@ -1185,7 +1184,7 @@ Handle<Value> MakeCallback(Environment* env,
int argc, int argc,
Handle<Value> argv[]) { Handle<Value> argv[]) {
Local<Function> callback = recv->Get(index).As<Function>(); Local<Function> callback = recv->Get(index).As<Function>();
assert(callback->IsFunction()); CHECK(callback->IsFunction());
return MakeCallback(env, recv.As<Value>(), callback, argc, argv); return MakeCallback(env, recv.As<Value>(), callback, argc, argv);
} }
@ -1197,7 +1196,7 @@ Handle<Value> MakeCallback(Environment* env,
int argc, int argc,
Handle<Value> argv[]) { Handle<Value> argv[]) {
Local<Function> callback = recv->Get(symbol).As<Function>(); Local<Function> callback = recv->Get(symbol).As<Function>();
assert(callback->IsFunction()); CHECK(callback->IsFunction());
return MakeCallback(env, recv.As<Value>(), callback, argc, argv); return MakeCallback(env, recv.As<Value>(), callback, argc, argv);
} }
@ -1337,7 +1336,7 @@ ssize_t DecodeBytes(Isolate* isolate,
if (val->IsArray()) { if (val->IsArray()) {
fprintf(stderr, "'raw' encoding (array of integers) has been removed. " fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
"Use 'binary'.\n"); "Use 'binary'.\n");
assert(0); UNREACHABLE();
return -1; return -1;
} }
@ -1414,7 +1413,7 @@ void AppendExceptionLine(Environment* env,
filename_string, filename_string,
linenum, linenum,
sourceline_string); sourceline_string);
assert(off >= 0); CHECK_GE(off, 0);
// Print wavy underline (GetUnderline is deprecated). // Print wavy underline (GetUnderline is deprecated).
for (int i = 0; i < start; i++) { for (int i = 0; i < start; i++) {
@ -1422,7 +1421,7 @@ void AppendExceptionLine(Environment* env,
static_cast<size_t>(off) >= sizeof(arrow)) { static_cast<size_t>(off) >= sizeof(arrow)) {
break; break;
} }
assert(static_cast<size_t>(off) < sizeof(arrow)); CHECK_LT(static_cast<size_t>(off), sizeof(arrow));
arrow[off++] = (sourceline_string[i] == '\t') ? '\t' : ' '; arrow[off++] = (sourceline_string[i] == '\t') ? '\t' : ' ';
} }
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
@ -1430,10 +1429,10 @@ void AppendExceptionLine(Environment* env,
static_cast<size_t>(off) >= sizeof(arrow)) { static_cast<size_t>(off) >= sizeof(arrow)) {
break; break;
} }
assert(static_cast<size_t>(off) < sizeof(arrow)); CHECK_LT(static_cast<size_t>(off), sizeof(arrow));
arrow[off++] = '^'; arrow[off++] = '^';
} }
assert(static_cast<size_t>(off - 1) <= sizeof(arrow) - 1); CHECK_LE(static_cast<size_t>(off - 1), sizeof(arrow) - 1);
arrow[off++] = '\n'; arrow[off++] = '\n';
arrow[off] = '\0'; arrow[off] = '\0';
@ -2035,7 +2034,7 @@ extern "C" void node_module_register(void* m) {
mp->nm_link = modlist_builtin; mp->nm_link = modlist_builtin;
modlist_builtin = mp; modlist_builtin = mp;
} else { } else {
assert(modpending == NULL); CHECK_EQ(modpending, NULL);
modpending = mp; modpending = mp;
} }
} }
@ -2048,7 +2047,7 @@ struct node_module* get_builtin_module(const char* name) {
break; break;
} }
assert(mp == NULL || (mp->nm_flags & NM_F_BUILTIN) != 0); CHECK(mp == NULL || (mp->nm_flags & NM_F_BUILTIN) != 0);
return (mp); return (mp);
} }
@ -2230,8 +2229,8 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
if (mod != NULL) { if (mod != NULL) {
exports = Object::New(env->isolate()); exports = Object::New(env->isolate());
// Internal bindings don't have a "module" object, only exports. // Internal bindings don't have a "module" object, only exports.
assert(mod->nm_register_func == NULL); CHECK_EQ(mod->nm_register_func, NULL);
assert(mod->nm_context_register_func != NULL); CHECK_NE(mod->nm_context_register_func, NULL);
Local<Value> unused = Undefined(env->isolate()); Local<Value> unused = Undefined(env->isolate());
mod->nm_context_register_func(exports, unused, mod->nm_context_register_func(exports, unused,
env->context(), mod->nm_priv); env->context(), mod->nm_priv);
@ -2825,8 +2824,8 @@ static void SignalExit(int signo) {
static void RawDebug(const FunctionCallbackInfo<Value>& args) { static void RawDebug(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(args.Length() == 1 && args[0]->IsString() && CHECK(args.Length() == 1 && args[0]->IsString() &&
"must be called with a single string"); "must be called with a single string");
node::Utf8Value message(args[0]); node::Utf8Value message(args[0]);
fprintf(stderr, "%s\n", *message); fprintf(stderr, "%s\n", *message);
@ -2860,7 +2859,7 @@ void LoadEnvironment(Environment* env) {
ReportException(env, try_catch); ReportException(env, try_catch);
exit(10); exit(10);
} }
assert(f_value->IsFunction()); CHECK(f_value->IsFunction());
Local<Function> f = Local<Function>::Cast(f_value); Local<Function> f = Local<Function>::Cast(f_value);
// Now we call 'f' with the 'process' variable that we've built up with // Now we call 'f' with the 'process' variable that we've built up with
@ -3675,7 +3674,7 @@ int Start(int argc, char** argv) {
InstallEarlyDebugSignalHandler(); InstallEarlyDebugSignalHandler();
#endif #endif
assert(argc > 0); CHECK_GT(argc, 0);
// Hack around with the argv pointer. Used for process.title = "blah". // Hack around with the argv pointer. Used for process.title = "blah".
argv = uv_setup_args(argc, argv); argv = uv_setup_args(argc, argv);

25
src/node_buffer.cc

@ -30,7 +30,6 @@
#include "v8-profiler.h" #include "v8-profiler.h"
#include "v8.h" #include "v8.h"
#include <assert.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
@ -47,7 +46,7 @@
char* obj_data = static_cast<char*>( \ char* obj_data = static_cast<char*>( \
obj->GetIndexedPropertiesExternalArrayData()); \ obj->GetIndexedPropertiesExternalArrayData()); \
if (obj_length > 0) \ if (obj_length > 0) \
assert(obj_data != NULL); CHECK_NE(obj_data, NULL);
#define SLICE_START_END(start_arg, end_arg, end_max) \ #define SLICE_START_END(start_arg, end_arg, end_max) \
size_t start; \ size_t start; \
@ -91,7 +90,7 @@ bool HasInstance(Handle<Object> obj) {
char* Data(Handle<Value> val) { char* Data(Handle<Value> val) {
assert(val->IsObject()); CHECK(val->IsObject());
// Use a fully qualified name here to work around a bug in gcc 4.2. // Use a fully qualified name here to work around a bug in gcc 4.2.
// It mistakes an unadorned call to Data() for the v8::String::Data type. // It mistakes an unadorned call to Data() for the v8::String::Data type.
return node::Buffer::Data(val.As<Object>()); return node::Buffer::Data(val.As<Object>());
@ -99,19 +98,19 @@ char* Data(Handle<Value> val) {
char* Data(Handle<Object> obj) { char* Data(Handle<Object> obj) {
assert(obj->HasIndexedPropertiesInExternalArrayData()); CHECK(obj->HasIndexedPropertiesInExternalArrayData());
return static_cast<char*>(obj->GetIndexedPropertiesExternalArrayData()); return static_cast<char*>(obj->GetIndexedPropertiesExternalArrayData());
} }
size_t Length(Handle<Value> val) { size_t Length(Handle<Value> val) {
assert(val->IsObject()); CHECK(val->IsObject());
return Length(val.As<Object>()); return Length(val.As<Object>());
} }
size_t Length(Handle<Object> obj) { size_t Length(Handle<Object> obj) {
assert(obj->HasIndexedPropertiesInExternalArrayData()); CHECK(obj->HasIndexedPropertiesInExternalArrayData());
return obj->GetIndexedPropertiesExternalArrayDataLength(); return obj->GetIndexedPropertiesExternalArrayDataLength();
} }
@ -141,7 +140,7 @@ Local<Object> New(Isolate* isolate, size_t length) {
Local<Object> New(Environment* env, size_t length) { Local<Object> New(Environment* env, size_t length) {
EscapableHandleScope scope(env->isolate()); EscapableHandleScope scope(env->isolate());
assert(length <= kMaxLength); CHECK_LE(length, kMaxLength);
Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length); Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length);
Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg); Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg);
@ -177,7 +176,7 @@ Local<Object> New(Isolate* isolate, const char* data, size_t length) {
Local<Object> New(Environment* env, const char* data, size_t length) { Local<Object> New(Environment* env, const char* data, size_t length) {
EscapableHandleScope scope(env->isolate()); EscapableHandleScope scope(env->isolate());
assert(length <= kMaxLength); CHECK_LE(length, kMaxLength);
Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length); Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length);
Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg); Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg);
@ -220,7 +219,7 @@ Local<Object> New(Environment* env,
void* hint) { void* hint) {
EscapableHandleScope scope(env->isolate()); EscapableHandleScope scope(env->isolate());
assert(length <= kMaxLength); CHECK_LE(length, kMaxLength);
Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length); Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length);
Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg); Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg);
@ -242,7 +241,7 @@ Local<Object> Use(Isolate* isolate, char* data, uint32_t length) {
Local<Object> Use(Environment* env, char* data, uint32_t length) { Local<Object> Use(Environment* env, char* data, uint32_t length) {
EscapableHandleScope scope(env->isolate()); EscapableHandleScope scope(env->isolate());
assert(length <= kMaxLength); CHECK_LE(length, kMaxLength);
Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length); Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length);
Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg); Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg);
@ -591,13 +590,13 @@ void Compare(const FunctionCallbackInfo<Value> &args) {
void SetupBufferJS(const FunctionCallbackInfo<Value>& args) { void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(args[0]->IsFunction()); CHECK(args[0]->IsFunction());
Local<Function> bv = args[0].As<Function>(); Local<Function> bv = args[0].As<Function>();
env->set_buffer_constructor_function(bv); env->set_buffer_constructor_function(bv);
Local<Value> proto_v = bv->Get(env->prototype_string()); Local<Value> proto_v = bv->Get(env->prototype_string());
assert(proto_v->IsObject()); CHECK(proto_v->IsObject());
Local<Object> proto = proto_v.As<Object>(); Local<Object> proto = proto_v.As<Object>();
@ -622,7 +621,7 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
Uint32::New(env->isolate(), 0), Uint32::New(env->isolate(), 0),
v8::ReadOnly); v8::ReadOnly);
assert(args[1]->IsObject()); CHECK(args[1]->IsObject());
Local<Object> internal = args[1].As<Object>(); Local<Object> internal = args[1].As<Object>();
ASSERT(internal->IsObject()); ASSERT(internal->IsObject());

4
src/node_contextify.cc

@ -184,7 +184,7 @@ class ContextifyContext {
"binding:script"); "binding:script");
Local<Script> script = Script::Compile(code, fname); Local<Script> script = Script::Compile(code, fname);
clone_property_method = Local<Function>::Cast(script->Run()); clone_property_method = Local<Function>::Cast(script->Run());
assert(clone_property_method->IsFunction()); CHECK(clone_property_method->IsFunction());
} }
Local<Value> args[] = { global, key, sandbox }; Local<Value> args[] = { global, key, sandbox };
clone_property_method->Call(global, ARRAY_SIZE(args), args); clone_property_method->Call(global, ARRAY_SIZE(args), args);
@ -276,7 +276,7 @@ class ContextifyContext {
FIXED_ONE_BYTE_STRING(env->isolate(), "_contextifyHidden"); FIXED_ONE_BYTE_STRING(env->isolate(), "_contextifyHidden");
// Don't allow contextifying a sandbox multiple times. // Don't allow contextifying a sandbox multiple times.
assert(sandbox->GetHiddenValue(hidden_name).IsEmpty()); CHECK(sandbox->GetHiddenValue(hidden_name).IsEmpty());
TryCatch try_catch; TryCatch try_catch;
ContextifyContext* context = new ContextifyContext(env, sandbox); ContextifyContext* context = new ContextifyContext(env, sandbox);

48
src/node_crypto.cc

@ -168,8 +168,8 @@ static void crypto_lock_init(void) {
static void crypto_lock_cb(int mode, int n, const char* file, int line) { static void crypto_lock_cb(int mode, int n, const char* file, int line) {
assert((mode & CRYPTO_LOCK) || (mode & CRYPTO_UNLOCK)); CHECK((mode & CRYPTO_LOCK) || (mode & CRYPTO_UNLOCK));
assert((mode & CRYPTO_READ) || (mode & CRYPTO_WRITE)); CHECK((mode & CRYPTO_READ) || (mode & CRYPTO_WRITE));
if (mode & CRYPTO_LOCK) { if (mode & CRYPTO_LOCK) {
if (mode & CRYPTO_READ) if (mode & CRYPTO_READ)
@ -669,7 +669,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) { void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
SecureContext* sc = Unwrap<SecureContext>(args.Holder()); SecureContext* sc = Unwrap<SecureContext>(args.Holder());
assert(sc->ca_store_ == NULL); CHECK_EQ(sc->ca_store_, NULL);
if (!root_cert_store) { if (!root_cert_store) {
root_cert_store = X509_STORE_new(); root_cert_store = X509_STORE_new();
@ -1149,10 +1149,10 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
int rv; int rv;
ext = X509_get_ext(cert, index); ext = X509_get_ext(cert, index);
assert(ext != NULL); CHECK_NE(ext, NULL);
rv = X509V3_EXT_print(bio, ext, 0, 0); rv = X509V3_EXT_print(bio, ext, 0, 0);
assert(rv == 1); CHECK_EQ(rv, 1);
BIO_get_mem_ptr(bio, &mem); BIO_get_mem_ptr(bio, &mem);
info->Set(keys[i], info->Set(keys[i],
@ -1386,7 +1386,7 @@ void SSLWrap<Base>::GetSession(const FunctionCallbackInfo<Value>& args) {
return; return;
int slen = i2d_SSL_SESSION(sess, NULL); int slen = i2d_SSL_SESSION(sess, NULL);
assert(slen > 0); CHECK_GT(slen, 0);
unsigned char* sbuf = new unsigned char[slen]; unsigned char* sbuf = new unsigned char[slen];
unsigned char* p = sbuf; unsigned char* p = sbuf;
@ -1806,7 +1806,7 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) {
// OpenSSL takes control of the pointer after accepting it // OpenSSL takes control of the pointer after accepting it
char* data = reinterpret_cast<char*>(malloc(len)); char* data = reinterpret_cast<char*>(malloc(len));
assert(data != NULL); CHECK_NE(data, NULL);
memcpy(data, resp, len); memcpy(data, resp, len);
if (!SSL_set_tlsext_status_ocsp_resp(s, data, len)) if (!SSL_set_tlsext_status_ocsp_resp(s, data, len))
@ -1930,7 +1930,7 @@ int Connection::HandleSSLError(const char* func,
BUF_MEM* mem; BUF_MEM* mem;
BIO *bio; BIO *bio;
assert(err == SSL_ERROR_SSL || err == SSL_ERROR_SYSCALL); CHECK(err == SSL_ERROR_SSL || err == SSL_ERROR_SYSCALL);
// XXX We need to drain the error queue for this thread or else OpenSSL // XXX We need to drain the error queue for this thread or else OpenSSL
// has the possibility of blocking connections? This problem is not well // has the possibility of blocking connections? This problem is not well
@ -1963,7 +1963,7 @@ void Connection::ClearError() {
// We should clear the error in JS-land // We should clear the error in JS-land
Local<String> error_key = ssl_env()->error_string(); Local<String> error_key = ssl_env()->error_string();
Local<Value> error = object()->Get(error_key); Local<Value> error = object()->Get(error_key);
assert(error->BooleanValue() == false); CHECK_EQ(error->BooleanValue(), false);
#endif // NDEBUG #endif // NDEBUG
} }
@ -2477,7 +2477,7 @@ void CipherBase::Initialize(Environment* env, Handle<Object> target) {
void CipherBase::New(const FunctionCallbackInfo<Value>& args) { void CipherBase::New(const FunctionCallbackInfo<Value>& args) {
assert(args.IsConstructCall() == true); CHECK_EQ(args.IsConstructCall(), true);
CipherKind kind = args[0]->IsTrue() ? kCipher : kDecipher; CipherKind kind = args[0]->IsTrue() ? kCipher : kDecipher;
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
new CipherBase(env, args.This(), kind); new CipherBase(env, args.This(), kind);
@ -2489,7 +2489,7 @@ void CipherBase::Init(const char* cipher_type,
int key_buf_len) { int key_buf_len) {
HandleScope scope(env()->isolate()); HandleScope scope(env()->isolate());
assert(cipher_ == NULL); CHECK_EQ(cipher_, NULL);
cipher_ = EVP_get_cipherbyname(cipher_type); cipher_ = EVP_get_cipherbyname(cipher_type);
if (cipher_ == NULL) { if (cipher_ == NULL) {
return env()->ThrowError("Unknown cipher"); return env()->ThrowError("Unknown cipher");
@ -2851,7 +2851,7 @@ void Hmac::New(const FunctionCallbackInfo<Value>& args) {
void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) { void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) {
HandleScope scope(env()->isolate()); HandleScope scope(env()->isolate());
assert(md_ == NULL); CHECK_EQ(md_, NULL);
md_ = EVP_get_digestbyname(hash_type); md_ = EVP_get_digestbyname(hash_type);
if (md_ == NULL) { if (md_ == NULL) {
return env()->ThrowError("Unknown message digest"); return env()->ThrowError("Unknown message digest");
@ -2994,7 +2994,7 @@ void Hash::New(const FunctionCallbackInfo<Value>& args) {
bool Hash::HashInit(const char* hash_type) { bool Hash::HashInit(const char* hash_type) {
assert(md_ == NULL); CHECK_EQ(md_, NULL);
md_ = EVP_get_digestbyname(hash_type); md_ = EVP_get_digestbyname(hash_type);
if (md_ == NULL) if (md_ == NULL)
return false; return false;
@ -3137,7 +3137,7 @@ void Sign::New(const FunctionCallbackInfo<Value>& args) {
SignBase::Error Sign::SignInit(const char* sign_type) { SignBase::Error Sign::SignInit(const char* sign_type) {
assert(md_ == NULL); CHECK_EQ(md_, NULL);
md_ = EVP_get_digestbyname(sign_type); md_ = EVP_get_digestbyname(sign_type);
if (!md_) if (!md_)
return kSignUnknownDigest; return kSignUnknownDigest;
@ -3314,7 +3314,7 @@ void Verify::New(const FunctionCallbackInfo<Value>& args) {
SignBase::Error Verify::VerifyInit(const char* verify_type) { SignBase::Error Verify::VerifyInit(const char* verify_type) {
assert(md_ == NULL); CHECK_EQ(md_, NULL);
md_ = EVP_get_digestbyname(verify_type); md_ = EVP_get_digestbyname(verify_type);
if (md_ == NULL) if (md_ == NULL)
return kSignUnknownDigest; return kSignUnknownDigest;
@ -3485,7 +3485,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
hlen, hlen,
args[1], args[1],
encoding); encoding);
assert(hwritten == hlen); CHECK_EQ(hwritten, hlen);
} else { } else {
hbuf = Buffer::Data(args[1]); hbuf = Buffer::Data(args[1]);
} }
@ -3943,14 +3943,14 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
} }
BN_free(key); BN_free(key);
assert(size >= 0); CHECK_GE(size, 0);
// DH_size returns number of bytes in a prime number // DH_size returns number of bytes in a prime number
// DH_compute_key returns number of bytes in a remainder of exponent, which // DH_compute_key returns number of bytes in a remainder of exponent, which
// may have less bytes than a prime number. Therefore add 0-padding to the // may have less bytes than a prime number. Therefore add 0-padding to the
// allocated buffer. // allocated buffer.
if (size != dataSize) { if (size != dataSize) {
assert(dataSize > size); CHECK(dataSize > size);
memmove(data + dataSize - size, data, size); memmove(data + dataSize - size, data, size);
memset(data, 0, dataSize - size); memset(data, 0, dataSize - size);
} }
@ -4363,7 +4363,7 @@ void EIO_PBKDF2After(PBKDF2Request* req, Local<Value> argv[2]) {
void EIO_PBKDF2After(uv_work_t* work_req, int status) { void EIO_PBKDF2After(uv_work_t* work_req, int status) {
assert(status == 0); CHECK_EQ(status, 0);
PBKDF2Request* req = ContainerOf(&PBKDF2Request::work_req_, work_req); PBKDF2Request* req = ContainerOf(&PBKDF2Request::work_req_, work_req);
Environment* env = req->env(); Environment* env = req->env();
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
@ -4600,7 +4600,7 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) {
void RandomBytesAfter(uv_work_t* work_req, int status) { void RandomBytesAfter(uv_work_t* work_req, int status) {
assert(status == 0); CHECK_EQ(status, 0);
RandomBytesRequest* req = RandomBytesRequest* req =
ContainerOf(&RandomBytesRequest::work_req_, work_req); ContainerOf(&RandomBytesRequest::work_req_, work_req);
Environment* env = req->env(); Environment* env = req->env();
@ -4789,7 +4789,7 @@ void Certificate::VerifySpkac(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().Set(i); return args.GetReturnValue().Set(i);
char* data = Buffer::Data(args[0]); char* data = Buffer::Data(args[0]);
assert(data != NULL); CHECK_NE(data, NULL);
i = certificate->VerifySpkac(data, length); i = certificate->VerifySpkac(data, length);
@ -4853,7 +4853,7 @@ void Certificate::ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().SetEmptyString(); return args.GetReturnValue().SetEmptyString();
char* data = Buffer::Data(args[0]); char* data = Buffer::Data(args[0]);
assert(data != NULL); CHECK_NE(data, NULL);
const char* pkey = certificate->ExportPublicKey(data, length); const char* pkey = certificate->ExportPublicKey(data, length);
if (pkey == NULL) if (pkey == NULL)
@ -4896,7 +4896,7 @@ void Certificate::ExportChallenge(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().SetEmptyString(); return args.GetReturnValue().SetEmptyString();
char* data = Buffer::Data(args[0]); char* data = Buffer::Data(args[0]);
assert(data != NULL); CHECK_NE(data, NULL);
const char* cert = crt->ExportChallenge(data, len); const char* cert = crt->ExportChallenge(data, len);
if (cert == NULL) if (cert == NULL)
@ -4927,7 +4927,7 @@ void InitCryptoOnce() {
STACK_OF(SSL_COMP)* comp_methods = SSL_COMP_get_compression_methods(); STACK_OF(SSL_COMP)* comp_methods = SSL_COMP_get_compression_methods();
#endif #endif
sk_SSL_COMP_zero(comp_methods); sk_SSL_COMP_zero(comp_methods);
assert(sk_SSL_COMP_num(comp_methods) == 0); CHECK_EQ(sk_SSL_COMP_num(comp_methods), 0);
#endif #endif
#ifndef OPENSSL_NO_ENGINE #ifndef OPENSSL_NO_ENGINE

4
src/node_crypto.h

@ -139,7 +139,7 @@ class SecureContext : public BaseObject {
cert_ = NULL; cert_ = NULL;
issuer_ = NULL; issuer_ = NULL;
} else { } else {
assert(ca_store_ == NULL); CHECK_EQ(ca_store_, NULL);
} }
} }
}; };
@ -161,7 +161,7 @@ class SSLWrap {
session_callbacks_(false), session_callbacks_(false),
new_session_wait_(false) { new_session_wait_(false) {
ssl_ = SSL_new(sc->ctx_); ssl_ = SSL_new(sc->ctx_);
assert(ssl_ != NULL); CHECK_NE(ssl_, NULL);
} }
~SSLWrap() { ~SSLWrap() {

32
src/node_crypto_bio.cc

@ -21,6 +21,8 @@
#include "node_crypto_bio.h" #include "node_crypto_bio.h"
#include "openssl/bio.h" #include "openssl/bio.h"
#include "util.h"
#include "util-inl.h"
#include <string.h> #include <string.h>
namespace node { namespace node {
@ -185,11 +187,11 @@ long NodeBIO::Ctrl(BIO* bio, int cmd, long num, void* ptr) {
*reinterpret_cast<void**>(ptr) = NULL; *reinterpret_cast<void**>(ptr) = NULL;
break; break;
case BIO_C_SET_BUF_MEM: case BIO_C_SET_BUF_MEM:
assert(0 && "Can't use SET_BUF_MEM_PTR with NodeBIO"); CHECK(0 && "Can't use SET_BUF_MEM_PTR with NodeBIO");
abort(); abort();
break; break;
case BIO_C_GET_BUF_MEM_PTR: case BIO_C_GET_BUF_MEM_PTR:
assert(0 && "Can't use GET_BUF_MEM_PTR with NodeBIO"); CHECK(0 && "Can't use GET_BUF_MEM_PTR with NodeBIO");
ret = 0; ret = 0;
break; break;
case BIO_CTRL_GET_CLOSE: case BIO_CTRL_GET_CLOSE:
@ -244,7 +246,7 @@ size_t NodeBIO::Read(char* out, size_t size) {
size_t left = size; size_t left = size;
while (bytes_read < expected) { while (bytes_read < expected) {
assert(read_head_->read_pos_ <= read_head_->write_pos_); CHECK_LE(read_head_->read_pos_, read_head_->write_pos_);
size_t avail = read_head_->write_pos_ - read_head_->read_pos_; size_t avail = read_head_->write_pos_ - read_head_->read_pos_;
if (avail > left) if (avail > left)
avail = left; avail = left;
@ -261,7 +263,7 @@ size_t NodeBIO::Read(char* out, size_t size) {
TryMoveReadHead(); TryMoveReadHead();
} }
assert(expected == bytes_read); CHECK_EQ(expected, bytes_read);
length_ -= bytes_read; length_ -= bytes_read;
// Free all empty buffers, but write_head's child // Free all empty buffers, but write_head's child
@ -283,8 +285,8 @@ void NodeBIO::FreeEmpty() {
Buffer* prev = child; Buffer* prev = child;
while (cur != read_head_) { while (cur != read_head_) {
assert(cur != write_head_); CHECK_NE(cur, write_head_);
assert(cur->write_pos_ == cur->read_pos_); CHECK_EQ(cur->write_pos_, cur->read_pos_);
Buffer* next = cur->next_; Buffer* next = cur->next_;
delete cur; delete cur;
@ -301,7 +303,7 @@ size_t NodeBIO::IndexOf(char delim, size_t limit) {
Buffer* current = read_head_; Buffer* current = read_head_;
while (bytes_read < max) { while (bytes_read < max) {
assert(current->read_pos_ <= current->write_pos_); CHECK_LE(current->read_pos_, current->write_pos_);
size_t avail = current->write_pos_ - current->read_pos_; size_t avail = current->write_pos_ - current->read_pos_;
if (avail > left) if (avail > left)
avail = left; avail = left;
@ -328,7 +330,7 @@ size_t NodeBIO::IndexOf(char delim, size_t limit) {
current = current->next_; current = current->next_;
} }
} }
assert(max == bytes_read); CHECK_EQ(max, bytes_read);
return max; return max;
} }
@ -343,7 +345,7 @@ void NodeBIO::Write(const char* data, size_t size) {
while (left > 0) { while (left > 0) {
size_t to_write = left; size_t to_write = left;
assert(write_head_->write_pos_ <= write_head_->len_); CHECK_LE(write_head_->write_pos_, write_head_->len_);
size_t avail = write_head_->len_ - write_head_->write_pos_; size_t avail = write_head_->len_ - write_head_->write_pos_;
if (to_write > avail) if (to_write > avail)
@ -359,11 +361,11 @@ void NodeBIO::Write(const char* data, size_t size) {
offset += to_write; offset += to_write;
length_ += to_write; length_ += to_write;
write_head_->write_pos_ += to_write; write_head_->write_pos_ += to_write;
assert(write_head_->write_pos_ <= write_head_->len_); CHECK_LE(write_head_->write_pos_, write_head_->len_);
// Go to next buffer if there still are some bytes to write // Go to next buffer if there still are some bytes to write
if (left != 0) { if (left != 0) {
assert(write_head_->write_pos_ == write_head_->len_); CHECK_EQ(write_head_->write_pos_, write_head_->len_);
TryAllocateForWrite(left); TryAllocateForWrite(left);
write_head_ = write_head_->next_; write_head_ = write_head_->next_;
@ -372,7 +374,7 @@ void NodeBIO::Write(const char* data, size_t size) {
TryMoveReadHead(); TryMoveReadHead();
} }
} }
assert(left == 0); CHECK_EQ(left, 0);
} }
@ -392,7 +394,7 @@ char* NodeBIO::PeekWritable(size_t* size) {
void NodeBIO::Commit(size_t size) { void NodeBIO::Commit(size_t size) {
write_head_->write_pos_ += size; write_head_->write_pos_ += size;
length_ += size; length_ += size;
assert(write_head_->write_pos_ <= write_head_->len_); CHECK_LE(write_head_->write_pos_, write_head_->len_);
// Allocate new buffer if write head is full, // Allocate new buffer if write head is full,
// and there're no other place to go // and there're no other place to go
@ -437,7 +439,7 @@ void NodeBIO::Reset() {
return; return;
while (read_head_->read_pos_ != read_head_->write_pos_) { while (read_head_->read_pos_ != read_head_->write_pos_) {
assert(read_head_->write_pos_ > read_head_->read_pos_); CHECK(read_head_->write_pos_ > read_head_->read_pos_);
length_ -= read_head_->write_pos_ - read_head_->read_pos_; length_ -= read_head_->write_pos_ - read_head_->read_pos_;
read_head_->write_pos_ = 0; read_head_->write_pos_ = 0;
@ -446,7 +448,7 @@ void NodeBIO::Reset() {
read_head_ = read_head_->next_; read_head_ = read_head_->next_;
} }
write_head_ = read_head_; write_head_ = read_head_;
assert(length_ == 0); CHECK_EQ(length_, 0);
} }

5
src/node_crypto_bio.h

@ -23,7 +23,8 @@
#define SRC_NODE_CRYPTO_BIO_H_ #define SRC_NODE_CRYPTO_BIO_H_
#include "openssl/bio.h" #include "openssl/bio.h"
#include <assert.h> #include "util.h"
#include "util-inl.h"
namespace node { namespace node {
@ -88,7 +89,7 @@ class NodeBIO {
} }
static inline NodeBIO* FromBIO(BIO* bio) { static inline NodeBIO* FromBIO(BIO* bio) {
assert(bio->ptr != NULL); CHECK_NE(bio->ptr, NULL);
return static_cast<NodeBIO*>(bio->ptr); return static_cast<NodeBIO*>(bio->ptr);
} }

5
src/node_crypto_clienthello-inl.h

@ -22,7 +22,8 @@
#ifndef SRC_NODE_CRYPTO_CLIENTHELLO_INL_H_ #ifndef SRC_NODE_CRYPTO_CLIENTHELLO_INL_H_
#define SRC_NODE_CRYPTO_CLIENTHELLO_INL_H_ #define SRC_NODE_CRYPTO_CLIENTHELLO_INL_H_
#include <assert.h> #include "util.h"
#include "util-inl.h"
namespace node { namespace node {
@ -45,7 +46,7 @@ inline void ClientHelloParser::Start(ClientHelloParser::OnHelloCb onhello_cb,
return; return;
Reset(); Reset();
assert(onhello_cb != NULL); CHECK_NE(onhello_cb, NULL);
state_ = kWaiting; state_ = kWaiting;
onhello_cb_ = onhello_cb; onhello_cb_ = onhello_cb;

15
src/node_file.cc

@ -34,7 +34,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
@ -116,7 +115,7 @@ static inline bool IsInt64(double x) {
static void After(uv_fs_t *req) { static void After(uv_fs_t *req) {
FSReqWrap* req_wrap = static_cast<FSReqWrap*>(req->data); FSReqWrap* req_wrap = static_cast<FSReqWrap*>(req->data);
assert(&req_wrap->req_ == req); CHECK_EQ(&req_wrap->req_, req);
req_wrap->ReleaseEarly(); // Free memory that's no longer used now. req_wrap->ReleaseEarly(); // Free memory that's no longer used now.
Environment* env = req_wrap->env(); Environment* env = req_wrap->env();
@ -234,7 +233,7 @@ static void After(uv_fs_t *req) {
break; break;
default: default:
assert(0 && "Unhandled eio response"); CHECK(0 && "Unhandled eio response");
} }
} }
@ -330,7 +329,7 @@ static void Close(const FunctionCallbackInfo<Value>& args) {
Local<Value> BuildStatsObject(Environment* env, const uv_stat_t* s) { Local<Value> BuildStatsObject(Environment* env, const uv_stat_t* s) {
// If you hit this assertion, you forgot to enter the v8::Context first. // If you hit this assertion, you forgot to enter the v8::Context first.
assert(env->context() == env->isolate()->GetCurrentContext()); CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
EscapableHandleScope handle_scope(env->isolate()); EscapableHandleScope handle_scope(env->isolate());
@ -699,7 +698,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
} else { } else {
SYNC_CALL(readdir, *path, *path, 0 /*flags*/) SYNC_CALL(readdir, *path, *path, 0 /*flags*/)
assert(SYNC_REQ.result >= 0); CHECK_GE(SYNC_REQ.result, 0);
int r; int r;
Local<Array> names = Array::New(env->isolate(), 0); Local<Array> names = Array::New(env->isolate(), 0);
@ -763,8 +762,8 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
static void WriteBuffer(const FunctionCallbackInfo<Value>& args) { static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(args[0]->IsInt32()); CHECK(args[0]->IsInt32());
assert(Buffer::HasInstance(args[1])); CHECK(Buffer::HasInstance(args[1]));
int fd = args[0]->Int32Value(); int fd = args[0]->Int32Value();
Local<Object> obj = args[1].As<Object>(); Local<Object> obj = args[1].As<Object>();
@ -1090,7 +1089,7 @@ static void FUTimes(const FunctionCallbackInfo<Value>& args) {
void FSInitialize(const FunctionCallbackInfo<Value>& args) { void FSInitialize(const FunctionCallbackInfo<Value>& args) {
Local<Function> stats_constructor = args[0].As<Function>(); Local<Function> stats_constructor = args[0].As<Function>();
assert(stats_constructor->IsFunction()); CHECK(stats_constructor->IsFunction());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
env->set_fs_stats_constructor_function(stats_constructor); env->set_fs_stats_constructor_function(stats_constructor);

26
src/node_http_parser.cc

@ -213,8 +213,8 @@ class Parser : public BaseObject {
fields_[num_fields_ - 1].Reset(); fields_[num_fields_ - 1].Reset();
} }
assert(num_fields_ < static_cast<int>(ARRAY_SIZE(fields_))); CHECK_LT(num_fields_, static_cast<int>(ARRAY_SIZE(fields_)));
assert(num_fields_ == num_values_ + 1); CHECK_EQ(num_fields_, num_values_ + 1);
fields_[num_fields_ - 1].Update(at, length); fields_[num_fields_ - 1].Update(at, length);
@ -229,8 +229,8 @@ class Parser : public BaseObject {
values_[num_values_ - 1].Reset(); values_[num_values_ - 1].Reset();
} }
assert(num_values_ < static_cast<int>(ARRAY_SIZE(values_))); CHECK_LT(num_values_, static_cast<int>(ARRAY_SIZE(values_)));
assert(num_values_ == num_fields_); CHECK_EQ(num_values_, num_fields_);
values_[num_values_ - 1].Update(at, length); values_[num_values_ - 1].Update(at, length);
@ -353,7 +353,7 @@ class Parser : public BaseObject {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
http_parser_type type = http_parser_type type =
static_cast<http_parser_type>(args[0]->Int32Value()); static_cast<http_parser_type>(args[0]->Int32Value());
assert(type == HTTP_REQUEST || type == HTTP_RESPONSE); CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE);
new Parser(env, args.This(), type); new Parser(env, args.This(), type);
} }
@ -383,10 +383,10 @@ class Parser : public BaseObject {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
Parser* parser = Unwrap<Parser>(args.Holder()); Parser* parser = Unwrap<Parser>(args.Holder());
assert(parser->current_buffer_.IsEmpty()); CHECK(parser->current_buffer_.IsEmpty());
assert(parser->current_buffer_len_ == 0); CHECK_EQ(parser->current_buffer_len_, 0);
assert(parser->current_buffer_data_ == NULL); CHECK_EQ(parser->current_buffer_data_, NULL);
assert(Buffer::HasInstance(args[0]) == true); CHECK_EQ(Buffer::HasInstance(args[0]), true);
Local<Object> buffer_obj = args[0].As<Object>(); Local<Object> buffer_obj = args[0].As<Object>();
char* buffer_data = Buffer::Data(buffer_obj); char* buffer_data = Buffer::Data(buffer_obj);
@ -438,7 +438,7 @@ class Parser : public BaseObject {
Parser* parser = Unwrap<Parser>(args.Holder()); Parser* parser = Unwrap<Parser>(args.Holder());
assert(parser->current_buffer_.IsEmpty()); CHECK(parser->current_buffer_.IsEmpty());
parser->got_exception_ = false; parser->got_exception_ = false;
int rv = http_parser_execute(&(parser->parser_), &settings, NULL, 0); int rv = http_parser_execute(&(parser->parser_), &settings, NULL, 0);
@ -466,10 +466,10 @@ class Parser : public BaseObject {
http_parser_type type = http_parser_type type =
static_cast<http_parser_type>(args[0]->Int32Value()); static_cast<http_parser_type>(args[0]->Int32Value());
assert(type == HTTP_REQUEST || type == HTTP_RESPONSE); CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE);
Parser* parser = Unwrap<Parser>(args.Holder()); Parser* parser = Unwrap<Parser>(args.Holder());
// Should always be called from the same context. // Should always be called from the same context.
assert(env == parser->env()); CHECK_EQ(env, parser->env());
parser->Init(type); parser->Init(type);
} }
@ -479,7 +479,7 @@ class Parser : public BaseObject {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
Parser* parser = Unwrap<Parser>(args.Holder()); Parser* parser = Unwrap<Parser>(args.Holder());
// Should always be called from the same context. // Should always be called from the same context.
assert(env == parser->env()); CHECK_EQ(env, parser->env());
http_parser_pause(&parser->parser_, should_pause); http_parser_pause(&parser->parser_, should_pause);
} }

1
src/node_internals.h

@ -28,7 +28,6 @@
#include "uv.h" #include "uv.h"
#include "v8.h" #include "v8.h"
#include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>

7
src/node_stat_watcher.cc

@ -27,7 +27,6 @@
#include "util.h" #include "util.h"
#include "util-inl.h" #include "util-inl.h"
#include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -85,7 +84,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
const uv_stat_t* prev, const uv_stat_t* prev,
const uv_stat_t* curr) { const uv_stat_t* curr) {
StatWatcher* wrap = static_cast<StatWatcher*>(handle->data); StatWatcher* wrap = static_cast<StatWatcher*>(handle->data);
assert(wrap->watcher_ == handle); CHECK_EQ(wrap->watcher_, handle);
Environment* env = wrap->env(); Environment* env = wrap->env();
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());
@ -99,14 +98,14 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
void StatWatcher::New(const FunctionCallbackInfo<Value>& args) { void StatWatcher::New(const FunctionCallbackInfo<Value>& args) {
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
new StatWatcher(env, args.This()); new StatWatcher(env, args.This());
} }
void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) { void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) {
assert(args.Length() == 3); CHECK_EQ(args.Length(), 3);
StatWatcher* wrap = Unwrap<StatWatcher>(args.Holder()); StatWatcher* wrap = Unwrap<StatWatcher>(args.Holder());
node::Utf8Value path(args[0]); node::Utf8Value path(args[0]);

1
src/node_watchdog.cc

@ -23,7 +23,6 @@
#include "env.h" #include "env.h"
#include "env-inl.h" #include "env-inl.h"
#include "util.h" #include "util.h"
#include <assert.h>
namespace node { namespace node {

2
src/node_win32_etw_provider-inl.h

@ -113,7 +113,7 @@ extern int events_enabled;
sizeof(dataDescriptors) / \ sizeof(dataDescriptors) / \
sizeof(*dataDescriptors), \ sizeof(*dataDescriptors), \
dataDescriptors); \ dataDescriptors); \
assert(status == ERROR_SUCCESS); CHECK_EQ(status, ERROR_SUCCESS);
void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req, void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req,

2
src/node_win32_etw_provider.cc

@ -183,7 +183,7 @@ void init_etw() {
etw_events_enable_callback, etw_events_enable_callback,
NULL, NULL,
&node_provider); &node_provider);
assert(status == ERROR_SUCCESS); CHECK_EQ(status, ERROR_SUCCESS);
} }
} }
} }

50
src/node_zlib.cc

@ -94,7 +94,7 @@ class ZCtx : public AsyncWrap {
~ZCtx() { ~ZCtx() {
assert(!write_in_progress_ && "write in progress"); CHECK_EQ(false, write_in_progress_ && "write in progress");
Close(); Close();
} }
@ -105,8 +105,8 @@ class ZCtx : public AsyncWrap {
} }
pending_close_ = false; pending_close_ = false;
assert(init_done_ && "close before init"); CHECK(init_done_ && "close before init");
assert(mode_ <= UNZIP); CHECK_LE(mode_, UNZIP);
if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) { if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) {
(void)deflateEnd(&strm_); (void)deflateEnd(&strm_);
@ -136,18 +136,18 @@ class ZCtx : public AsyncWrap {
// write(flush, in, in_off, in_len, out, out_off, out_len) // write(flush, in, in_off, in_len, out, out_off, out_len)
template <bool async> template <bool async>
static void Write(const FunctionCallbackInfo<Value>& args) { static void Write(const FunctionCallbackInfo<Value>& args) {
assert(args.Length() == 7); CHECK_EQ(args.Length(), 7);
ZCtx* ctx = Unwrap<ZCtx>(args.Holder()); ZCtx* ctx = Unwrap<ZCtx>(args.Holder());
assert(ctx->init_done_ && "write before init"); CHECK(ctx->init_done_ && "write before init");
assert(ctx->mode_ != NONE && "already finalized"); CHECK(ctx->mode_ != NONE && "already finalized");
assert(!ctx->write_in_progress_ && "write already in progress"); CHECK_EQ(false, ctx->write_in_progress_ && "write already in progress");
assert(!ctx->pending_close_ && "close is pending"); CHECK_EQ(false, ctx->pending_close_ && "close is pending");
ctx->write_in_progress_ = true; ctx->write_in_progress_ = true;
ctx->Ref(); ctx->Ref();
assert(!args[0]->IsUndefined() && "must provide flush value"); CHECK_EQ(false, args[0]->IsUndefined() && "must provide flush value");
unsigned int flush = args[0]->Uint32Value(); unsigned int flush = args[0]->Uint32Value();
@ -157,7 +157,7 @@ class ZCtx : public AsyncWrap {
flush != Z_FULL_FLUSH && flush != Z_FULL_FLUSH &&
flush != Z_FINISH && flush != Z_FINISH &&
flush != Z_BLOCK) { flush != Z_BLOCK) {
assert(0 && "Invalid flush value"); CHECK(0 && "Invalid flush value");
} }
Bytef *in; Bytef *in;
@ -171,21 +171,21 @@ class ZCtx : public AsyncWrap {
in_len = 0; in_len = 0;
in_off = 0; in_off = 0;
} else { } else {
assert(Buffer::HasInstance(args[1])); CHECK(Buffer::HasInstance(args[1]));
Local<Object> in_buf; Local<Object> in_buf;
in_buf = args[1]->ToObject(); in_buf = args[1]->ToObject();
in_off = args[2]->Uint32Value(); in_off = args[2]->Uint32Value();
in_len = args[3]->Uint32Value(); in_len = args[3]->Uint32Value();
assert(Buffer::IsWithinBounds(in_off, in_len, Buffer::Length(in_buf))); CHECK(Buffer::IsWithinBounds(in_off, in_len, Buffer::Length(in_buf)));
in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off); in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off);
} }
assert(Buffer::HasInstance(args[4])); CHECK(Buffer::HasInstance(args[4]));
Local<Object> out_buf = args[4]->ToObject(); Local<Object> out_buf = args[4]->ToObject();
out_off = args[5]->Uint32Value(); out_off = args[5]->Uint32Value();
out_len = args[6]->Uint32Value(); out_len = args[6]->Uint32Value();
assert(Buffer::IsWithinBounds(out_off, out_len, Buffer::Length(out_buf))); CHECK(Buffer::IsWithinBounds(out_off, out_len, Buffer::Length(out_buf)));
out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off); out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off);
// build up the work request // build up the work request
@ -276,7 +276,7 @@ class ZCtx : public AsyncWrap {
} }
break; break;
default: default:
assert(0 && "wtf?"); CHECK(0 && "wtf?");
} }
// pass any errors back to the main thread to deal with. // pass any errors back to the main thread to deal with.
@ -313,7 +313,7 @@ class ZCtx : public AsyncWrap {
// v8 land! // v8 land!
static void After(uv_work_t* work_req, int status) { static void After(uv_work_t* work_req, int status) {
assert(status == 0); CHECK_EQ(status, 0);
ZCtx* ctx = ContainerOf(&ZCtx::work_req_, work_req); ZCtx* ctx = ContainerOf(&ZCtx::work_req_, work_req);
Environment* env = ctx->env(); Environment* env = ctx->env();
@ -344,7 +344,7 @@ class ZCtx : public AsyncWrap {
Environment* env = ctx->env(); Environment* env = ctx->env();
// If you hit this assertion, you forgot to enter the v8::Context first. // If you hit this assertion, you forgot to enter the v8::Context first.
assert(env->context() == env->isolate()->GetCurrentContext()); CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
if (ctx->strm_.msg != NULL) { if (ctx->strm_.msg != NULL) {
message = ctx->strm_.msg; message = ctx->strm_.msg;
@ -383,22 +383,22 @@ class ZCtx : public AsyncWrap {
static void Init(const FunctionCallbackInfo<Value>& args) { static void Init(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert((args.Length() == 4 || args.Length() == 5) && CHECK((args.Length() == 4 || args.Length() == 5) &&
"init(windowBits, level, memLevel, strategy, [dictionary])"); "init(windowBits, level, memLevel, strategy, [dictionary])");
ZCtx* ctx = Unwrap<ZCtx>(args.Holder()); ZCtx* ctx = Unwrap<ZCtx>(args.Holder());
int windowBits = args[0]->Uint32Value(); int windowBits = args[0]->Uint32Value();
assert((windowBits >= 8 && windowBits <= 15) && "invalid windowBits"); CHECK((windowBits >= 8 && windowBits <= 15) && "invalid windowBits");
int level = args[1]->Int32Value(); int level = args[1]->Int32Value();
assert((level >= -1 && level <= 9) && "invalid compression level"); CHECK((level >= -1 && level <= 9) && "invalid compression level");
int memLevel = args[2]->Uint32Value(); int memLevel = args[2]->Uint32Value();
assert((memLevel >= 1 && memLevel <= 9) && "invalid memlevel"); CHECK((memLevel >= 1 && memLevel <= 9) && "invalid memlevel");
int strategy = args[3]->Uint32Value(); int strategy = args[3]->Uint32Value();
assert((strategy == Z_FILTERED || CHECK((strategy == Z_FILTERED ||
strategy == Z_HUFFMAN_ONLY || strategy == Z_HUFFMAN_ONLY ||
strategy == Z_RLE || strategy == Z_RLE ||
strategy == Z_FIXED || strategy == Z_FIXED ||
@ -423,7 +423,7 @@ class ZCtx : public AsyncWrap {
static void Params(const FunctionCallbackInfo<Value>& args) { static void Params(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
assert(args.Length() == 2 && "params(level, strategy)"); CHECK(args.Length() == 2 && "params(level, strategy)");
ZCtx* ctx = Unwrap<ZCtx>(args.Holder()); ZCtx* ctx = Unwrap<ZCtx>(args.Holder());
@ -488,7 +488,7 @@ class ZCtx : public AsyncWrap {
->AdjustAmountOfExternalAllocatedMemory(kInflateContextSize); ->AdjustAmountOfExternalAllocatedMemory(kInflateContextSize);
break; break;
default: default:
assert(0 && "wtf?"); CHECK(0 && "wtf?");
} }
if (ctx->err_ != Z_OK) { if (ctx->err_ != Z_OK) {
@ -571,7 +571,7 @@ class ZCtx : public AsyncWrap {
} }
void Unref() { void Unref() {
assert(refs_ > 0); CHECK_GT(refs_, 0);
if (--refs_ == 0) { if (--refs_ == 0) {
MakeWeak<ZCtx>(this); MakeWeak<ZCtx>(this);
} }

24
src/pipe_wrap.cc

@ -61,11 +61,11 @@ uv_pipe_t* PipeWrap::UVHandle() {
Local<Object> PipeWrap::Instantiate(Environment* env) { Local<Object> PipeWrap::Instantiate(Environment* env) {
EscapableHandleScope handle_scope(env->isolate()); EscapableHandleScope handle_scope(env->isolate());
assert(!env->pipe_constructor_template().IsEmpty()); CHECK_EQ(false, env->pipe_constructor_template().IsEmpty());
Local<Function> constructor = env->pipe_constructor_template()->GetFunction(); Local<Function> constructor = env->pipe_constructor_template()->GetFunction();
assert(!constructor.IsEmpty()); CHECK_EQ(false, constructor.IsEmpty());
Local<Object> instance = constructor->NewInstance(); Local<Object> instance = constructor->NewInstance();
assert(!instance.IsEmpty()); CHECK_EQ(false, instance.IsEmpty());
return handle_scope.Escape(instance); return handle_scope.Escape(instance);
} }
@ -126,7 +126,7 @@ void PipeWrap::New(const FunctionCallbackInfo<Value>& args) {
// This constructor should not be exposed to public javascript. // This constructor should not be exposed to public javascript.
// Therefore we assert that we are not trying to call this as a // Therefore we assert that we are not trying to call this as a
// normal function. // normal function.
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
new PipeWrap(env, args.This(), args[0]->IsTrue()); new PipeWrap(env, args.This(), args[0]->IsTrue());
} }
@ -138,7 +138,7 @@ PipeWrap::PipeWrap(Environment* env, Handle<Object> object, bool ipc)
reinterpret_cast<uv_stream_t*>(&handle_), reinterpret_cast<uv_stream_t*>(&handle_),
AsyncWrap::PROVIDER_PIPEWRAP) { AsyncWrap::PROVIDER_PIPEWRAP) {
int r = uv_pipe_init(env->event_loop(), &handle_, ipc); int r = uv_pipe_init(env->event_loop(), &handle_, ipc);
assert(r == 0); // How do we proxy this error up to javascript? CHECK_EQ(r, 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void. // Suggestion: uv_pipe_init() returns void.
UpdateWriteQueueSize(); UpdateWriteQueueSize();
} }
@ -174,7 +174,7 @@ void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
// TODO(bnoordhuis) maybe share with TCPWrap? // TODO(bnoordhuis) maybe share with TCPWrap?
void PipeWrap::OnConnection(uv_stream_t* handle, int status) { void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
PipeWrap* pipe_wrap = static_cast<PipeWrap*>(handle->data); PipeWrap* pipe_wrap = static_cast<PipeWrap*>(handle->data);
assert(&pipe_wrap->handle_ == reinterpret_cast<uv_pipe_t*>(handle)); CHECK_EQ(&pipe_wrap->handle_, reinterpret_cast<uv_pipe_t*>(handle));
Environment* env = pipe_wrap->env(); Environment* env = pipe_wrap->env();
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
@ -182,7 +182,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
// We should not be getting this callback if someone as already called // We should not be getting this callback if someone as already called
// uv_close() on the handle. // uv_close() on the handle.
assert(pipe_wrap->persistent().IsEmpty() == false); CHECK_EQ(pipe_wrap->persistent().IsEmpty(), false);
Local<Value> argv[] = { Local<Value> argv[] = {
Integer::New(env->isolate(), status), Integer::New(env->isolate(), status),
@ -212,15 +212,15 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
void PipeWrap::AfterConnect(uv_connect_t* req, int status) { void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data); ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data);
PipeWrap* wrap = static_cast<PipeWrap*>(req->handle->data); PipeWrap* wrap = static_cast<PipeWrap*>(req->handle->data);
assert(req_wrap->env() == wrap->env()); CHECK_EQ(req_wrap->env(), wrap->env());
Environment* env = wrap->env(); Environment* env = wrap->env();
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());
// The wrap and request objects should still be there. // The wrap and request objects should still be there.
assert(req_wrap->persistent().IsEmpty() == false); CHECK_EQ(req_wrap->persistent().IsEmpty(), false);
assert(wrap->persistent().IsEmpty() == false); CHECK_EQ(wrap->persistent().IsEmpty(), false);
bool readable, writable; bool readable, writable;
@ -265,8 +265,8 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
PipeWrap* wrap = Unwrap<PipeWrap>(args.Holder()); PipeWrap* wrap = Unwrap<PipeWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsString()); CHECK(args[1]->IsString());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value name(args[1]); node::Utf8Value name(args[1]);

10
src/process_wrap.cc

@ -73,7 +73,7 @@ class ProcessWrap : public HandleWrap {
// This constructor should not be exposed to public javascript. // This constructor should not be exposed to public javascript.
// Therefore we assert that we are not trying to call this as a // Therefore we assert that we are not trying to call this as a
// normal function. // normal function.
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
new ProcessWrap(env, args.This()); new ProcessWrap(env, args.This());
} }
@ -116,7 +116,7 @@ class ProcessWrap : public HandleWrap {
Local<String> handle_key = env->handle_string(); Local<String> handle_key = env->handle_string();
Local<Object> handle = stdio->Get(handle_key).As<Object>(); Local<Object> handle = stdio->Get(handle_key).As<Object>();
uv_stream_t* stream = HandleToStream(env, handle); uv_stream_t* stream = HandleToStream(env, handle);
assert(stream != NULL); CHECK_NE(stream, NULL);
options->stdio[i].flags = UV_INHERIT_STREAM; options->stdio[i].flags = UV_INHERIT_STREAM;
options->stdio[i].data.stream = stream; options->stdio[i].data.stream = stream;
@ -231,7 +231,7 @@ class ProcessWrap : public HandleWrap {
int err = uv_spawn(env->event_loop(), &wrap->process_, &options); int err = uv_spawn(env->event_loop(), &wrap->process_, &options);
if (err == 0) { if (err == 0) {
assert(wrap->process_.data == wrap); CHECK_EQ(wrap->process_.data, wrap);
wrap->object()->Set(env->pid_string(), wrap->object()->Set(env->pid_string(),
Integer::New(env->isolate(), wrap->process_.pid)); Integer::New(env->isolate(), wrap->process_.pid));
} }
@ -262,8 +262,8 @@ class ProcessWrap : public HandleWrap {
int64_t exit_status, int64_t exit_status,
int term_signal) { int term_signal) {
ProcessWrap* wrap = static_cast<ProcessWrap*>(handle->data); ProcessWrap* wrap = static_cast<ProcessWrap*>(handle->data);
assert(wrap != NULL); CHECK_NE(wrap, NULL);
assert(&wrap->process_ == handle); CHECK_EQ(&wrap->process_, handle);
Environment* env = wrap->env(); Environment* env = wrap->env();
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());

4
src/req_wrap.h

@ -48,8 +48,8 @@ class ReqWrap : public AsyncWrap {
~ReqWrap() { ~ReqWrap() {
QUEUE_REMOVE(&req_wrap_queue_); QUEUE_REMOVE(&req_wrap_queue_);
// Assert that someone has called Dispatched() // Assert that someone has called Dispatched()
assert(req_.data == this); CHECK_EQ(req_.data, this);
assert(!persistent().IsEmpty()); CHECK_EQ(false, persistent().IsEmpty());
persistent().Reset(); persistent().Reset();
} }

4
src/signal_wrap.cc

@ -67,7 +67,7 @@ class SignalWrap : public HandleWrap {
// This constructor should not be exposed to public javascript. // This constructor should not be exposed to public javascript.
// Therefore we assert that we are not trying to call this as a // Therefore we assert that we are not trying to call this as a
// normal function. // normal function.
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
new SignalWrap(env, args.This()); new SignalWrap(env, args.This());
} }
@ -78,7 +78,7 @@ class SignalWrap : public HandleWrap {
reinterpret_cast<uv_handle_t*>(&handle_), reinterpret_cast<uv_handle_t*>(&handle_),
AsyncWrap::PROVIDER_SIGNALWRAP) { AsyncWrap::PROVIDER_SIGNALWRAP) {
int r = uv_signal_init(env->event_loop(), &handle_); int r = uv_signal_init(env->event_loop(), &handle_);
assert(r == 0); CHECK_EQ(r, 0);
} }
~SignalWrap() { ~SignalWrap() {

35
src/smalloc.cc

@ -29,7 +29,6 @@
#include "v8.h" #include "v8.h"
#include <string.h> #include <string.h>
#include <assert.h>
#define ALLOC_ID (0xA10C) #define ALLOC_ID (0xA10C)
@ -251,8 +250,8 @@ void SliceOnto(const FunctionCallbackInfo<Value>& args) {
Local<Object> source = args[0].As<Object>(); Local<Object> source = args[0].As<Object>();
Local<Object> dest = args[1].As<Object>(); Local<Object> dest = args[1].As<Object>();
assert(source->HasIndexedPropertiesInExternalArrayData()); CHECK(source->HasIndexedPropertiesInExternalArrayData());
assert(!dest->HasIndexedPropertiesInExternalArrayData()); CHECK_EQ(false, dest->HasIndexedPropertiesInExternalArrayData());
char* source_data = static_cast<char*>( char* source_data = static_cast<char*>(
source->GetIndexedPropertiesExternalArrayData()); source->GetIndexedPropertiesExternalArrayData());
@ -261,20 +260,20 @@ void SliceOnto(const FunctionCallbackInfo<Value>& args) {
source->GetIndexedPropertiesExternalArrayDataType(); source->GetIndexedPropertiesExternalArrayDataType();
size_t source_size = ExternalArraySize(source_type); size_t source_size = ExternalArraySize(source_type);
assert(source_size != 0); CHECK_NE(source_size, 0);
size_t start = args[2]->Uint32Value(); size_t start = args[2]->Uint32Value();
size_t end = args[3]->Uint32Value(); size_t end = args[3]->Uint32Value();
size_t length = end - start; size_t length = end - start;
if (source_size > 1) { if (source_size > 1) {
assert(length * source_size >= length); CHECK_GE(length * source_size, length);
length *= source_size; length *= source_size;
} }
assert(source_data != NULL || length == 0); CHECK(source_data != NULL || length == 0);
assert(end <= source_len); CHECK_LE(end, source_len);
assert(start <= end); CHECK_LE(start, end);
dest->SetIndexedPropertiesToExternalArrayData(source_data + start, dest->SetIndexedPropertiesToExternalArrayData(source_data + start,
source_type, source_type,
@ -303,7 +302,7 @@ void Alloc(const FunctionCallbackInfo<Value>& args) {
} else { } else {
array_type = static_cast<ExternalArrayType>(args[2]->Uint32Value()); array_type = static_cast<ExternalArrayType>(args[2]->Uint32Value());
size_t type_length = ExternalArraySize(array_type); size_t type_length = ExternalArraySize(array_type);
assert(type_length * length >= length); CHECK_GE(type_length * length, length);
length *= type_length; length *= type_length;
} }
@ -318,8 +317,8 @@ void Alloc(Environment* env,
enum ExternalArrayType type) { enum ExternalArrayType type) {
size_t type_size = ExternalArraySize(type); size_t type_size = ExternalArraySize(type);
assert(length <= kMaxLength); CHECK_LE(length, kMaxLength);
assert(type_size > 0); CHECK_GT(type_size, 0);
if (length == 0) if (length == 0)
return Alloc(env, obj, NULL, length, type); return Alloc(env, obj, NULL, length, type);
@ -339,7 +338,7 @@ void Alloc(Environment* env,
char* data, char* data,
size_t length, size_t length,
enum ExternalArrayType type) { enum ExternalArrayType type) {
assert(!obj->HasIndexedPropertiesInExternalArrayData()); CHECK_EQ(false, obj->HasIndexedPropertiesInExternalArrayData());
env->isolate()->AdjustAmountOfExternalAllocatedMemory(length); env->isolate()->AdjustAmountOfExternalAllocatedMemory(length);
size_t size = length / ExternalArraySize(type); size_t size = length / ExternalArraySize(type);
obj->SetIndexedPropertiesToExternalArrayData(data, type, size); obj->SetIndexedPropertiesToExternalArrayData(data, type, size);
@ -373,8 +372,8 @@ void AllocDispose(Environment* env, Handle<Object> obj) {
obj->GetIndexedPropertiesExternalArrayDataType(); obj->GetIndexedPropertiesExternalArrayDataType();
size_t array_size = ExternalArraySize(array_type); size_t array_size = ExternalArraySize(array_type);
assert(array_size > 0); CHECK_GT(array_size, 0);
assert(length * array_size >= length); CHECK_GE(length * array_size, length);
length *= array_size; length *= array_size;
@ -397,12 +396,12 @@ void Alloc(Environment* env,
FreeCallback fn, FreeCallback fn,
void* hint, void* hint,
enum ExternalArrayType type) { enum ExternalArrayType type) {
assert(length <= kMaxLength); CHECK_LE(length, kMaxLength);
size_t type_size = ExternalArraySize(type); size_t type_size = ExternalArraySize(type);
assert(type_size > 0); CHECK_GT(type_size, 0);
assert(length * type_size >= length); CHECK_GE(length * type_size, length);
length *= type_size; length *= type_size;
@ -418,7 +417,7 @@ void Alloc(Environment* env,
FreeCallback fn, FreeCallback fn,
void* hint, void* hint,
enum ExternalArrayType type) { enum ExternalArrayType type) {
assert(!obj->HasIndexedPropertiesInExternalArrayData()); CHECK_EQ(false, obj->HasIndexedPropertiesInExternalArrayData());
Isolate* isolate = env->isolate(); Isolate* isolate = env->isolate();
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
env->set_using_smalloc_alloc_cb(true); env->set_using_smalloc_alloc_cb(true);

64
src/spawn_sync.cc

@ -63,7 +63,7 @@ void SyncProcessOutputBuffer::OnAlloc(size_t suggested_size,
void SyncProcessOutputBuffer::OnRead(const uv_buf_t* buf, size_t nread) { void SyncProcessOutputBuffer::OnRead(const uv_buf_t* buf, size_t nread) {
// If we hand out the same chunk twice, this should catch it. // If we hand out the same chunk twice, this should catch it.
assert(buf->base == data_ + used()); CHECK_EQ(buf->base, data_ + used());
used_ += static_cast<unsigned int>(nread); used_ += static_cast<unsigned int>(nread);
} }
@ -111,12 +111,12 @@ SyncProcessStdioPipe::SyncProcessStdioPipe(SyncProcessRunner* process_handler,
shutdown_req_(), shutdown_req_(),
lifecycle_(kUninitialized) { lifecycle_(kUninitialized) {
assert(readable || writable); CHECK(readable || writable);
} }
SyncProcessStdioPipe::~SyncProcessStdioPipe() { SyncProcessStdioPipe::~SyncProcessStdioPipe() {
assert(lifecycle_ == kUninitialized || lifecycle_ == kClosed); CHECK(lifecycle_ == kUninitialized || lifecycle_ == kClosed);
SyncProcessOutputBuffer* buf; SyncProcessOutputBuffer* buf;
SyncProcessOutputBuffer* next; SyncProcessOutputBuffer* next;
@ -129,7 +129,7 @@ SyncProcessStdioPipe::~SyncProcessStdioPipe() {
int SyncProcessStdioPipe::Initialize(uv_loop_t* loop) { int SyncProcessStdioPipe::Initialize(uv_loop_t* loop) {
assert(lifecycle_ == kUninitialized); CHECK_EQ(lifecycle_, kUninitialized);
int r = uv_pipe_init(loop, uv_pipe(), 0); int r = uv_pipe_init(loop, uv_pipe(), 0);
if (r < 0) if (r < 0)
@ -143,7 +143,7 @@ int SyncProcessStdioPipe::Initialize(uv_loop_t* loop) {
int SyncProcessStdioPipe::Start() { int SyncProcessStdioPipe::Start() {
assert(lifecycle_ == kInitialized); CHECK_EQ(lifecycle_, kInitialized);
// Set the busy flag already. If this function fails no recovery is // Set the busy flag already. If this function fails no recovery is
// possible. // possible.
@ -151,7 +151,7 @@ int SyncProcessStdioPipe::Start() {
if (readable()) { if (readable()) {
if (input_buffer_.len > 0) { if (input_buffer_.len > 0) {
assert(input_buffer_.base != NULL); CHECK_NE(input_buffer_.base, NULL);
int r = uv_write(&write_req_, int r = uv_write(&write_req_,
uv_stream(), uv_stream(),
@ -178,7 +178,7 @@ int SyncProcessStdioPipe::Start() {
void SyncProcessStdioPipe::Close() { void SyncProcessStdioPipe::Close() {
assert(lifecycle_ == kInitialized || lifecycle_ == kStarted); CHECK(lifecycle_ == kInitialized || lifecycle_ == kStarted);
uv_close(uv_handle(), CloseCallback); uv_close(uv_handle(), CloseCallback);
@ -218,7 +218,7 @@ uv_stdio_flags SyncProcessStdioPipe::uv_flags() const {
uv_pipe_t* SyncProcessStdioPipe::uv_pipe() const { uv_pipe_t* SyncProcessStdioPipe::uv_pipe() const {
assert(lifecycle_ < kClosing); CHECK_LT(lifecycle_, kClosing);
return &uv_pipe_; return &uv_pipe_;
} }
@ -309,7 +309,7 @@ void SyncProcessStdioPipe::OnClose() {
void SyncProcessStdioPipe::SetError(int error) { void SyncProcessStdioPipe::SetError(int error) {
assert(error != 0); CHECK_NE(error, 0);
process_handler_->SetPipeError(error); process_handler_->SetPipeError(error);
} }
@ -406,7 +406,7 @@ SyncProcessRunner::SyncProcessRunner(Environment* env)
SyncProcessRunner::~SyncProcessRunner() { SyncProcessRunner::~SyncProcessRunner() {
assert(lifecycle_ == kHandlesClosed); CHECK_EQ(lifecycle_, kHandlesClosed);
if (stdio_pipes_ != NULL) { if (stdio_pipes_ != NULL) {
for (size_t i = 0; i < stdio_count_; i++) { for (size_t i = 0; i < stdio_count_; i++) {
@ -432,7 +432,7 @@ Environment* SyncProcessRunner::env() const {
Local<Object> SyncProcessRunner::Run(Local<Value> options) { Local<Object> SyncProcessRunner::Run(Local<Value> options) {
EscapableHandleScope scope(env()->isolate()); EscapableHandleScope scope(env()->isolate());
assert(lifecycle_ == kUninitialized); CHECK_EQ(lifecycle_, kUninitialized);
TryInitializeAndRunLoop(options); TryInitializeAndRunLoop(options);
CloseHandlesAndDeleteLoop(); CloseHandlesAndDeleteLoop();
@ -448,7 +448,7 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
// There is no recovery from failure inside TryInitializeAndRunLoop - the // There is no recovery from failure inside TryInitializeAndRunLoop - the
// only option we'd have is to close all handles and destroy the loop. // only option we'd have is to close all handles and destroy the loop.
assert(lifecycle_ == kUninitialized); CHECK_EQ(lifecycle_, kUninitialized);
lifecycle_ = kInitialized; lifecycle_ = kInitialized;
uv_loop_ = new uv_loop_t; uv_loop_ = new uv_loop_t;
@ -500,12 +500,12 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
abort(); abort();
// If we get here the process should have exited. // If we get here the process should have exited.
assert(exit_status_ >= 0); CHECK_GE(exit_status_, 0);
} }
void SyncProcessRunner::CloseHandlesAndDeleteLoop() { void SyncProcessRunner::CloseHandlesAndDeleteLoop() {
assert(lifecycle_ < kHandlesClosed); CHECK_LT(lifecycle_, kHandlesClosed);
if (uv_loop_ != NULL) { if (uv_loop_ != NULL) {
CloseStdioPipes(); CloseStdioPipes();
@ -528,8 +528,8 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() {
} else { } else {
// If the loop doesn't exist, neither should any pipes or timers. // If the loop doesn't exist, neither should any pipes or timers.
assert(!stdio_pipes_initialized_); CHECK_EQ(false, stdio_pipes_initialized_);
assert(!kill_timer_initialized_); CHECK_EQ(false, kill_timer_initialized_);
} }
lifecycle_ = kHandlesClosed; lifecycle_ = kHandlesClosed;
@ -537,11 +537,11 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() {
void SyncProcessRunner::CloseStdioPipes() { void SyncProcessRunner::CloseStdioPipes() {
assert(lifecycle_ < kHandlesClosed); CHECK_LT(lifecycle_, kHandlesClosed);
if (stdio_pipes_initialized_) { if (stdio_pipes_initialized_) {
assert(stdio_pipes_ != NULL); CHECK_NE(stdio_pipes_, NULL);
assert(uv_loop_ != NULL); CHECK_NE(uv_loop_, NULL);
for (uint32_t i = 0; i < stdio_count_; i++) { for (uint32_t i = 0; i < stdio_count_; i++) {
if (stdio_pipes_[i] != NULL) if (stdio_pipes_[i] != NULL)
@ -554,11 +554,11 @@ void SyncProcessRunner::CloseStdioPipes() {
void SyncProcessRunner::CloseKillTimer() { void SyncProcessRunner::CloseKillTimer() {
assert(lifecycle_ < kHandlesClosed); CHECK_LT(lifecycle_, kHandlesClosed);
if (kill_timer_initialized_) { if (kill_timer_initialized_) {
assert(timeout_ > 0); CHECK_GT(timeout_, 0);
assert(uv_loop_ != NULL); CHECK_NE(uv_loop_, NULL);
uv_handle_t* uv_timer_handle = reinterpret_cast<uv_handle_t*>(&uv_timer_); uv_handle_t* uv_timer_handle = reinterpret_cast<uv_handle_t*>(&uv_timer_);
uv_ref(uv_timer_handle); uv_ref(uv_timer_handle);
@ -590,7 +590,7 @@ void SyncProcessRunner::Kill() {
SetError(r); SetError(r);
r = uv_process_kill(&uv_process_, SIGKILL); r = uv_process_kill(&uv_process_, SIGKILL);
assert(r >= 0 || r == UV_ESRCH); CHECK(r >= 0 || r == UV_ESRCH);
} }
} }
@ -683,8 +683,8 @@ Local<Object> SyncProcessRunner::BuildResultObject() {
Local<Array> SyncProcessRunner::BuildOutputArray() { Local<Array> SyncProcessRunner::BuildOutputArray() {
assert(lifecycle_ >= kInitialized); CHECK_GE(lifecycle_, kInitialized);
assert(stdio_pipes_ != NULL); CHECK_NE(stdio_pipes_, NULL);
EscapableHandleScope scope(env()->isolate()); EscapableHandleScope scope(env()->isolate());
Local<Array> js_output = Array::New(env()->isolate(), stdio_count_); Local<Array> js_output = Array::New(env()->isolate(), stdio_count_);
@ -868,15 +868,15 @@ int SyncProcessRunner::ParseStdioOption(int child_fd,
return AddStdioInheritFD(child_fd, inherit_fd); return AddStdioInheritFD(child_fd, inherit_fd);
} else { } else {
assert(0 && "invalid child stdio type"); CHECK(0 && "invalid child stdio type");
return UV_EINVAL; return UV_EINVAL;
} }
} }
int SyncProcessRunner::AddStdioIgnore(uint32_t child_fd) { int SyncProcessRunner::AddStdioIgnore(uint32_t child_fd) {
assert(child_fd < stdio_count_); CHECK_LT(child_fd, stdio_count_);
assert(stdio_pipes_[child_fd] == NULL); CHECK_EQ(stdio_pipes_[child_fd], NULL);
uv_stdio_containers_[child_fd].flags = UV_IGNORE; uv_stdio_containers_[child_fd].flags = UV_IGNORE;
@ -888,8 +888,8 @@ int SyncProcessRunner::AddStdioPipe(uint32_t child_fd,
bool readable, bool readable,
bool writable, bool writable,
uv_buf_t input_buffer) { uv_buf_t input_buffer) {
assert(child_fd < stdio_count_); CHECK_LT(child_fd, stdio_count_);
assert(stdio_pipes_[child_fd] == NULL); CHECK_EQ(stdio_pipes_[child_fd], NULL);
SyncProcessStdioPipe* h = new SyncProcessStdioPipe(this, SyncProcessStdioPipe* h = new SyncProcessStdioPipe(this,
readable, readable,
@ -912,8 +912,8 @@ int SyncProcessRunner::AddStdioPipe(uint32_t child_fd,
int SyncProcessRunner::AddStdioInheritFD(uint32_t child_fd, int inherit_fd) { int SyncProcessRunner::AddStdioInheritFD(uint32_t child_fd, int inherit_fd) {
assert(child_fd < stdio_count_); CHECK_LT(child_fd, stdio_count_);
assert(stdio_pipes_[child_fd] == NULL); CHECK_EQ(stdio_pipes_[child_fd], NULL);
uv_stdio_containers_[child_fd].flags = UV_INHERIT_FD; uv_stdio_containers_[child_fd].flags = UV_INHERIT_FD;
uv_stdio_containers_[child_fd].data.fd = inherit_fd; uv_stdio_containers_[child_fd].data.fd = inherit_fd;

44
src/stream_wrap.cc

@ -107,7 +107,7 @@ void StreamWrap::OnAlloc(uv_handle_t* handle,
size_t suggested_size, size_t suggested_size,
uv_buf_t* buf) { uv_buf_t* buf) {
StreamWrap* wrap = static_cast<StreamWrap*>(handle->data); StreamWrap* wrap = static_cast<StreamWrap*>(handle->data);
assert(wrap->stream() == reinterpret_cast<uv_stream_t*>(handle)); CHECK_EQ(wrap->stream(), reinterpret_cast<uv_stream_t*>(handle));
wrap->callbacks()->DoAlloc(handle, suggested_size, buf); wrap->callbacks()->DoAlloc(handle, suggested_size, buf);
} }
@ -140,7 +140,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle,
// We should not be getting this callback if someone as already called // We should not be getting this callback if someone as already called
// uv_close() on the handle. // uv_close() on the handle.
assert(wrap->persistent().IsEmpty() == false); CHECK_EQ(wrap->persistent().IsEmpty(), false);
if (nread > 0) { if (nread > 0) {
if (wrap->is_tcp()) { if (wrap->is_tcp()) {
@ -170,7 +170,7 @@ void StreamWrap::OnRead(uv_stream_t* handle,
size_t StreamWrap::WriteBuffer(Handle<Value> val, uv_buf_t* buf) { size_t StreamWrap::WriteBuffer(Handle<Value> val, uv_buf_t* buf) {
assert(Buffer::HasInstance(val)); CHECK(Buffer::HasInstance(val));
// Simple non-writev case // Simple non-writev case
buf->base = Buffer::Data(val); buf->base = Buffer::Data(val);
@ -185,8 +185,8 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(Buffer::HasInstance(args[1])); CHECK(Buffer::HasInstance(args[1]));
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
Local<Object> buf_obj = args[1].As<Object>(); Local<Object> buf_obj = args[1].As<Object>();
@ -206,7 +206,7 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
goto done; goto done;
if (count == 0) if (count == 0)
goto done; goto done;
assert(count == 1); CHECK_EQ(count, 1);
// Allocate, or write rest // Allocate, or write rest
storage = new char[sizeof(WriteWrap)]; storage = new char[sizeof(WriteWrap)];
@ -242,8 +242,8 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsString()); CHECK(args[1]->IsString());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
Local<String> string = args[1].As<String>(); Local<String> string = args[1].As<String>();
@ -293,7 +293,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
goto done; goto done;
// Partial write // Partial write
assert(count == 1); CHECK_EQ(count, 1);
} }
storage = new char[sizeof(WriteWrap) + storage_size + 15]; storage = new char[sizeof(WriteWrap) + storage_size + 15];
@ -315,7 +315,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
encoding); encoding);
} }
assert(data_size <= storage_size); CHECK_LE(data_size, storage_size);
buf = uv_buf_init(data, data_size); buf = uv_buf_init(data, data_size);
@ -334,7 +334,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
send_handle = wrap->GetHandle(); send_handle = wrap->GetHandle();
// Reference StreamWrap instance to prevent it from being garbage // Reference StreamWrap instance to prevent it from being garbage
// collected before `AfterWrite` is called. // collected before `AfterWrite` is called.
assert(!req_wrap->persistent().IsEmpty()); CHECK_EQ(false, req_wrap->persistent().IsEmpty());
req_wrap->object()->Set(env->handle_string(), send_handle_obj); req_wrap->object()->Set(env->handle_string(), send_handle_obj);
} }
@ -369,8 +369,8 @@ void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) {
StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsArray()); CHECK(args[1]->IsArray());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
Local<Array> chunks = args[1].As<Array>(); Local<Array> chunks = args[1].As<Array>();
@ -429,7 +429,7 @@ void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) {
// Write string // Write string
offset = ROUND_UP(offset, 16); offset = ROUND_UP(offset, 16);
assert(offset < storage_size); CHECK_LT(offset, storage_size);
char* str_storage = storage + offset; char* str_storage = storage + offset;
size_t str_size = storage_size - offset; size_t str_size = storage_size - offset;
@ -494,7 +494,7 @@ void StreamWrap::WriteBinaryString(const FunctionCallbackInfo<Value>& args) {
void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) { void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) {
StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());
assert(args.Length() > 0); CHECK_GT(args.Length(), 0);
int err = uv_stream_set_blocking(wrap->stream(), args[0]->IsTrue()); int err = uv_stream_set_blocking(wrap->stream(), args[0]->IsTrue());
args.GetReturnValue().Set(err); args.GetReturnValue().Set(err);
} }
@ -508,8 +508,8 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());
// The wrap and request objects should still be there. // The wrap and request objects should still be there.
assert(req_wrap->persistent().IsEmpty() == false); CHECK_EQ(req_wrap->persistent().IsEmpty(), false);
assert(wrap->persistent().IsEmpty() == false); CHECK_EQ(wrap->persistent().IsEmpty(), false);
// Unref handle property // Unref handle property
Local<Object> req_wrap_obj = req_wrap->object(); Local<Object> req_wrap_obj = req_wrap->object();
@ -539,7 +539,7 @@ void StreamWrap::Shutdown(const FunctionCallbackInfo<Value>& args) {
StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
ShutdownWrap* req_wrap = new ShutdownWrap(env, ShutdownWrap* req_wrap = new ShutdownWrap(env,
@ -559,8 +559,8 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
Environment* env = wrap->env(); Environment* env = wrap->env();
// The wrap and request objects should still be there. // The wrap and request objects should still be there.
assert(req_wrap->persistent().IsEmpty() == false); CHECK_EQ(req_wrap->persistent().IsEmpty(), false);
assert(wrap->persistent().IsEmpty() == false); CHECK_EQ(wrap->persistent().IsEmpty(), false);
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());
@ -699,7 +699,7 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
} }
char* base = static_cast<char*>(realloc(buf->base, nread)); char* base = static_cast<char*>(realloc(buf->base, nread));
assert(static_cast<size_t>(nread) <= buf->len); CHECK_LE(static_cast<size_t>(nread), buf->len);
argv[1] = Buffer::Use(env, base, nread); argv[1] = Buffer::Use(env, base, nread);
Local<Object> pending_obj; Local<Object> pending_obj;
@ -710,7 +710,7 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
} else if (pending == UV_UDP) { } else if (pending == UV_UDP) {
pending_obj = AcceptHandle<UDPWrap, uv_udp_t>(env, handle); pending_obj = AcceptHandle<UDPWrap, uv_udp_t>(env, handle);
} else { } else {
assert(pending == UV_UNKNOWN_HANDLE); CHECK_EQ(pending, UV_UNKNOWN_HANDLE);
} }
if (!pending_obj.IsEmpty()) { if (!pending_obj.IsEmpty()) {

6
src/stream_wrap.h

@ -48,7 +48,7 @@ class WriteWrap: public ReqWrap<uv_write_t> {
// This is just to keep the compiler happy. It should never be called, since // This is just to keep the compiler happy. It should never be called, since
// we don't use exceptions in node. // we don't use exceptions in node.
void operator delete(void* ptr, char* storage) { assert(0); } void operator delete(void* ptr, char* storage) { UNREACHABLE(); }
inline StreamWrap* wrap() const { inline StreamWrap* wrap() const {
return wrap_; return wrap_;
@ -57,8 +57,8 @@ class WriteWrap: public ReqWrap<uv_write_t> {
private: private:
// People should not be using the non-placement new and delete operator on a // People should not be using the non-placement new and delete operator on a
// WriteWrap. Ensure this never happens. // WriteWrap. Ensure this never happens.
void* operator new(size_t size) { assert(0); } void* operator new(size_t size) { UNREACHABLE(); }
void operator delete(void* ptr) { assert(0); } void operator delete(void* ptr) { UNREACHABLE(); }
StreamWrap* const wrap_; StreamWrap* const wrap_;
}; };

23
src/string_bytes.cc

@ -25,7 +25,6 @@
#include "node_buffer.h" #include "node_buffer.h"
#include "v8.h" #include "v8.h"
#include <assert.h>
#include <limits.h> #include <limits.h>
#include <string.h> // memcpy #include <string.h> // memcpy
@ -378,7 +377,7 @@ size_t StringBytes::Write(Isolate* isolate,
break; break;
default: default:
assert(0 && "unknown encoding"); CHECK(0 && "unknown encoding");
break; break;
} }
@ -435,12 +434,12 @@ size_t StringBytes::StorageSize(Isolate* isolate,
break; break;
case HEX: case HEX:
assert(str->Length() % 2 == 0 && "invalid hex string length"); CHECK(str->Length() % 2 == 0 && "invalid hex string length");
data_size = str->Length() / 2; data_size = str->Length() / 2;
break; break;
default: default:
assert(0 && "unknown encoding"); CHECK(0 && "unknown encoding");
break; break;
} }
@ -490,7 +489,7 @@ size_t StringBytes::Size(Isolate* isolate,
break; break;
default: default:
assert(0 && "unknown encoding"); CHECK(0 && "unknown encoding");
break; break;
} }
@ -610,8 +609,8 @@ static size_t base64_encode(const char* src,
char* dst, char* dst,
size_t dlen) { size_t dlen) {
// We know how much we'll write, just make sure that there's space. // We know how much we'll write, just make sure that there's space.
assert(dlen >= base64_encoded_size(slen) && CHECK(dlen >= base64_encoded_size(slen) &&
"not enough space provided for base64 encode"); "not enough space provided for base64 encode");
dlen = base64_encoded_size(slen); dlen = base64_encoded_size(slen);
@ -671,7 +670,7 @@ static size_t base64_encode(const char* src,
static size_t hex_encode(const char* src, size_t slen, char* dst, size_t dlen) { static size_t hex_encode(const char* src, size_t slen, char* dst, size_t dlen) {
// We know how much we'll write, just make sure that there's space. // We know how much we'll write, just make sure that there's space.
assert(dlen >= slen * 2 && CHECK(dlen >= slen * 2 &&
"not enough space provided for hex encode"); "not enough space provided for hex encode");
dlen = slen * 2; dlen = slen * 2;
@ -693,7 +692,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
enum encoding encoding) { enum encoding encoding) {
EscapableHandleScope scope(isolate); EscapableHandleScope scope(isolate);
assert(buflen <= Buffer::kMaxLength); CHECK_LE(buflen, Buffer::kMaxLength);
if (!buflen && encoding != BUFFER) if (!buflen && encoding != BUFFER)
return scope.Escape(String::Empty(isolate)); return scope.Escape(String::Empty(isolate));
@ -739,7 +738,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
char* dst = new char[dlen]; char* dst = new char[dlen];
size_t written = base64_encode(buf, buflen, dst, dlen); size_t written = base64_encode(buf, buflen, dst, dlen);
assert(written == dlen); CHECK_EQ(written, dlen);
if (dlen < EXTERN_APEX) { if (dlen < EXTERN_APEX) {
val = OneByteString(isolate, dst, dlen); val = OneByteString(isolate, dst, dlen);
@ -780,7 +779,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
size_t dlen = buflen * 2; size_t dlen = buflen * 2;
char* dst = new char[dlen]; char* dst = new char[dlen];
size_t written = hex_encode(buf, buflen, dst, dlen); size_t written = hex_encode(buf, buflen, dst, dlen);
assert(written == dlen); CHECK_EQ(written, dlen);
if (dlen < EXTERN_APEX) { if (dlen < EXTERN_APEX) {
val = OneByteString(isolate, dst, dlen); val = OneByteString(isolate, dst, dlen);
@ -792,7 +791,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
} }
default: default:
assert(0 && "unknown encoding"); CHECK(0 && "unknown encoding");
break; break;
} }

40
src/tcp_wrap.cc

@ -57,11 +57,11 @@ typedef class ReqWrap<uv_connect_t> ConnectWrap;
Local<Object> TCPWrap::Instantiate(Environment* env) { Local<Object> TCPWrap::Instantiate(Environment* env) {
EscapableHandleScope handle_scope(env->isolate()); EscapableHandleScope handle_scope(env->isolate());
assert(env->tcp_constructor_template().IsEmpty() == false); CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false);
Local<Function> constructor = env->tcp_constructor_template()->GetFunction(); Local<Function> constructor = env->tcp_constructor_template()->GetFunction();
assert(constructor.IsEmpty() == false); CHECK_EQ(constructor.IsEmpty(), false);
Local<Object> instance = constructor->NewInstance(); Local<Object> instance = constructor->NewInstance();
assert(instance.IsEmpty() == false); CHECK_EQ(instance.IsEmpty(), false);
return handle_scope.Escape(instance); return handle_scope.Escape(instance);
} }
@ -147,10 +147,10 @@ void TCPWrap::New(const FunctionCallbackInfo<Value>& args) {
// This constructor should not be exposed to public javascript. // This constructor should not be exposed to public javascript.
// Therefore we assert that we are not trying to call this as a // Therefore we assert that we are not trying to call this as a
// normal function. // normal function.
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
TCPWrap* wrap = new TCPWrap(env, args.This()); TCPWrap* wrap = new TCPWrap(env, args.This());
assert(wrap); CHECK(wrap);
} }
@ -160,14 +160,14 @@ TCPWrap::TCPWrap(Environment* env, Handle<Object> object)
reinterpret_cast<uv_stream_t*>(&handle_), reinterpret_cast<uv_stream_t*>(&handle_),
AsyncWrap::PROVIDER_TCPWRAP) { AsyncWrap::PROVIDER_TCPWRAP) {
int r = uv_tcp_init(env->event_loop(), &handle_); int r = uv_tcp_init(env->event_loop(), &handle_);
assert(r == 0); // How do we proxy this error up to javascript? CHECK_EQ(r, 0); // How do we proxy this error up to javascript?
// Suggestion: uv_tcp_init() returns void. // Suggestion: uv_tcp_init() returns void.
UpdateWriteQueueSize(); UpdateWriteQueueSize();
} }
TCPWrap::~TCPWrap() { TCPWrap::~TCPWrap() {
assert(persistent().IsEmpty()); CHECK(persistent().IsEmpty());
} }
@ -177,7 +177,7 @@ void TCPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
TCPWrap* wrap = Unwrap<TCPWrap>(args.Holder()); TCPWrap* wrap = Unwrap<TCPWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
Local<Object> out = args[0].As<Object>(); Local<Object> out = args[0].As<Object>();
int addrlen = sizeof(address); int addrlen = sizeof(address);
@ -199,7 +199,7 @@ void TCPWrap::GetPeerName(const FunctionCallbackInfo<Value>& args) {
TCPWrap* wrap = Unwrap<TCPWrap>(args.Holder()); TCPWrap* wrap = Unwrap<TCPWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
Local<Object> out = args[0].As<Object>(); Local<Object> out = args[0].As<Object>();
int addrlen = sizeof(address); int addrlen = sizeof(address);
@ -291,7 +291,7 @@ void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
void TCPWrap::OnConnection(uv_stream_t* handle, int status) { void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
TCPWrap* tcp_wrap = static_cast<TCPWrap*>(handle->data); TCPWrap* tcp_wrap = static_cast<TCPWrap*>(handle->data);
assert(&tcp_wrap->handle_ == reinterpret_cast<uv_tcp_t*>(handle)); CHECK_EQ(&tcp_wrap->handle_, reinterpret_cast<uv_tcp_t*>(handle));
Environment* env = tcp_wrap->env(); Environment* env = tcp_wrap->env();
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
@ -299,7 +299,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
// We should not be getting this callback if someone as already called // We should not be getting this callback if someone as already called
// uv_close() on the handle. // uv_close() on the handle.
assert(tcp_wrap->persistent().IsEmpty() == false); CHECK_EQ(tcp_wrap->persistent().IsEmpty(), false);
Local<Value> argv[2] = { Local<Value> argv[2] = {
Integer::New(env->isolate(), status), Integer::New(env->isolate(), status),
@ -327,15 +327,15 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
void TCPWrap::AfterConnect(uv_connect_t* req, int status) { void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data); ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data);
TCPWrap* wrap = static_cast<TCPWrap*>(req->handle->data); TCPWrap* wrap = static_cast<TCPWrap*>(req->handle->data);
assert(req_wrap->env() == wrap->env()); CHECK_EQ(req_wrap->env(), wrap->env());
Environment* env = wrap->env(); Environment* env = wrap->env();
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());
// The wrap and request objects should still be there. // The wrap and request objects should still be there.
assert(req_wrap->persistent().IsEmpty() == false); CHECK_EQ(req_wrap->persistent().IsEmpty(), false);
assert(wrap->persistent().IsEmpty() == false); CHECK_EQ(wrap->persistent().IsEmpty(), false);
Local<Object> req_wrap_obj = req_wrap->object(); Local<Object> req_wrap_obj = req_wrap->object();
Local<Value> argv[5] = { Local<Value> argv[5] = {
@ -357,9 +357,9 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
TCPWrap* wrap = Unwrap<TCPWrap>(args.Holder()); TCPWrap* wrap = Unwrap<TCPWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsString()); CHECK(args[1]->IsString());
assert(args[2]->Uint32Value()); CHECK(args[2]->Uint32Value());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value ip_address(args[1]); node::Utf8Value ip_address(args[1]);
@ -390,9 +390,9 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
TCPWrap* wrap = Unwrap<TCPWrap>(args.Holder()); TCPWrap* wrap = Unwrap<TCPWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(args[1]->IsString()); CHECK(args[1]->IsString());
assert(args[2]->Uint32Value()); CHECK(args[2]->Uint32Value());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value ip_address(args[1]); node::Utf8Value ip_address(args[1]);

4
src/timer_wrap.cc

@ -78,7 +78,7 @@ class TimerWrap : public HandleWrap {
// This constructor should not be exposed to public javascript. // This constructor should not be exposed to public javascript.
// Therefore we assert that we are not trying to call this as a // Therefore we assert that we are not trying to call this as a
// normal function. // normal function.
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
new TimerWrap(env, args.This()); new TimerWrap(env, args.This());
} }
@ -89,7 +89,7 @@ class TimerWrap : public HandleWrap {
reinterpret_cast<uv_handle_t*>(&handle_), reinterpret_cast<uv_handle_t*>(&handle_),
AsyncWrap::PROVIDER_TIMERWRAP) { AsyncWrap::PROVIDER_TIMERWRAP) {
int r = uv_timer_init(env->event_loop(), &handle_); int r = uv_timer_init(env->event_loop(), &handle_);
assert(r == 0); CHECK_EQ(r, 0);
} }
~TimerWrap() { ~TimerWrap() {

24
src/tls_wrap.cc

@ -272,7 +272,7 @@ void TLSCallbacks::Start(const FunctionCallbackInfo<Value>& args) {
wrap->started_ = true; wrap->started_ = true;
// Send ClientHello handshake // Send ClientHello handshake
assert(wrap->is_client()); CHECK(wrap->is_client());
wrap->ClearOut(); wrap->ClearOut();
wrap->EncOut(); wrap->EncOut();
} }
@ -336,7 +336,7 @@ void TLSCallbacks::EncOut() {
size_t size[ARRAY_SIZE(data)]; size_t size[ARRAY_SIZE(data)];
size_t count = ARRAY_SIZE(data); size_t count = ARRAY_SIZE(data);
write_size_ = NodeBIO::FromBIO(enc_out_)->PeekMultiple(data, size, &count); write_size_ = NodeBIO::FromBIO(enc_out_)->PeekMultiple(data, size, &count);
assert(write_size_ != 0 && count != 0); CHECK(write_size_ != 0 && count != 0);
write_req_.data = this; write_req_.data = this;
uv_buf_t buf[ARRAY_SIZE(data)]; uv_buf_t buf[ARRAY_SIZE(data)];
@ -387,7 +387,7 @@ int TLSCallbacks::PrintErrorsCb(const char* str, size_t len, void* arg) {
memcpy(error_buf_, str, avail); memcpy(error_buf_, str, avail);
error_off_ += avail; error_off_ += avail;
assert(error_off_ < sizeof(error_buf_)); CHECK_LT(error_off_, sizeof(error_buf_));
// Zero-terminate // Zero-terminate
error_buf_[error_off_] = '\0'; error_buf_[error_off_] = '\0';
@ -418,7 +418,7 @@ Local<Value> TLSCallbacks::GetSSLError(int status, int* err, const char** msg) {
break; break;
default: default:
{ {
assert(*err == SSL_ERROR_SSL || *err == SSL_ERROR_SYSCALL); CHECK(*err == SSL_ERROR_SSL || *err == SSL_ERROR_SYSCALL);
const char* buf = PrintErrors(); const char* buf = PrintErrors();
@ -427,7 +427,7 @@ Local<Value> TLSCallbacks::GetSSLError(int status, int* err, const char** msg) {
Local<Value> exception = Exception::Error(message); Local<Value> exception = Exception::Error(message);
if (msg != NULL) { if (msg != NULL) {
assert(*msg == NULL); CHECK_EQ(*msg, NULL);
*msg = buf; *msg = buf;
} }
@ -450,7 +450,7 @@ void TLSCallbacks::ClearOut() {
HandleScope handle_scope(env()->isolate()); HandleScope handle_scope(env()->isolate());
Context::Scope context_scope(env()->context()); Context::Scope context_scope(env()->context());
assert(ssl_ != NULL); CHECK_NE(ssl_, NULL);
char out[kClearOutChunkSize]; char out[kClearOutChunkSize];
int read; int read;
@ -502,7 +502,7 @@ bool TLSCallbacks::ClearIn() {
size_t avail = 0; size_t avail = 0;
char* data = clear_in_->Peek(&avail); char* data = clear_in_->Peek(&avail);
written = SSL_write(ssl_, data, avail); written = SSL_write(ssl_, data, avail);
assert(written == -1 || written == static_cast<int>(avail)); CHECK(written == -1 || written == static_cast<int>(avail));
if (written == -1) if (written == -1)
break; break;
clear_in_->Read(NULL, avail); clear_in_->Read(NULL, avail);
@ -510,7 +510,7 @@ bool TLSCallbacks::ClearIn() {
// All written // All written
if (clear_in_->Length() == 0) { if (clear_in_->Length() == 0) {
assert(written >= 0); CHECK_GE(written, 0);
return true; return true;
} }
@ -549,7 +549,7 @@ int TLSCallbacks::DoWrite(WriteWrap* w,
size_t count, size_t count,
uv_stream_t* send_handle, uv_stream_t* send_handle,
uv_write_cb cb) { uv_write_cb cb) {
assert(send_handle == NULL); CHECK_EQ(send_handle, NULL);
bool empty = true; bool empty = true;
@ -589,7 +589,7 @@ int TLSCallbacks::DoWrite(WriteWrap* w,
int written = 0; int written = 0;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
written = SSL_write(ssl_, bufs[i].base, bufs[i].len); written = SSL_write(ssl_, bufs[i].base, bufs[i].len);
assert(written == -1 || written == static_cast<int>(bufs[i].len)); CHECK(written == -1 || written == static_cast<int>(bufs[i].len));
if (written == -1) if (written == -1)
break; break;
} }
@ -651,7 +651,7 @@ void TLSCallbacks::DoRead(uv_stream_t* handle,
} }
// Only client connections can receive data // Only client connections can receive data
assert(ssl_ != NULL); CHECK_NE(ssl_, NULL);
// Commit read data // Commit read data
NodeBIO* enc_in = NodeBIO::FromBIO(enc_in_); NodeBIO* enc_in = NodeBIO::FromBIO(enc_in_);
@ -661,7 +661,7 @@ void TLSCallbacks::DoRead(uv_stream_t* handle,
if (!hello_parser_.IsEnded()) { if (!hello_parser_.IsEnded()) {
size_t avail = 0; size_t avail = 0;
uint8_t* data = reinterpret_cast<uint8_t*>(enc_in->Peek(&avail)); uint8_t* data = reinterpret_cast<uint8_t*>(enc_in->Peek(&avail));
assert(avail == 0 || data != NULL); CHECK(avail == 0 || data != NULL);
return hello_parser_.Parse(data, avail); return hello_parser_.Parse(data, avail);
} }

10
src/tty_wrap.cc

@ -100,7 +100,7 @@ uv_tty_t* TTYWrap::UVHandle() {
void TTYWrap::GuessHandleType(const FunctionCallbackInfo<Value>& args) { void TTYWrap::GuessHandleType(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
int fd = args[0]->Int32Value(); int fd = args[0]->Int32Value();
assert(fd >= 0); CHECK_GE(fd, 0);
uv_handle_type t = uv_guess_handle(fd); uv_handle_type t = uv_guess_handle(fd);
const char* type = NULL; const char* type = NULL;
@ -122,7 +122,7 @@ void TTYWrap::GuessHandleType(const FunctionCallbackInfo<Value>& args) {
void TTYWrap::IsTTY(const FunctionCallbackInfo<Value>& args) { void TTYWrap::IsTTY(const FunctionCallbackInfo<Value>& args) {
int fd = args[0]->Int32Value(); int fd = args[0]->Int32Value();
assert(fd >= 0); CHECK_GE(fd, 0);
bool rc = uv_guess_handle(fd) == UV_TTY; bool rc = uv_guess_handle(fd) == UV_TTY;
args.GetReturnValue().Set(rc); args.GetReturnValue().Set(rc);
} }
@ -132,7 +132,7 @@ void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
TTYWrap* wrap = Unwrap<TTYWrap>(args.Holder()); TTYWrap* wrap = Unwrap<TTYWrap>(args.Holder());
assert(args[0]->IsArray()); CHECK(args[0]->IsArray());
int width, height; int width, height;
int err = uv_tty_get_winsize(&wrap->handle_, &width, &height); int err = uv_tty_get_winsize(&wrap->handle_, &width, &height);
@ -160,10 +160,10 @@ void TTYWrap::New(const FunctionCallbackInfo<Value>& args) {
// This constructor should not be exposed to public javascript. // This constructor should not be exposed to public javascript.
// Therefore we assert that we are not trying to call this as a // Therefore we assert that we are not trying to call this as a
// normal function. // normal function.
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
int fd = args[0]->Int32Value(); int fd = args[0]->Int32Value();
assert(fd >= 0); CHECK_GE(fd, 0);
TTYWrap* wrap = new TTYWrap(env, args.This(), fd, args[1]->IsTrue()); TTYWrap* wrap = new TTYWrap(env, args.This(), fd, args[1]->IsTrue());
wrap->UpdateWriteQueueSize(); wrap->UpdateWriteQueueSize();

34
src/udp_wrap.cc

@ -78,7 +78,7 @@ UDPWrap::UDPWrap(Environment* env, Handle<Object> object)
reinterpret_cast<uv_handle_t*>(&handle_), reinterpret_cast<uv_handle_t*>(&handle_),
AsyncWrap::PROVIDER_UDPWRAP) { AsyncWrap::PROVIDER_UDPWRAP) {
int r = uv_udp_init(env->event_loop(), &handle_); int r = uv_udp_init(env->event_loop(), &handle_);
assert(r == 0); // can't fail anyway CHECK_EQ(r, 0); // can't fail anyway
} }
@ -128,7 +128,7 @@ void UDPWrap::Initialize(Handle<Object> target,
void UDPWrap::New(const FunctionCallbackInfo<Value>& args) { void UDPWrap::New(const FunctionCallbackInfo<Value>& args) {
assert(args.IsConstructCall()); CHECK(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate());
new UDPWrap(env, args.This()); new UDPWrap(env, args.This());
} }
@ -149,7 +149,7 @@ void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) {
UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder());
// bind(ip, port, flags) // bind(ip, port, flags)
assert(args.Length() == 3); CHECK_EQ(args.Length(), 3);
node::Utf8Value address(args[0]); node::Utf8Value address(args[0]);
const int port = args[1]->Uint32Value(); const int port = args[1]->Uint32Value();
@ -165,7 +165,7 @@ void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) {
err = uv_ip6_addr(*address, port, reinterpret_cast<sockaddr_in6*>(&addr)); err = uv_ip6_addr(*address, port, reinterpret_cast<sockaddr_in6*>(&addr));
break; break;
default: default:
assert(0 && "unexpected address family"); CHECK(0 && "unexpected address family");
abort(); abort();
} }
@ -192,7 +192,7 @@ void UDPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
#define X(name, fn) \ #define X(name, fn) \
void UDPWrap::name(const FunctionCallbackInfo<Value>& args) { \ void UDPWrap::name(const FunctionCallbackInfo<Value>& args) { \
UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); \ UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); \
assert(args.Length() == 1); \ CHECK_EQ(args.Length(), 1); \
int flag = args[0]->Int32Value(); \ int flag = args[0]->Int32Value(); \
int err = fn(&wrap->handle_, flag); \ int err = fn(&wrap->handle_, flag); \
args.GetReturnValue().Set(err); \ args.GetReturnValue().Set(err); \
@ -210,7 +210,7 @@ void UDPWrap::SetMembership(const FunctionCallbackInfo<Value>& args,
uv_membership membership) { uv_membership membership) {
UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder());
assert(args.Length() == 2); CHECK_EQ(args.Length(), 2);
node::Utf8Value address(args[0]); node::Utf8Value address(args[0]);
node::Utf8Value iface(args[1]); node::Utf8Value iface(args[1]);
@ -244,13 +244,13 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder());
// send(req, buffer, offset, length, port, address) // send(req, buffer, offset, length, port, address)
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
assert(Buffer::HasInstance(args[1])); CHECK(Buffer::HasInstance(args[1]));
assert(args[2]->IsUint32()); CHECK(args[2]->IsUint32());
assert(args[3]->IsUint32()); CHECK(args[3]->IsUint32());
assert(args[4]->IsUint32()); CHECK(args[4]->IsUint32());
assert(args[5]->IsString()); CHECK(args[5]->IsString());
assert(args[6]->IsBoolean()); CHECK(args[6]->IsBoolean());
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
Local<Object> buffer_obj = args[1].As<Object>(); Local<Object> buffer_obj = args[1].As<Object>();
@ -260,7 +260,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
node::Utf8Value address(args[5]); node::Utf8Value address(args[5]);
const bool have_callback = args[6]->IsTrue(); const bool have_callback = args[6]->IsTrue();
assert(length <= Buffer::Length(buffer_obj) - offset); CHECK_LE(length, Buffer::Length(buffer_obj) - offset);
SendWrap* req_wrap = new SendWrap(env, req_wrap_obj, have_callback); SendWrap* req_wrap = new SendWrap(env, req_wrap_obj, have_callback);
@ -277,7 +277,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
err = uv_ip6_addr(*address, port, reinterpret_cast<sockaddr_in6*>(&addr)); err = uv_ip6_addr(*address, port, reinterpret_cast<sockaddr_in6*>(&addr));
break; break;
default: default:
assert(0 && "unexpected address family"); CHECK(0 && "unexpected address family");
abort(); abort();
} }
@ -331,7 +331,7 @@ void UDPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
struct sockaddr_storage address; struct sockaddr_storage address;
UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder());
assert(args[0]->IsObject()); CHECK(args[0]->IsObject());
Local<Object> obj = args[0].As<Object>(); Local<Object> obj = args[0].As<Object>();
int addrlen = sizeof(address); int addrlen = sizeof(address);
@ -416,7 +416,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
Local<Object> UDPWrap::Instantiate(Environment* env) { Local<Object> UDPWrap::Instantiate(Environment* env) {
// If this assert fires then Initialize hasn't been called yet. // If this assert fires then Initialize hasn't been called yet.
assert(env->udp_constructor_function().IsEmpty() == false); CHECK_EQ(env->udp_constructor_function().IsEmpty(), false);
return env->udp_constructor_function()->NewInstance(); return env->udp_constructor_function()->NewInstance();
} }

10
src/util-inl.h

@ -24,8 +24,6 @@
#include "util.h" #include "util.h"
#include <assert.h>
namespace node { namespace node {
template <typename Inner, typename Outer> template <typename Inner, typename Outer>
@ -102,8 +100,8 @@ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
template <typename TypeName> template <typename TypeName>
void Wrap(v8::Local<v8::Object> object, TypeName* pointer) { void Wrap(v8::Local<v8::Object> object, TypeName* pointer) {
assert(!object.IsEmpty()); CHECK_EQ(false, object.IsEmpty());
assert(object->InternalFieldCount() > 0); CHECK_GT(object->InternalFieldCount(), 0);
object->SetAlignedPointerInInternalField(0, pointer); object->SetAlignedPointerInInternalField(0, pointer);
} }
@ -113,8 +111,8 @@ void ClearWrap(v8::Local<v8::Object> object) {
template <typename TypeName> template <typename TypeName>
TypeName* Unwrap(v8::Local<v8::Object> object) { TypeName* Unwrap(v8::Local<v8::Object> object) {
assert(!object.IsEmpty()); CHECK_EQ(false, object.IsEmpty());
assert(object->InternalFieldCount() > 0); CHECK_GT(object->InternalFieldCount(), 0);
void* pointer = object->GetAlignedPointerFromInternalField(0); void* pointer = object->GetAlignedPointerFromInternalField(0);
return static_cast<TypeName*>(pointer); return static_cast<TypeName*>(pointer);
} }

Loading…
Cancel
Save