GeezerVison is showing github.com — timers: fix arbitrary object clearImmediate errors · nodejs/node@e4d1042
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/timers.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -275,11 +275,11 @@ ImmediateList.prototype.append = function(item) { |
275 | 275 | // Removes an item from the linked list, adjusting the pointers of adjacent |
276 | 276 | // items and the linked list's head or tail pointers as necessary |
277 | 277 | ImmediateList.prototype.remove = function(item) { |
278 | | - if (item._idleNext !== null) { |
| 278 | + if (item._idleNext) { |
279 | 279 | item._idleNext._idlePrev = item._idlePrev; |
280 | 280 | } |
281 | 281 |
|
282 | | - if (item._idlePrev !== null) { |
| 282 | + if (item._idlePrev) { |
283 | 283 | item._idlePrev._idleNext = item._idleNext; |
284 | 284 | } |
285 | 285 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: lib/timers.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -283,7 +283,7 @@ function clearImmediate(immediate) { |
283 | 283 | toggleImmediateRef(false); |
284 | 284 | immediate[kRefed] = null; |
285 | 285 |
|
286 | | - if (destroyHooksExist()) { |
| 286 | + if (destroyHooksExist() && immediate[async_id_symbol] !== undefined) { |
287 | 287 | emitDestroy(immediate[async_id_symbol]); |
288 | 288 | } |
289 | 289 |
|
|
Collapse file
Copy file name to clipboard +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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'); |
Collapse file
Copy file name to clipboard +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +require('../common'); |
| 3 | + |
| 4 | +// This test makes sure clearing timers with |
| 5 | +// objects doesn't throw |
| 6 | +clearImmediate({}); |
| 7 | +clearTimeout({}); |
| 8 | +clearInterval({}); |