@@ -55,7 +55,7 @@ const activateImmediateCheck = process._activateImmediateCheck;
55
55
delete process . _activateImmediateCheck ;
56
56
57
57
// Timeout values > TIMEOUT_MAX are set to 1.
58
- const TIMEOUT_MAX = 2147483647 ; // 2^31-1
58
+ const TIMEOUT_MAX = 2 ** 31 - 1 ;
59
59
60
60
61
61
// HOW and WHY the timers implementation works the way it does.
@@ -173,9 +173,9 @@ function insert(item, unrefed) {
173
173
174
174
// Use an existing list if there is one, otherwise we need to make a new one.
175
175
var list = lists [ msecs ] ;
176
- if ( ! list ) {
176
+ if ( list === undefined ) {
177
177
debug ( 'no %d list was found in insert, creating a new one' , msecs ) ;
178
- lists [ msecs ] = list = createTimersList ( msecs , unrefed ) ;
178
+ lists [ msecs ] = list = new TimersList ( msecs , unrefed ) ;
179
179
}
180
180
181
181
if ( ! item [ async_id_symbol ] || item . _destroyed ) {
@@ -194,28 +194,21 @@ function insert(item, unrefed) {
194
194
assert ( ! L . isEmpty ( list ) ) ; // list is not empty
195
195
}
196
196
197
- function createTimersList ( msecs , unrefed ) {
198
- // Make a new linked list of timers, and create a TimerWrap to schedule
199
- // processing for the list.
200
- const list = new TimersList ( msecs , unrefed ) ;
201
- L . init ( list ) ;
202
- list . _timer . _list = list ;
203
-
204
- if ( unrefed === true ) list . _timer . unref ( ) ;
205
- list . _timer . start ( msecs ) ;
206
-
207
- list . _timer [ kOnTimeout ] = listOnTimeout ;
208
-
209
- return list ;
210
- }
211
-
212
197
function TimersList ( msecs , unrefed ) {
213
- this . _idleNext = null ; // Create the list with the linkedlist properties to
214
- this . _idlePrev = null ; // prevent any unnecessary hidden class changes.
215
- this . _timer = new TimerWrap ( ) ;
198
+ this . _idleNext = this ; // Create the list with the linkedlist properties to
199
+ this . _idlePrev = this ; // prevent any unnecessary hidden class changes.
216
200
this . _unrefed = unrefed ;
217
201
this . msecs = msecs ;
218
202
this . nextTick = false ;
203
+
204
+ const timer = this . _timer = new TimerWrap ( ) ;
205
+ timer . _list = this ;
206
+
207
+ if ( unrefed === true )
208
+ timer . unref ( ) ;
209
+ timer . start ( msecs ) ;
210
+
211
+ timer [ kOnTimeout ] = listOnTimeout ;
219
212
}
220
213
221
214
function listOnTimeout ( ) {
@@ -359,7 +352,7 @@ function reuse(item) {
359
352
360
353
var list = refedLists [ item . _idleTimeout ] ;
361
354
// if empty - reuse the watcher
362
- if ( list && L . isEmpty ( list ) ) {
355
+ if ( list !== undefined && L . isEmpty ( list ) ) {
363
356
debug ( 'reuse hit' ) ;
364
357
list . _timer . stop ( ) ;
365
358
delete refedLists [ item . _idleTimeout ] ;
@@ -382,7 +375,7 @@ const unenroll = exports.unenroll = function(item) {
382
375
}
383
376
384
377
var handle = reuse ( item ) ;
385
- if ( handle ) {
378
+ if ( handle !== null ) {
386
379
debug ( 'unenroll: list empty' ) ;
387
380
handle . close ( ) ;
388
381
}
@@ -610,7 +603,7 @@ Timeout.prototype.unref = function() {
610
603
}
611
604
612
605
var handle = reuse ( this ) ;
613
- if ( handle ) {
606
+ if ( handle !== null ) {
614
607
handle . _list = undefined ;
615
608
}
616
609
@@ -659,7 +652,7 @@ function ImmediateList() {
659
652
// Appends an item to the end of the linked list, adjusting the current tail's
660
653
// previous and next pointers where applicable
661
654
ImmediateList . prototype . append = function ( item ) {
662
- if ( this . tail ) {
655
+ if ( this . tail !== null ) {
663
656
this . tail . _idleNext = item ;
664
657
item . _idlePrev = this . tail ;
665
658
} else {
@@ -671,11 +664,11 @@ ImmediateList.prototype.append = function(item) {
671
664
// Removes an item from the linked list, adjusting the pointers of adjacent
672
665
// items and the linked list's head or tail pointers as necessary
673
666
ImmediateList . prototype . remove = function ( item ) {
674
- if ( item . _idleNext ) {
667
+ if ( item . _idleNext !== null ) {
675
668
item . _idleNext . _idlePrev = item . _idlePrev ;
676
669
}
677
670
678
- if ( item . _idlePrev ) {
671
+ if ( item . _idlePrev !== null ) {
679
672
item . _idlePrev . _idleNext = item . _idleNext ;
680
673
}
681
674
@@ -701,7 +694,7 @@ function processImmediate() {
701
694
// immediate callbacks are executed
702
695
immediateQueue . head = immediateQueue . tail = null ;
703
696
704
- while ( immediate ) {
697
+ while ( immediate !== null ) {
705
698
domain = immediate . domain ;
706
699
707
700
if ( ! immediate . _onImmediate ) {
@@ -722,7 +715,7 @@ function processImmediate() {
722
715
723
716
// If `clearImmediate(immediate)` wasn't called from the callback, use the
724
717
// `immediate`'s next item
725
- if ( immediate . _idleNext )
718
+ if ( immediate . _idleNext !== null )
726
719
immediate = immediate . _idleNext ;
727
720
else
728
721
immediate = next ;
@@ -754,11 +747,11 @@ function tryOnImmediate(immediate, oldTail) {
754
747
}
755
748
}
756
749
757
- if ( threw && immediate . _idleNext ) {
750
+ if ( threw && immediate . _idleNext !== null ) {
758
751
// Handle any remaining on next tick, assuming we're still alive to do so.
759
752
const curHead = immediateQueue . head ;
760
753
const next = immediate . _idleNext ;
761
- if ( curHead ) {
754
+ if ( curHead !== null ) {
762
755
curHead . _idlePrev = oldTail ;
763
756
oldTail . _idleNext = curHead ;
764
757
next . _idlePrev = null ;
0 commit comments