From a0261d231c4353cbea29d0c747c4e604d3dcb6aa 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" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d8f535b0259db91124a14b689cb2514977de6045. PR-URL: https://github.com/nodejs/node/pull/38245 Reviewed-By: Gerhard Stöbich Reviewed-By: Robert Nagy Reviewed-By: Richard Lau Reviewed-By: Antoine du Hamel Reviewed-By: Michaël Zasso Reviewed-By: Zijian Liu Reviewed-By: Beth Griggs Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Michael Dawson Reviewed-By: Rich Trott --- 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;