From cfe28b161a10dc666797031572a24debe4daa495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Thu, 7 Nov 2024 16:59:12 +0100 Subject: [PATCH] lib: remove unnecessary optional chaining MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/55728 Reviewed-By: Yagiz Nizipli Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell Reviewed-By: LiviaMedeiros Reviewed-By: Gerhard Stöbich Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat --- lib/events.js | 6 +++--- lib/fs.js | 4 ++-- lib/internal/fs/promises.js | 2 +- lib/internal/fs/read/context.js | 2 +- lib/internal/fs/watchers.js | 2 +- lib/timers/promises.js | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/events.js b/lib/events.js index ef97d243a73ae9..50cc720b1247ba 100644 --- a/lib/events.js +++ b/lib/events.js @@ -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); diff --git a/lib/fs.js b/lib/fs.js index 9db60a4f89a3d9..6a7d2cde463597 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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 { diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 76460d2957bb0b..41be9a2a213b13 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -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) { diff --git a/lib/internal/fs/read/context.js b/lib/internal/fs/read/context.js index b1a5d6ae03e953..bbbf4f35e4ba40 100644 --- a/lib/internal/fs/read/context.js +++ b/lib/internal/fs/read/context.js @@ -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); diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js index efa8dd85c64bfb..411eab8136d595 100644 --- a/lib/internal/fs/watchers.js +++ b/lib/internal/fs/watchers.js @@ -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(); diff --git a/lib/timers/promises.js b/lib/timers/promises.js index d205c0df0b602f..61012f42dc2cd3 100644 --- a/lib/timers/promises.js +++ b/lib/timers/promises.js @@ -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;