mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
timers: fix arbitrary object clearImmediate errors
Fix errors that are caused by invoking clearImmediate with arbitrary objects. fixes: https://github.com/nodejs/node/issues/37806 PR-URL: https://github.com/nodejs/node/pull/37824 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
dbe710512f
commit
fcc934f3d0
@ -279,11 +279,11 @@ ImmediateList.prototype.append = function(item) {
|
||||
// Removes an item from the linked list, adjusting the pointers of adjacent
|
||||
// items and the linked list's head or tail pointers as necessary
|
||||
ImmediateList.prototype.remove = function(item) {
|
||||
if (item._idleNext !== null) {
|
||||
if (item._idleNext) {
|
||||
item._idleNext._idlePrev = item._idlePrev;
|
||||
}
|
||||
|
||||
if (item._idlePrev !== null) {
|
||||
if (item._idlePrev) {
|
||||
item._idlePrev._idleNext = item._idleNext;
|
||||
}
|
||||
|
||||
|
@ -283,7 +283,7 @@ function clearImmediate(immediate) {
|
||||
toggleImmediateRef(false);
|
||||
immediate[kRefed] = null;
|
||||
|
||||
if (destroyHooksExist()) {
|
||||
if (destroyHooksExist() && immediate[async_id_symbol] !== undefined) {
|
||||
emitDestroy(immediate[async_id_symbol]);
|
||||
}
|
||||
|
||||
|
12
test/parallel/test-repl-clear-immediate-crash.js
Normal file
12
test/parallel/test-repl-clear-immediate-crash.js
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const child_process = require('child_process');
|
||||
const assert = require('assert');
|
||||
|
||||
// Regression test for https://github.com/nodejs/node/issues/37806:
|
||||
const proc = child_process.spawn(process.execPath, ['-i']);
|
||||
proc.on('error', common.mustNotCall());
|
||||
proc.on('exit', common.mustCall((code) => {
|
||||
assert.strictEqual(code, 0);
|
||||
}));
|
||||
proc.stdin.write('clearImmediate({});\n.exit\n');
|
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
|
||||
// This test makes sure clearing timers with
|
||||
// objects doesn't throw
|
||||
clearImmediate({});
|
||||
clearTimeout({});
|
||||
clearInterval({});
|
Loading…
Reference in New Issue
Block a user