From c0d0db8707947083a5e930fd1a03f2d86b27ed02 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Sun, 18 Sep 2022 22:23:48 +0900 Subject: [PATCH] fixup: add warning for `process.exitCode` Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com --- lib/internal/bootstrap/node.js | 25 +++++++++++++++++++ lib/internal/process/per_thread.js | 3 ++- .../test-process-exit-code-deprecation.js | 4 +-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 4295ce79d88956..35b79bbc973c21 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -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'); diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 3299d959910247..91d44431cd5b55 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -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 ); @@ -448,4 +448,5 @@ module.exports = { hrtime, hrtimeBigInt, refreshHrtimeBuffer, + isDeprecatedExitCode, }; diff --git a/test/parallel/test-process-exit-code-deprecation.js b/test/parallel/test-process-exit-code-deprecation.js index f9163039f1b02a..17da793dfc2276 100644 --- a/test/parallel/test-process-exit-code-deprecation.js +++ b/test/parallel/test-process-exit-code-deprecation.js @@ -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]);