Skip to content

Commit

Permalink
lib: remove unnecessary optional chaining
Browse files Browse the repository at this point in the history
PR-URL: #55728
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
gurgunday authored and aduh95 committed Nov 16, 2024
1 parent e147935 commit cfe28b1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/read/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/timers/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cfe28b1

Please sign in to comment.