timers: refactor to use optional chaining

PR-URL: https://github.com/nodejs/node/pull/36767
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
pull/34284/head
ZiJian Liu 2021-01-04 18:39:35 +08:00 committed by James M Snell
parent 9574e5b632
commit d8f535b025
No known key found for this signature in database
GPG Key ID: 7341B15C070877AC
2 changed files with 3 additions and 9 deletions

View File

@ -171,7 +171,7 @@ ObjectDefineProperty(setTimeout, customPromisify, {
});
function clearTimeout(timer) {
if (timer && timer._onTimeout) {
if (timer?._onTimeout) {
timer._onTimeout = null;
unenroll(timer);
return;

View File

@ -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;