Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
process: allow changing exitCode in on('exit')
Browse files Browse the repository at this point in the history
fix #7081
  • Loading branch information
indutny committed Feb 9, 2014
1 parent 28dbc96 commit c0d81f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down
11 changes: 11 additions & 0 deletions test/simple/test-process-exit-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ switch (process.argv[2]) {
return child3();
case 'child4':
return child4();
case 'child5':
return child5();
case undefined:
return parent();
default:
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c0d81f9

Please sign in to comment.