process: allow changing `exitCode` in `on('exit')`
authorFedor Indutny <fedor.indutny@gmail.com>
Sun, 9 Feb 2014 10:40:57 +0000 (14:40 +0400)
committerFedor Indutny <fedor.indutny@gmail.com>
Sun, 9 Feb 2014 11:10:38 +0000 (15:10 +0400)
fix #7081

src/node.cc
test/simple/test-process-exit-code.js

index 0b61076..434682f 100644 (file)
@@ -3385,7 +3385,9 @@ int EmitExit(Environment* env) {
   };
 
   MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args);
-  return code;
+
+  // Reload exit code, it may be changed by `emit('exit')`
+  return process_object->Get(exitCode)->IntegerValue();
 }
 
 
index 6a19db9..2488175 100644 (file)
@@ -31,6 +31,8 @@ switch (process.argv[2]) {
     return child3();
   case 'child4':
     return child4();
+  case 'child5':
+    return child5();
   case undefined:
     return parent();
   default:
@@ -71,11 +73,20 @@ function child4() {
   throw new Error('ok');
 }
 
+function child5() {
+  process.exitCode = 95;
+  process.on('exit', function(code) {
+    assert.equal(code, 95);
+    process.exitCode = 99;
+  });
+}
+
 function parent() {
   test('child1', 42);
   test('child2', 42);
   test('child3', 0);
   test('child4', 1);
+  test('child5', 99);
 }
 
 function test(arg, exit) {