Skip to content

Commit

Permalink
fixup: remove the range restriction
Browse files Browse the repository at this point in the history
Signed-off-by: Daeyeon Jeong [email protected]
  • Loading branch information
daeyeon committed Jul 8, 2022
1 parent dcc27ac commit 82930d5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ that started the Node.js process. Symbolic links, if any, are resolved.
added: v0.1.13
-->
* `code` {integer} The exit code in the range `0``255`. **Default:** `0`.
* `code` {integer} The exit code. **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
2 changes: 1 addition & 1 deletion lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function wrapProcessMethods(binding) {
process.off('exit', handleProcessExit);

if (code !== null && code !== undefined) {
validateInteger(code, 'code', 0, 255);
validateInteger(code, 'code');
process.exitCode = code;
}

Expand Down
15 changes: 2 additions & 13 deletions test/parallel/test-process-exit-code-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,14 @@ require('../common');
const { strictEqual } = require('node:assert');

const isParent = () => process.argv[2] === undefined;
const invalid_type_samples = ['', '0', {}, [], true, false];
const out_of_range_samples = [-1, 256];
const args = [...invalid_type_samples, ...out_of_range_samples];
const args = ['', '0', {}, [], true, false];

if (isParent()) {
const { spawn } = require('node:child_process');

// Test the samples.
strictEqual(
invalid_type_samples.every(
(v) => typeof v !== 'number' && v !== null && v !== undefined,
),
true,
);

strictEqual(
out_of_range_samples.every(
(v) => typeof v == 'number' && (v < 0 || v > 255),
),
args.every((v) => typeof v !== 'number' && v !== null && v !== undefined),
true,
);

Expand Down

0 comments on commit 82930d5

Please sign in to comment.