From c87d6365007fc3bcb907523e15cff2ec07e062e2 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 15 Apr 2021 12:11:05 +0200 Subject: [PATCH] Revert "timers: refactor to use optional chaining" This reverts commit d8f535b0259db91124a14b689cb2514977de6045. --- lib/timers.js | 2 +- lib/timers/promises.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/timers.js b/lib/timers.js index 73844fdbcc7613..485f577d29f2f0 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -171,7 +171,7 @@ ObjectDefineProperty(setTimeout, customPromisify, { }); function clearTimeout(timer) { - if (timer?._onTimeout) { + if (timer && timer._onTimeout) { timer._onTimeout = null; unenroll(timer); return; diff --git a/lib/timers/promises.js b/lib/timers/promises.js index cc2d264d987e20..ec13e873d8443c 100644 --- a/lib/timers/promises.js +++ b/lib/timers/promises.js @@ -53,7 +53,10 @@ function setTimeout(after, value, options = {}) { 'boolean', ref)); } - if (signal?.aborted) { + // 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) { return PromiseReject(new AbortError()); } let oncancel; @@ -95,7 +98,10 @@ function setImmediate(value, options = {}) { 'boolean', ref)); } - if (signal?.aborted) { + // 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) { return PromiseReject(new AbortError()); } let oncancel;