@@ -81,14 +81,11 @@ const {
81
81
Symbol,
82
82
} = primordials ;
83
83
84
+ const binding = internalBinding ( 'timers' ) ;
84
85
const {
85
- scheduleTimer,
86
- toggleTimerRef,
87
- getLibuvNow,
88
86
immediateInfo,
89
87
timeoutInfo,
90
- toggleImmediateRef,
91
- } = internalBinding ( 'timers' ) ;
88
+ } = binding ;
92
89
93
90
const {
94
91
getDefaultTriggerAsyncId,
@@ -306,13 +303,17 @@ class ImmediateList {
306
303
const immediateQueue = new ImmediateList ( ) ;
307
304
308
305
function incRefCount ( ) {
309
- if ( timeoutInfo [ 0 ] ++ === 0 )
310
- toggleTimerRef ( true ) ;
306
+ if ( timeoutInfo [ 0 ] ++ === 0 ) {
307
+ // We need to use the binding as the receiver for fast API calls.
308
+ binding . toggleTimerRef ( true ) ;
309
+ }
311
310
}
312
311
313
312
function decRefCount ( ) {
314
- if ( -- timeoutInfo [ 0 ] === 0 )
315
- toggleTimerRef ( false ) ;
313
+ if ( -- timeoutInfo [ 0 ] === 0 ) {
314
+ // We need to use the binding as the receiver for fast API calls.
315
+ binding . toggleTimerRef ( false ) ;
316
+ }
316
317
}
317
318
318
319
// Schedule or re-schedule a timer.
@@ -356,7 +357,8 @@ function insertGuarded(item, refed, start) {
356
357
item [ kRefed ] = refed ;
357
358
}
358
359
359
- function insert ( item , msecs , start = getLibuvNow ( ) ) {
360
+ // We need to use the binding as the receiver for fast API calls.
361
+ function insert ( item , msecs , start = binding . getLibuvNow ( ) ) {
360
362
// Truncate so that accuracy of sub-millisecond timers is not assumed.
361
363
msecs = MathTrunc ( msecs ) ;
362
364
item . _idleStart = start ;
@@ -370,7 +372,8 @@ function insert(item, msecs, start = getLibuvNow()) {
370
372
timerListQueue . insert ( list ) ;
371
373
372
374
if ( nextExpiry > expiry ) {
373
- scheduleTimer ( msecs ) ;
375
+ // We need to use the binding as the receiver for fast API calls.
376
+ binding . scheduleTimer ( msecs ) ;
374
377
nextExpiry = expiry ;
375
378
}
376
379
}
@@ -559,8 +562,10 @@ function getTimerCallbacks(runNextTicks) {
559
562
emitBefore ( asyncId , timer [ trigger_async_id_symbol ] , timer ) ;
560
563
561
564
let start ;
562
- if ( timer . _repeat )
563
- start = getLibuvNow ( ) ;
565
+ if ( timer . _repeat ) {
566
+ // We need to use the binding as the receiver for fast API calls.
567
+ start = binding . getLibuvNow ( ) ;
568
+ }
564
569
565
570
try {
566
571
const args = timer . _timerArgs ;
@@ -627,17 +632,22 @@ class Immediate {
627
632
ref ( ) {
628
633
if ( this [ kRefed ] === false ) {
629
634
this [ kRefed ] = true ;
630
- if ( immediateInfo [ kRefCount ] ++ === 0 )
631
- toggleImmediateRef ( true ) ;
635
+
636
+ if ( immediateInfo [ kRefCount ] ++ === 0 ) {
637
+ // We need to use the binding as the receiver for fast API calls.
638
+ binding . toggleImmediateRef ( true ) ;
639
+ }
632
640
}
633
641
return this ;
634
642
}
635
643
636
644
unref ( ) {
637
645
if ( this [ kRefed ] === true ) {
638
646
this [ kRefed ] = false ;
639
- if ( -- immediateInfo [ kRefCount ] === 0 )
640
- toggleImmediateRef ( false ) ;
647
+ if ( -- immediateInfo [ kRefCount ] === 0 ) {
648
+ // We need to use the binding as the receiver for fast API calls.
649
+ binding . toggleImmediateRef ( false ) ;
650
+ }
641
651
}
642
652
return this ;
643
653
}
0 commit comments