Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: honor --abort_on_uncaught_exception flag #2776

Merged
merged 2 commits into from
Sep 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
break;
default:
CHECK(0 && "bad address family");
abort();
ABORT();
}

GetAddrInfoReqWrap* req_wrap = new GetAddrInfoReqWrap(env, req_wrap_obj);
Expand Down Expand Up @@ -1193,7 +1193,7 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
break;
default:
CHECK(0 && "Bad address family.");
abort();
ABORT();
}

if (err)
Expand Down
2 changes: 1 addition & 1 deletion src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
event_string = env->change_string();
} else {
CHECK(0 && "bad fs events flag");
abort();
ABORT();
}

Local<Value> argv[] = {
Expand Down
18 changes: 11 additions & 7 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ void SetupDomainUse(const FunctionCallbackInfo<Value>& args) {

if (!tick_callback_function->IsFunction()) {
fprintf(stderr, "process._tickDomainCallback assigned to non-function\n");
abort();
ABORT();
}

process_object->Set(env->tick_callback_string(), tick_callback_function);
Expand Down Expand Up @@ -1514,7 +1514,7 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {


static void Abort(const FunctionCallbackInfo<Value>& args) {
abort();
ABORT();
}


Expand Down Expand Up @@ -2134,14 +2134,14 @@ static void OnFatalError(const char* location, const char* message) {
fprintf(stderr, "FATAL ERROR: %s\n", message);
}
fflush(stderr);
abort();
ABORT();
}


NO_RETURN void FatalError(const char* location, const char* message) {
OnFatalError(location, message);
// to suppress compiler warning
abort();
ABORT();
}


Expand Down Expand Up @@ -2180,7 +2180,11 @@ void FatalException(Isolate* isolate,

if (false == caught->BooleanValue()) {
ReportException(env, error, message);
exit(1);
if (abort_on_uncaught_exception) {
ABORT();
} else {
exit(1);
}
}
}

Expand Down Expand Up @@ -3543,9 +3547,9 @@ inline void PlatformInit() {
// Anything but EBADF means something is seriously wrong. We don't
// have to special-case EINTR, fstat() is not interruptible.
if (errno != EBADF)
abort();
ABORT();
if (fd != open("/dev/null", O_RDWR))
abort();
ABORT();
}

CHECK_EQ(err, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static void crypto_lock_init(void) {

for (i = 0; i < n; i++)
if (uv_mutex_init(locks + i))
abort();
ABORT();
}


Expand Down Expand Up @@ -3466,7 +3466,7 @@ void SignBase::CheckThrow(SignBase::Error error) {
case kSignPublicKey:
return env()->ThrowError("PEM_read_bio_PUBKEY failed");
default:
abort();
ABORT();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto_bio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ long NodeBIO::Ctrl(BIO* bio, int cmd, long num, void* ptr) {
break;
case BIO_C_SET_BUF_MEM:
CHECK(0 && "Can't use SET_BUF_MEM_PTR with NodeBIO");
abort();
ABORT();
break;
case BIO_C_GET_BUF_MEM_PTR:
CHECK(0 && "Can't use GET_BUF_MEM_PTR with NodeBIO");
Expand Down
4 changes: 2 additions & 2 deletions src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
r = uv_run(uv_loop_, UV_RUN_DEFAULT);
if (r < 0)
// We can't handle uv_run failure.
abort();
ABORT();

// If we get here the process should have exited.
CHECK_GE(exit_status_, 0);
Expand All @@ -508,7 +508,7 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() {
// callbacks called.
int r = uv_run(uv_loop_, UV_RUN_DEFAULT);
if (r < 0)
abort();
ABORT();

CHECK_EQ(uv_loop_close(uv_loop_), 0);
delete uv_loop_;
Expand Down
2 changes: 1 addition & 1 deletion src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static Local<Object> AcceptHandle(Environment* env, StreamWrap* parent) {
handle = wrap->UVHandle();

if (uv_accept(parent->stream(), reinterpret_cast<uv_stream_t*>(handle)))
abort();
ABORT();

return scope.Escape(wrap_obj);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void TLSWrap::InitSSL() {
SSL_set_connect_state(ssl_);
} else {
// Unexpected
abort();
ABORT();
}

// Initialize ring for queud clear data
Expand Down
2 changes: 1 addition & 1 deletion src/tty_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void TTYWrap::GuessHandleType(const FunctionCallbackInfo<Value>& args) {
case UV_NAMED_PIPE: type = "PIPE"; break;
case UV_UNKNOWN_HANDLE: type = "UNKNOWN"; break;
default:
abort();
ABORT();
}

args.GetReturnValue().Set(OneByteString(env->isolate(), type));
Expand Down
4 changes: 2 additions & 2 deletions src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) {
break;
default:
CHECK(0 && "unexpected address family");
abort();
ABORT();
}

if (err == 0) {
Expand Down Expand Up @@ -278,7 +278,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
break;
default:
CHECK(0 && "unexpected address family");
abort();
ABORT();
}

if (err == 0) {
Expand Down
11 changes: 9 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ namespace node {
TypeName(const TypeName&) = delete; \
TypeName(TypeName&&) = delete

// Windows 8+ does not like abort() in Release mode
#ifdef _WIN32
#define ABORT() raise(SIGABRT)
#else
#define ABORT() abort()
#endif

#if defined(NDEBUG)
# define ASSERT(expression)
# define CHECK(expression) \
do { \
if (!(expression)) abort(); \
if (!(expression)) ABORT(); \
} while (0)
#else
# define ASSERT(expression) assert(expression)
Expand All @@ -43,7 +50,7 @@ namespace node {
#define CHECK_LT(a, b) CHECK((a) < (b))
#define CHECK_NE(a, b) CHECK((a) != (b))

#define UNREACHABLE() abort()
#define UNREACHABLE() ABORT()

// TAILQ-style intrusive list node.
template <typename T>
Expand Down
31 changes: 31 additions & 0 deletions test/abort/test-abort-uncaught-exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const node = process.execPath;

if (process.argv[2] === 'child') {
throw new Error('child error');
} else {
run('', null);
run('--abort-on-uncaught-exception', 'SIGABRT');
}

function run(flags, signal) {
const args = [__filename, 'child'];
if (flags)
args.unshift(flags);

const child = spawn(node, args);
child.on('exit', common.mustCall(function(code, sig) {
if (!common.isWindows) {
assert.strictEqual(sig, signal);
} else {
if (signal)
assert.strictEqual(code, 3);
else
assert.strictEqual(code, 1);
}
}));
}