node: EmitExit should not call exit()

Before this commit `RunAtExit` and `env->Dispose()` were never reached,
because `EmitExit` was always colling `exit`.
This commit is contained in:
Fedor Indutny 2014-01-18 22:49:33 +00:00
parent 1442c1c6de
commit e57ab7ba06
2 changed files with 7 additions and 4 deletions

View File

@ -190,6 +190,8 @@ inline Environment::Environment(v8::Local<v8::Context> context)
} }
inline Environment::~Environment() { inline Environment::~Environment() {
v8::HandleScope handle_scope(isolate());
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL); context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL);
#define V(PropertyName, TypeName) PropertyName ## _.Dispose(); #define V(PropertyName, TypeName) PropertyName ## _.Dispose();
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)

View File

@ -3315,7 +3315,7 @@ void AtExit(void (*cb)(void* arg), void* arg) {
} }
void EmitExit(Environment* env) { int EmitExit(Environment* env) {
// process.emit('exit') // process.emit('exit')
HandleScope handle_scope(env->isolate()); HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());
@ -3332,7 +3332,7 @@ void EmitExit(Environment* env) {
}; };
MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args); MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args);
exit(code); return code;
} }
@ -3406,6 +3406,7 @@ int Start(int argc, char** argv) {
V8::SetEntropySource(crypto::EntropySource); V8::SetEntropySource(crypto::EntropySource);
#endif #endif
int code;
V8::Initialize(); V8::Initialize();
{ {
Locker locker(node_isolate); Locker locker(node_isolate);
@ -3417,7 +3418,7 @@ int Start(int argc, char** argv) {
// be removed. // be removed.
Context::Scope context_scope(env->context()); Context::Scope context_scope(env->context());
uv_run(env->event_loop(), UV_RUN_DEFAULT); uv_run(env->event_loop(), UV_RUN_DEFAULT);
EmitExit(env); code = EmitExit(env);
RunAtExit(env); RunAtExit(env);
env->Dispose(); env->Dispose();
env = NULL; env = NULL;
@ -3431,7 +3432,7 @@ int Start(int argc, char** argv) {
delete[] exec_argv; delete[] exec_argv;
exec_argv = NULL; exec_argv = NULL;
return 0; return code;
} }