From: Fedor Indutny Date: Sun, 9 Feb 2014 10:40:57 +0000 (+0400) Subject: process: allow changing `exitCode` in `on('exit')` X-Git-Tag: v0.11.12~79 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0d81f90996667a658aa4403123e02161262506a;p=platform%2Fupstream%2Fnodejs.git process: allow changing `exitCode` in `on('exit')` fix #7081 --- diff --git a/src/node.cc b/src/node.cc index 0b61076..434682f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -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(); } diff --git a/test/simple/test-process-exit-code.js b/test/simple/test-process-exit-code.js index 6a19db9..2488175 100644 --- a/test/simple/test-process-exit-code.js +++ b/test/simple/test-process-exit-code.js @@ -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) {