fix: validate integer values in Deno.exitCode setter (#24068)

This commit is contained in:
Kenta Moriuchi 2024-06-03 10:29:01 +09:00 committed by GitHub
parent 754f21f0cd
commit eda43c46de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 90 additions and 135 deletions

View file

@ -22,7 +22,8 @@ import {
const {
Error,
FunctionPrototypeBind,
NumberParseInt,
NumberIsInteger,
RangeError,
SymbolFor,
TypeError,
} = primordials;
@ -102,13 +103,17 @@ function getExitCode() {
}
function setExitCode(value) {
const code = NumberParseInt(value, 10);
if (typeof code !== "number") {
if (typeof value !== "number") {
throw new TypeError(
`Exit code must be a number, got: ${code} (${typeof code}).`,
`Exit code must be a number, got: ${value} (${typeof value})`,
);
}
op_set_exit_code(code);
if (!NumberIsInteger(value)) {
throw new RangeError(
`Exit code must be an integer, got: ${value}`,
);
}
op_set_exit_code(value);
}
function setEnv(key, value) {