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;