Revert "timers: refactor to use optional chaining"

This reverts commit d8f535b025.

PR-URL: https://github.com/nodejs/node/pull/38245
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
pull/37678/head
Matteo Collina 2021-04-15 12:11:05 +02:00 committed by Beth Griggs
parent 4afcd55274
commit a0261d231c
No known key found for this signature in database
GPG Key ID: D7062848A1AB005C
2 changed files with 9 additions and 3 deletions

View File

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

View File

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