Skip to content

Commit

Permalink
fixup: add warning for process.exitCode
Browse files Browse the repository at this point in the history
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
  • Loading branch information
daeyeon committed Sep 18, 2022
1 parent 799cd8d commit c0d0db8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
25 changes: 25 additions & 0 deletions lib/internal/bootstrap/node.js
Expand Up @@ -86,6 +86,31 @@ process.domain = null;
}
process._exiting = false;

{
const warnIntegerCoercionDeprecation = deprecate(
() => {},
'Implicit coercion to interger for `exit code` is deprecated.',
'DEP0164'
);

let exitCode;

ObjectDefineProperty(process, 'exitCode', {
__proto__: null,
get() {
return exitCode;
},
set(code) {
if (perThreadSetup.isDeprecatedExitCode(code)) {
warnIntegerCoercionDeprecation();
}
exitCode = code;
},
enumerable: true,
configurable: false,
});
}

// process.config is serialized config.gypi
const nativeModule = internalBinding('builtins');

Expand Down
3 changes: 2 additions & 1 deletion lib/internal/process/per_thread.js
Expand Up @@ -185,7 +185,7 @@ function wrapProcessMethods(binding) {
const { deprecate } = require('internal/util');
const warnIntegerCoercionDeprecationSync = deprecate(
() => {},
'Implicit coercion to interger for `code` is deprecated.',
'Implicit coercion to interger for `exit code` is deprecated.',
'DEP0164',
true
);
Expand Down Expand Up @@ -448,4 +448,5 @@ module.exports = {
hrtime,
hrtimeBigInt,
refreshHrtimeBuffer,
isDeprecatedExitCode,
};
4 changes: 2 additions & 2 deletions test/parallel/test-process-exit-code-deprecation.js
Expand Up @@ -82,8 +82,8 @@ if (process.argv[2] === undefined) {
for (const index of args.keys()) {
// Check `process.exit([code])`
test(index);
// TODO: Check exit with `process.exitCode`
// test(index, true);
// Check exit with `process.exitCode`
test(index, true);
}
} else {
const index = parseInt(process.argv[2]);
Expand Down

0 comments on commit c0d0db8

Please sign in to comment.