Skip to content

Commit

Permalink
Add support for an exithandler being called on isolate exit
Browse files Browse the repository at this point in the history
  • Loading branch information
paddybyers committed Nov 30, 2011
1 parent d8437ae commit 3211e25
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ int Isolate::Start(uv_thread_shared_t *hnd) {
RETURN_ON_EXIT(exit_status);

EmitExit(process);

if(exitHandler) exitHandler();
#ifndef NDEBUG
// Clean up.
context.Dispose();
Expand Down Expand Up @@ -2578,6 +2578,7 @@ Isolate::Isolate() {
exit_status = 0;
term_signal = 0;
loop_ = (this == &defaultIsolate) ? uv_default_loop(): uv_loop_new();
exitHandler = 0;
}

Isolate::~Isolate() {
Expand Down
3 changes: 2 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

#ifdef NODE_LIBRARY
# define EXIT(X) node::Isolate *i = node::Isolate::GetCurrent(); if(!i->exit_status) i->exit_status = (X)
# define RETURN_ON_EXIT(X) if(exit_status) return X
# define RETURN_ON_EXIT(X) if(exit_status) { if(exitHandler) exitHandler(); return X; }
# define BREAK_AND_EXIT(X) ev_break(node::Isolate::GetCurrent()->Loop()->ev, EVBREAK_ALL); EXIT(X) //FIXME: implement generically for uv
#else
# define EXIT(X) exit((X))
Expand Down Expand Up @@ -146,6 +146,7 @@ class Isolate {
ext_statics statics_;
int exit_status;
int term_signal;
void (*exitHandler)();

Isolate();
~Isolate();
Expand Down

0 comments on commit 3211e25

Please sign in to comment.