Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: remove process.exit(), process.exitCode coercion to integer #43716

Merged
merged 3 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3178,6 +3178,9 @@ thing instead.

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/43716
description: End-of-Life.
- version: v19.0.0
pr-url: https://github.com/nodejs/node/pull/44711
description: Runtime deprecation.
Expand All @@ -3195,7 +3198,7 @@ changes:
coercion.
-->

Type: Runtime
Type: End-of-Life

Values other than `undefined`, `null`, integer numbers, and integer strings
(e.g., `'1'`) are deprecated as value for the `code` parameter in
Expand Down
16 changes: 14 additions & 2 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1708,9 +1708,15 @@ that started the Node.js process. Symbolic links, if any, are resolved.

<!-- YAML
added: v0.1.13
daeyeon marked this conversation as resolved.
Show resolved Hide resolved
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/43716
description: Only accepts a code of type number, or of type string if it
represents an integer.
-->

* `code` {integer} The exit code. **Default:** `0`.
* `code` {integer|string|null|undefined} The exit code. For string type, only
integer strings (e.g.,'1') are allowed. **Default:** `0`.

The `process.exit()` method instructs Node.js to terminate the process
synchronously with an exit status of `code`. If `code` is omitted, exit uses
Expand Down Expand Up @@ -1810,9 +1816,15 @@ than the current process.

<!-- YAML
added: v0.11.8
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/43716
description: Only accepts a code of type number, or of type string if it
represents an integer.
-->

* {integer}
* {integer|string|null|undefined} The exit code. For string type, only
integer strings (e.g.,'1') are allowed. **Default:** `undefined`.

A number which will be the process exit code, when the process either
exits gracefully, or is exited via [`process.exit()`][] without specifying
Expand Down
20 changes: 12 additions & 8 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const {
ArrayPrototypeFill,
FunctionPrototypeCall,
JSONParse,
Number,
NumberIsNaN,
ObjectDefineProperty,
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
Expand All @@ -74,6 +76,9 @@ const {
deprecate,
exposeInterface,
} = require('internal/util');
const {
validateInteger,
} = require('internal/validators');
const {
exiting_aliased_Uint32Array,
getHiddenValue,
Expand Down Expand Up @@ -103,12 +108,6 @@ process.domain = null;
process._exiting = false;

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

let exitCode;

ObjectDefineProperty(process, 'exitCode', {
Expand All @@ -117,8 +116,13 @@ process._exiting = false;
return exitCode;
},
set(code) {
if (perThreadSetup.isDeprecatedExitCode(code)) {
warnIntegerCoercionDeprecation();
if (code !== null && code !== undefined) {
let value = code;
if (typeof code === 'string' && code !== '' &&
NumberIsNaN((value = Number(code)))) {
value = code;
}
validateInteger(value, 'code');
}
exitCode = code;
},
Expand Down
38 changes: 2 additions & 36 deletions lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const {
ArrayPrototypeSplice,
BigUint64Array,
Float64Array,
Number,
NumberIsInteger,
NumberMAX_SAFE_INTEGER,
NumberMIN_SAFE_INTEGER,
ObjectFreeze,
ObjectDefineProperty,
ReflectApply,
Expand Down Expand Up @@ -183,25 +180,12 @@ function wrapProcessMethods(binding) {

memoryUsage.rss = rss;

const { deprecate } = require('internal/util');
const warnIntegerCoercionDeprecationSync = deprecate(
() => {},
'Implicit coercion to integer for exit code is deprecated.',
'DEP0164',
true
);

function exit(code) {
process.off('exit', handleProcessExit);

if (isDeprecatedExitCode(code)) {
// Emit the deprecation warning synchronously since deprecation warning is
// generally emitted in a next tick but we have no next tick timing here.
warnIntegerCoercionDeprecationSync();
}

if (code || code === 0)
if (arguments.length !== 0) {
process.exitCode = code;
}

if (!process._exiting) {
process._exiting = true;
Expand Down Expand Up @@ -424,23 +408,6 @@ function toggleTraceCategoryState(asyncHooksEnabled) {
}
}

function isDeprecatedExitCode(code) {
if (code !== null && code !== undefined) {
const value =
typeof code === 'string' && code !== '' ? Number(code) : code;
// Check if the value is an integer.
if (
typeof value !== 'number' ||
!NumberIsInteger(value) ||
value < NumberMIN_SAFE_INTEGER ||
value > NumberMAX_SAFE_INTEGER
) {
return true;
}
}
return false;
}

module.exports = {
toggleTraceCategoryState,
assert,
Expand All @@ -449,5 +416,4 @@ module.exports = {
hrtime,
hrtimeBigInt,
refreshHrtimeBuffer,
isDeprecatedExitCode,
};
100 changes: 0 additions & 100 deletions test/parallel/test-process-exit-code-deprecation.js

This file was deleted.

Loading