From 738759a6925986c3944516f50294e8ee5f8ed216 Mon Sep 17 00:00:00 2001 From: ZiJian Liu Date: Mon, 4 Jan 2021 18:39:35 +0800 Subject: [PATCH] timers: refactor to use optional chaining --- lib/timers.js | 2 +- lib/timers/promises.js | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/timers.js b/lib/timers.js index 6cb64b98b5cdc0..3cce2e37b007e8 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -171,7 +171,7 @@ ObjectDefineProperty(setTimeout, customPromisify, { }); function clearTimeout(timer) { - if (timer && timer._onTimeout) { + if (timer?._onTimeout) { timer._onTimeout = null; unenroll(timer); return; diff --git a/lib/timers/promises.js b/lib/timers/promises.js index 55d554bb838e95..c46b98f798ccaf 100644 --- a/lib/timers/promises.js +++ b/lib/timers/promises.js @@ -49,10 +49,7 @@ function setTimeout(after, value, options = {}) { 'boolean', ref)); } - // TODO(@jasnell): If a decision is made that this cannot be backported - // to 12.x, then this can be converted to use optional chaining to - // simplify the check. - if (signal && signal.aborted) { + if (signal?.aborted) { return PromiseReject(new AbortError()); } let oncancel; @@ -94,10 +91,7 @@ function setImmediate(value, options = {}) { 'boolean', ref)); } - // TODO(@jasnell): If a decision is made that this cannot be backported - // to 12.x, then this can be converted to use optional chaining to - // simplify the check. - if (signal && signal.aborted) { + if (signal?.aborted) { return PromiseReject(new AbortError()); } let oncancel;