timers: fix arbitrary object clearImmediate errors · nodejs/node@d44b268 · GitHub
Skip to content

Commit d44b268

Browse files
Linkgoronruyadorno
authored andcommitted
timers: fix arbitrary object clearImmediate errors
Fix errors that are caused by invoking clearImmediate with arbitrary objects. fixes: #37806 PR-URL: #37824 Fixes: #37806 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent ac60d01 commit d44b268

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

lib/internal/timers.js

Lines changed: 2 additions & 2 deletions

lib/timers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function clearImmediate(immediate) {
283283
toggleImmediateRef(false);
284284
immediate[kRefed] = null;
285285

286-
if (destroyHooksExist()) {
286+
if (destroyHooksExist() && immediate[async_id_symbol] !== undefined) {
287287
emitDestroy(immediate[async_id_symbol]);
288288
}
289289

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
const common = require('../common');
3+
const child_process = require('child_process');
4+
const assert = require('assert');
5+
6+
// Regression test for https://github.com/nodejs/node/issues/37806:
7+
const proc = child_process.spawn(process.execPath, ['-i']);
8+
proc.on('error', common.mustNotCall());
9+
proc.on('exit', common.mustCall((code) => {
10+
assert.strictEqual(code, 0);
11+
}));
12+
proc.stdin.write('clearImmediate({});\n.exit\n');
Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)