node: `EmitExit` should not call `exit()`
authorFedor Indutny <fedor.indutny@gmail.com>
Sat, 18 Jan 2014 22:49:33 +0000 (22:49 +0000)
committerFedor Indutny <fedor.indutny@gmail.com>
Tue, 21 Jan 2014 20:39:13 +0000 (00:39 +0400)
Before this commit `RunAtExit` and `env->Dispose()` were never reached,
because `EmitExit` was always colling `exit`.

src/env-inl.h
src/node.cc

index 21075a6..ef6b3be 100644 (file)
@@ -190,6 +190,8 @@ inline Environment::Environment(v8::Local<v8::Context> context)
 }
 
 inline Environment::~Environment() {
+  v8::HandleScope handle_scope(isolate());
+
   context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL);
 #define V(PropertyName, TypeName) PropertyName ## _.Dispose();
   ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
index 25283c0..47ef87b 100644 (file)
@@ -3315,7 +3315,7 @@ void AtExit(void (*cb)(void* arg), void* arg) {
 }
 
 
-void EmitExit(Environment* env) {
+int EmitExit(Environment* env) {
   // process.emit('exit')
   HandleScope handle_scope(env->isolate());
   Context::Scope context_scope(env->context());
@@ -3332,7 +3332,7 @@ void EmitExit(Environment* env) {
   };
 
   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);
 #endif
 
+  int code;
   V8::Initialize();
   {
     Locker locker(node_isolate);
@@ -3417,7 +3418,7 @@ int Start(int argc, char** argv) {
     // be removed.
     Context::Scope context_scope(env->context());
     uv_run(env->event_loop(), UV_RUN_DEFAULT);
-    EmitExit(env);
+    code = EmitExit(env);
     RunAtExit(env);
     env->Dispose();
     env = NULL;
@@ -3431,7 +3432,7 @@ int Start(int argc, char** argv) {
   delete[] exec_argv;
   exec_argv = NULL;
 
-  return 0;
+  return code;
 }