@@ -303,13 +303,17 @@ class ImmediateList {
303303const immediateQueue = new ImmediateList ( ) ;
304304
305305function incRefCount ( ) {
306- if ( timeoutInfo [ 0 ] ++ === 0 )
306+ if ( timeoutInfo [ 0 ] ++ === 0 ) {
307+ // We need to use the binding as the receiver for fast API calls.
307308 binding . toggleTimerRef ( true ) ;
309+ }
308310}
309311
310312function decRefCount ( ) {
311- if ( -- timeoutInfo [ 0 ] === 0 )
313+ if ( -- timeoutInfo [ 0 ] === 0 ) {
314+ // We need to use the binding as the receiver for fast API calls.
312315 binding . toggleTimerRef ( false ) ;
316+ }
313317}
314318
315319// Schedule or re-schedule a timer.
@@ -353,6 +357,7 @@ function insertGuarded(item, refed, start) {
353357 item [ kRefed ] = refed ;
354358}
355359
360+ // We need to use the binding as the receiver for fast API calls.
356361function insert ( item , msecs , start = binding . getLibuvNow ( ) ) {
357362 // Truncate so that accuracy of sub-millisecond timers is not assumed.
358363 msecs = MathTrunc ( msecs ) ;
@@ -367,6 +372,7 @@ function insert(item, msecs, start = binding.getLibuvNow()) {
367372 timerListQueue . insert ( list ) ;
368373
369374 if ( nextExpiry > expiry ) {
375+ // We need to use the binding as the receiver for fast API calls.
370376 binding . scheduleTimer ( msecs ) ;
371377 nextExpiry = expiry ;
372378 }
@@ -556,8 +562,10 @@ function getTimerCallbacks(runNextTicks) {
556562 emitBefore ( asyncId , timer [ trigger_async_id_symbol ] , timer ) ;
557563
558564 let start ;
559- if ( timer . _repeat )
565+ if ( timer . _repeat ) {
566+ // We need to use the binding as the receiver for fast API calls.
560567 start = binding . getLibuvNow ( ) ;
568+ }
561569
562570 try {
563571 const args = timer . _timerArgs ;
@@ -624,17 +632,22 @@ class Immediate {
624632 ref ( ) {
625633 if ( this [ kRefed ] === false ) {
626634 this [ kRefed ] = true ;
627- if ( immediateInfo [ kRefCount ] ++ === 0 )
635+
636+ if ( immediateInfo [ kRefCount ] ++ === 0 ) {
637+ // We need to use the binding as the receiver for fast API calls.
628638 binding . toggleImmediateRef ( true ) ;
639+ }
629640 }
630641 return this ;
631642 }
632643
633644 unref ( ) {
634645 if ( this [ kRefed ] === true ) {
635646 this [ kRefed ] = false ;
636- if ( -- immediateInfo [ kRefCount ] === 0 )
647+ if ( -- immediateInfo [ kRefCount ] === 0 ) {
648+ // We need to use the binding as the receiver for fast API calls.
637649 binding . toggleImmediateRef ( false ) ;
650+ }
638651 }
639652 return this ;
640653 }
0 commit comments