| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cf375e7 commit 515dd24
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -152,6 +152,11 @@ const timerListQueue = new PriorityQueue(compareTimersLists, setPosition); | |||
| 152 | 152 | // - value = linked list | |
| 153 | 153 | const timerListMap = { __proto__: null }; | |
| 154 | 154 | ||
| 155 | + // This stores all the known timer async ids to allow users to clearTimeout and | ||
| 156 | + // clearInterval using those ids, to match the spec and the rest of the web | ||
| 157 | + // platform. | ||
| 158 | + const knownTimersById = { __proto__: null }; | ||
| 159 | + | ||
| 155 | 160 | function initAsyncResource(resource, type) { | |
| 156 | 161 | const asyncId = resource[async_id_symbol] = newAsyncId(); | |
| 157 | 162 | const triggerAsyncId = | |
@@ -550,6 +555,9 @@ function getTimerCallbacks(runNextTicks) { | |||
| 550 | 555 | if (!timer._destroyed) { | |
| 551 | 556 | timer._destroyed = true; | |
| 552 | 557 | ||
| 558 | + if (timer[kHasPrimitive]) | ||
| 559 | + delete knownTimersById[asyncId]; | ||
| 560 | + | ||
| 553 | 561 | if (timer[kRefed]) | |
| 554 | 562 | timeoutInfo[0]--; | |
| 555 | 563 | ||
@@ -580,6 +588,9 @@ function getTimerCallbacks(runNextTicks) { | |||
| 580 | 588 | } else if (!timer._idleNext && !timer._idlePrev && !timer._destroyed) { | |
| 581 | 589 | timer._destroyed = true; | |
| 582 | 590 | ||
| 591 | + if (timer[kHasPrimitive]) | ||
| 592 | + delete knownTimersById[asyncId]; | ||
| 593 | + | ||
| 583 | 594 | if (timer[kRefed]) | |
| 584 | 595 | timeoutInfo[0]--; | |
| 585 | 596 | ||
@@ -683,4 +694,5 @@ module.exports = { | |||
| 683 | 694 | timerListQueue, | |
| 684 | 695 | decRefCount, | |
| 685 | 696 | incRefCount, | |
| 697 | + knownTimersById, | ||
| 686 | 698 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,6 +52,7 @@ const { | |||
| 52 | 52 | active, | |
| 53 | 53 | unrefActive, | |
| 54 | 54 | insert, | |
| 55 | + knownTimersById, | ||
| 55 | 56 | } = require('internal/timers'); | |
| 56 | 57 | const { | |
| 57 | 58 | promisify: { custom: customPromisify }, | |
@@ -71,11 +72,6 @@ const { | |||
| 71 | 72 | emitDestroy, | |
| 72 | 73 | } = require('internal/async_hooks'); | |
| 73 | 74 | ||
| 74 | - // This stores all the known timer async ids to allow users to clearTimeout and | ||
| 75 | - // clearInterval using those ids, to match the spec and the rest of the web | ||
| 76 | - // platform. | ||
| 77 | - const knownTimersById = { __proto__: null }; | ||
| 78 | - | ||
| 79 | 75 | // Remove a timer. Cancels the timeout and resets the relevant timer properties. | |
| 80 | 76 | function unenroll(item) { | |
| 81 | 77 | if (item._destroyed) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,6 @@ | |||
| 6 | 6 | Error: goodbye | |
| 7 | 7 | at Hello (*uglify-throw-original.js:5:9) | |
| 8 | 8 | at Immediate.<anonymous> (*uglify-throw-original.js:9:3) | |
| 9 | - at process.processImmediate (node:internal*timers:478:21) | ||
| 9 | + at process.processImmediate (node:internal*timers:483:21) | ||
| 10 | 10 | ||
| 11 | 11 | Node.js * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // Flags: --expose-gc | ||
| 3 | + require('../common'); | ||
| 4 | + const onGC = require('../common/ongc'); | ||
| 5 | + | ||
| 6 | + // See https://github.com/nodejs/node/issues/53335 | ||
| 7 | + const poller = setInterval(() => { | ||
| 8 | + global.gc(); | ||
| 9 | + }, 100); | ||
| 10 | + | ||
| 11 | + let count = 0; | ||
| 12 | + | ||
| 13 | + for (let i = 0; i < 10; i++) { | ||
| 14 | + const timer = setTimeout(() => {}, 0); | ||
| 15 | + onGC(timer, { | ||
| 16 | + ongc: () => { | ||
| 17 | + if (++count === 10) { | ||
| 18 | + clearInterval(poller); | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + }); | ||
| 22 | + console.log(+timer); | ||
| 23 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments