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:
Jordan Harband 2023-09-09 15:28:21 -07:00
parent 362afa52eb
commit c8e87a1ec6
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
2 changed files with 10 additions and 6 deletions

View File

@ -129,7 +129,7 @@ process.domain = null;
exitCode = code;
},
enumerable: true,
configurable: false,
configurable: true,
});
}
process._exiting = false;

View File

@ -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);
}