Skip to content

Commit c0d0db8

Browse files
committed
fixup: add warning for process.exitCode
Signed-off-by: Daeyeon Jeong [email protected]
1 parent 799cd8d commit c0d0db8

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

lib/internal/bootstrap/node.js

+25
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,31 @@ process.domain = null;
8686
}
8787
process._exiting = false;
8888

89+
{
90+
const warnIntegerCoercionDeprecation = deprecate(
91+
() => {},
92+
'Implicit coercion to interger for `exit code` is deprecated.',
93+
'DEP0164'
94+
);
95+
96+
let exitCode;
97+
98+
ObjectDefineProperty(process, 'exitCode', {
99+
__proto__: null,
100+
get() {
101+
return exitCode;
102+
},
103+
set(code) {
104+
if (perThreadSetup.isDeprecatedExitCode(code)) {
105+
warnIntegerCoercionDeprecation();
106+
}
107+
exitCode = code;
108+
},
109+
enumerable: true,
110+
configurable: false,
111+
});
112+
}
113+
89114
// process.config is serialized config.gypi
90115
const nativeModule = internalBinding('builtins');
91116

lib/internal/process/per_thread.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function wrapProcessMethods(binding) {
185185
const { deprecate } = require('internal/util');
186186
const warnIntegerCoercionDeprecationSync = deprecate(
187187
() => {},
188-
'Implicit coercion to interger for `code` is deprecated.',
188+
'Implicit coercion to interger for `exit code` is deprecated.',
189189
'DEP0164',
190190
true
191191
);
@@ -448,4 +448,5 @@ module.exports = {
448448
hrtime,
449449
hrtimeBigInt,
450450
refreshHrtimeBuffer,
451+
isDeprecatedExitCode,
451452
};

test/parallel/test-process-exit-code-deprecation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ if (process.argv[2] === undefined) {
8282
for (const index of args.keys()) {
8383
// Check `process.exit([code])`
8484
test(index);
85-
// TODO: Check exit with `process.exitCode`
86-
// test(index, true);
85+
// Check exit with `process.exitCode`
86+
test(index, true);
8787
}
8888
} else {
8989
const index = parseInt(process.argv[2]);

0 commit comments

Comments
 (0)