lib: remove unnecessary optional chaining

PR-URL: https://github.com/nodejs/node/pull/55728
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Gürgün Dayıoğlu 2024-11-07 16:59:12 +01:00 committed by GitHub
parent 34dc8e37bf
commit 7788999ac1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 9 additions and 9 deletions

View File

@ -958,10 +958,10 @@ function getMaxListeners(emitterOrTarget) {
*/
async function once(emitter, name, options = kEmptyObject) {
validateObject(options, 'options');
const signal = options?.signal;
const { signal } = options;
validateAbortSignal(signal, 'options.signal');
if (signal?.aborted)
throw new AbortError(undefined, { cause: signal?.reason });
throw new AbortError(undefined, { cause: signal.reason });
return new Promise((resolve, reject) => {
const errorListener = (err) => {
emitter.removeListener(name, resolver);
@ -1049,7 +1049,7 @@ function on(emitter, event, options = kEmptyObject) {
const signal = options.signal;
validateAbortSignal(signal, 'options.signal');
if (signal?.aborted)
throw new AbortError(undefined, { cause: signal?.reason });
throw new AbortError(undefined, { cause: signal.reason });
// Support both highWaterMark and highWatermark for backward compatibility
const highWatermark = options.highWaterMark ?? options.highWatermark ?? NumberMAX_SAFE_INTEGER;
validateInteger(highWatermark, 'options.highWaterMark', 1);

View File

@ -340,7 +340,7 @@ function readFileAfterStat(err, stats) {
function checkAborted(signal, callback) {
if (signal?.aborted) {
callback(new AbortError(undefined, { cause: signal?.reason }));
callback(new AbortError(undefined, { cause: signal.reason }));
return true;
}
return false;
@ -2204,7 +2204,7 @@ function lutimesSync(path, atime, mtime) {
function writeAll(fd, isUserFd, buffer, offset, length, signal, flush, callback) {
if (signal?.aborted) {
const abortError = new AbortError(undefined, { cause: signal?.reason });
const abortError = new AbortError(undefined, { cause: signal.reason });
if (isUserFd) {
callback(abortError);
} else {

View File

@ -471,7 +471,7 @@ async function fsCall(fn, handle, ...args) {
function checkAborted(signal) {
if (signal?.aborted)
throw new AbortError(undefined, { cause: signal?.reason });
throw new AbortError(undefined, { cause: signal.reason });
}
async function writeFileHandle(filehandle, data, signal, encoding) {

View File

@ -89,7 +89,7 @@ class ReadFileContext {
if (this.signal?.aborted) {
return this.close(
new AbortError(undefined, { cause: this.signal?.reason }));
new AbortError(undefined, { cause: this.signal.reason }));
}
if (this.size === 0) {
buffer = Buffer.allocUnsafeSlow(kReadFileUnknownBufferLength);

View File

@ -322,7 +322,7 @@ async function* watch(filename, options = kEmptyObject) {
}
if (signal?.aborted)
throw new AbortError(undefined, { cause: signal?.reason });
throw new AbortError(undefined, { cause: signal.reason });
const handle = new FSEvent();
let { promise, resolve, reject } = PromiseWithResolvers();

View File

@ -147,7 +147,7 @@ async function* setInterval(after, value, options = kEmptyObject) {
const { signal, ref = true } = options;
if (signal?.aborted) {
throw new AbortError(undefined, { cause: signal?.reason });
throw new AbortError(undefined, { cause: signal.reason });
}
let onCancel;