Skip to content

Commit 2d0d997

Browse files
authored
process: remove process.exit(), process.exitCode coercion to integer
This removes the deprecation, `DEP0164` and validates the exit code for both `process.exit([code])` and `process.exitCode`. Signed-off-by: Daeyeon Jeong <[email protected]> PR-URL: #43716 Refs: #43738 Refs: #44714 Refs: #44711 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 19f3973 commit 2d0d997

7 files changed

+176
-148
lines changed

doc/api/deprecations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3178,6 +3178,9 @@ thing instead.
31783178

31793179
<!-- YAML
31803180
changes:
3181+
- version: REPLACEME
3182+
pr-url: https://github.com/nodejs/node/pull/43716
3183+
description: End-of-Life.
31813184
- version: v19.0.0
31823185
pr-url: https://github.com/nodejs/node/pull/44711
31833186
description: Runtime deprecation.
@@ -3195,7 +3198,7 @@ changes:
31953198
coercion.
31963199
-->
31973200

3198-
Type: Runtime
3201+
Type: End-of-Life
31993202

32003203
Values other than `undefined`, `null`, integer numbers, and integer strings
32013204
(e.g., `'1'`) are deprecated as value for the `code` parameter in

doc/api/process.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,9 +1708,15 @@ that started the Node.js process. Symbolic links, if any, are resolved.
17081708
17091709
<!-- YAML
17101710
added: v0.1.13
1711+
changes:
1712+
- version: REPLACEME
1713+
pr-url: https://github.com/nodejs/node/pull/43716
1714+
description: Only accepts a code of type number, or of type string if it
1715+
represents an integer.
17111716
-->
17121717
1713-
* `code` {integer} The exit code. **Default:** `0`.
1718+
* `code` {integer|string|null|undefined} The exit code. For string type, only
1719+
integer strings (e.g.,'1') are allowed. **Default:** `0`.
17141720
17151721
The `process.exit()` method instructs Node.js to terminate the process
17161722
synchronously with an exit status of `code`. If `code` is omitted, exit uses
@@ -1810,9 +1816,15 @@ than the current process.
18101816
18111817
<!-- YAML
18121818
added: v0.11.8
1819+
changes:
1820+
- version: REPLACEME
1821+
pr-url: https://github.com/nodejs/node/pull/43716
1822+
description: Only accepts a code of type number, or of type string if it
1823+
represents an integer.
18131824
-->
18141825
1815-
* {integer}
1826+
* {integer|string|null|undefined} The exit code. For string type, only
1827+
integer strings (e.g.,'1') are allowed. **Default:** `undefined`.
18161828
18171829
A number which will be the process exit code, when the process either
18181830
exits gracefully, or is exited via [`process.exit()`][] without specifying

lib/internal/bootstrap/node.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const {
6060
ArrayPrototypeFill,
6161
FunctionPrototypeCall,
6262
JSONParse,
63+
Number,
64+
NumberIsNaN,
6365
ObjectDefineProperty,
6466
ObjectGetPrototypeOf,
6567
ObjectSetPrototypeOf,
@@ -74,6 +76,9 @@ const {
7476
deprecate,
7577
exposeInterface,
7678
} = require('internal/util');
79+
const {
80+
validateInteger,
81+
} = require('internal/validators');
7782
const {
7883
exiting_aliased_Uint32Array,
7984
getHiddenValue,
@@ -103,12 +108,6 @@ process.domain = null;
103108
process._exiting = false;
104109

105110
{
106-
const warnIntegerCoercionDeprecation = deprecate(
107-
() => {},
108-
'Implicit coercion to integer for exit code is deprecated.',
109-
'DEP0164'
110-
);
111-
112111
let exitCode;
113112

114113
ObjectDefineProperty(process, 'exitCode', {
@@ -117,8 +116,13 @@ process._exiting = false;
117116
return exitCode;
118117
},
119118
set(code) {
120-
if (perThreadSetup.isDeprecatedExitCode(code)) {
121-
warnIntegerCoercionDeprecation();
119+
if (code !== null && code !== undefined) {
120+
let value = code;
121+
if (typeof code === 'string' && code !== '' &&
122+
NumberIsNaN((value = Number(code)))) {
123+
value = code;
124+
}
125+
validateInteger(value, 'code');
122126
}
123127
exitCode = code;
124128
},

lib/internal/process/per_thread.js

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ const {
1313
ArrayPrototypeSplice,
1414
BigUint64Array,
1515
Float64Array,
16-
Number,
17-
NumberIsInteger,
1816
NumberMAX_SAFE_INTEGER,
19-
NumberMIN_SAFE_INTEGER,
2017
ObjectFreeze,
2118
ObjectDefineProperty,
2219
ReflectApply,
@@ -183,25 +180,12 @@ function wrapProcessMethods(binding) {
183180

184181
memoryUsage.rss = rss;
185182

186-
const { deprecate } = require('internal/util');
187-
const warnIntegerCoercionDeprecationSync = deprecate(
188-
() => {},
189-
'Implicit coercion to integer for exit code is deprecated.',
190-
'DEP0164',
191-
true
192-
);
193-
194183
function exit(code) {
195184
process.off('exit', handleProcessExit);
196185

197-
if (isDeprecatedExitCode(code)) {
198-
// Emit the deprecation warning synchronously since deprecation warning is
199-
// generally emitted in a next tick but we have no next tick timing here.
200-
warnIntegerCoercionDeprecationSync();
201-
}
202-
203-
if (code || code === 0)
186+
if (arguments.length !== 0) {
204187
process.exitCode = code;
188+
}
205189

206190
if (!process._exiting) {
207191
process._exiting = true;
@@ -424,23 +408,6 @@ function toggleTraceCategoryState(asyncHooksEnabled) {
424408
}
425409
}
426410

427-
function isDeprecatedExitCode(code) {
428-
if (code !== null && code !== undefined) {
429-
const value =
430-
typeof code === 'string' && code !== '' ? Number(code) : code;
431-
// Check if the value is an integer.
432-
if (
433-
typeof value !== 'number' ||
434-
!NumberIsInteger(value) ||
435-
value < NumberMIN_SAFE_INTEGER ||
436-
value > NumberMAX_SAFE_INTEGER
437-
) {
438-
return true;
439-
}
440-
}
441-
return false;
442-
}
443-
444411
module.exports = {
445412
toggleTraceCategoryState,
446413
assert,
@@ -449,5 +416,4 @@ module.exports = {
449416
hrtime,
450417
hrtimeBigInt,
451418
refreshHrtimeBuffer,
452-
isDeprecatedExitCode,
453419
};

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

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)