timers: check for immediate instance in clearImmediate

PR-URL: https://github.com/nodejs/node/pull/57069
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
Gürgün Dayıoğlu 2025-03-02 00:54:52 +01:00 committed by GitHub
parent d1ec948866
commit 6b0af1748c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -301,7 +301,7 @@ ObjectDefineProperty(setImmediate, customPromisify, {
* @returns {void}
*/
function clearImmediate(immediate) {
if (!immediate || immediate._destroyed)
if (!immediate?._onImmediate || immediate._destroyed)
return;
immediateInfo[kCount]--;

View File

@ -0,0 +1,13 @@
'use strict';
const common = require('../common');
// clearImmediate should be a noop if anything other than an Immediate
// is passed to it.
const t = setTimeout(common.mustCall());
clearImmediate(t);
setTimeout(common.mustCall());
setTimeout(common.mustCall());