mirror of https://github.com/nodejs/node.git
process: make `exitCode` configurable again
This change was done in #44711, and it's not clear it was intentional. It caused #45683, and also makes it impossible to mock out the exitCode in tests. Filing this PR per https://github.com/nodejs/node/pull/44711#discussion_r1320660607 Fixes #45683.
This commit is contained in:
parent
362afa52eb
commit
c8e87a1ec6
|
@ -129,7 +129,7 @@ process.domain = null;
|
|||
exitCode = code;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
process._exiting = false;
|
||||
|
|
|
@ -110,17 +110,14 @@ if (process.argv[2] === undefined) {
|
|||
|
||||
// Check process.exitCode
|
||||
for (const arg of invalids) {
|
||||
debug(`invaild code: ${inspect(arg.code)}`);
|
||||
debug(`invalid code: ${inspect(arg.code)}`);
|
||||
throws(() => (process.exitCode = arg.code), new RegExp(arg.pattern));
|
||||
}
|
||||
for (const arg of valids) {
|
||||
debug(`vaild code: ${inspect(arg.code)}`);
|
||||
debug(`valid code: ${inspect(arg.code)}`);
|
||||
process.exitCode = arg.code;
|
||||
}
|
||||
|
||||
throws(() => {
|
||||
delete process.exitCode;
|
||||
}, /Cannot delete property 'exitCode' of #<process>/);
|
||||
process.exitCode = 0;
|
||||
|
||||
// Check process.exit([code])
|
||||
|
@ -141,3 +138,10 @@ if (process.argv[2] === undefined) {
|
|||
process.exit(args[index].code);
|
||||
}
|
||||
}
|
||||
|
||||
const origExitCode = Object.getOwnPropertyDescriptor(process, 'exitCode');
|
||||
try {
|
||||
delete process.exitCode;
|
||||
} finally {
|
||||
Object.defineProperty(process, 'exitCode', origExitCode);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue