@@ -447,41 +447,44 @@ var requestHostCallback;
447
447
var cancelHostCallback ;
448
448
var shouldYieldToHost ;
449
449
450
- if ( typeof window !== 'undefined' && window . _schedMock ) {
450
+ var globalValue = null ;
451
+ if ( typeof window !== 'undefined' ) {
452
+ globalValue = window ;
453
+ } else if ( typeof global !== 'undefined' ) {
454
+ globalValue = global ;
455
+ }
456
+
457
+ if ( globalValue && globalValue . _schedMock ) {
451
458
// Dynamic injection, only for testing purposes.
452
- var impl = window . _schedMock ;
453
- requestHostCallback = impl [ 0 ] ;
454
- cancelHostCallback = impl [ 1 ] ;
455
- shouldYieldToHost = impl [ 2 ] ;
459
+ var globalImpl = globalValue . _schedMock ;
460
+ requestHostCallback = globalImpl [ 0 ] ;
461
+ cancelHostCallback = globalImpl [ 1 ] ;
462
+ shouldYieldToHost = globalImpl [ 2 ] ;
463
+ getCurrentTime = globalImpl [ 3 ] ;
456
464
} else if (
457
465
// If Scheduler runs in a non-DOM environment, it falls back to a naive
458
466
// implementation using setTimeout.
459
467
typeof window === 'undefined' ||
460
468
// Check if MessageChannel is supported, too.
461
469
typeof MessageChannel !== 'function'
462
470
) {
471
+ // If this accidentally gets imported in a non-browser environment, e.g. JavaScriptCore,
472
+ // fallback to a naive implementation.
463
473
var _callback = null ;
464
- var _currentTime = - 1 ;
465
- var _flushCallback = function ( didTimeout , ms ) {
474
+ var _flushCallback = function ( didTimeout ) {
466
475
if ( _callback !== null ) {
467
476
var cb = _callback ;
468
477
_callback = null ;
469
- try {
470
- _currentTime = ms ;
471
- cb ( didTimeout ) ;
472
- } finally {
473
- _currentTime = - 1 ;
474
- }
478
+ cb ( didTimeout ) ;
475
479
}
476
480
} ;
477
481
requestHostCallback = function ( cb , ms ) {
478
- if ( _currentTime !== - 1 ) {
482
+ if ( _callback !== null ) {
479
483
// Protect against re-entrancy.
480
- setTimeout ( requestHostCallback , 0 , cb , ms ) ;
484
+ setTimeout ( requestHostCallback , 0 , cb ) ;
481
485
} else {
482
486
_callback = cb ;
483
- setTimeout ( _flushCallback , ms , true , ms ) ;
484
- setTimeout ( _flushCallback , maxSigned31BitInt , false , maxSigned31BitInt ) ;
487
+ setTimeout ( _flushCallback , 0 , false ) ;
485
488
}
486
489
} ;
487
490
cancelHostCallback = function ( ) {
@@ -490,9 +493,6 @@ if (typeof window !== 'undefined' && window._schedMock) {
490
493
shouldYieldToHost = function ( ) {
491
494
return false ;
492
495
} ;
493
- getCurrentTime = function ( ) {
494
- return _currentTime === - 1 ? 0 : _currentTime ;
495
- } ;
496
496
} else {
497
497
if ( typeof console !== 'undefined' ) {
498
498
// TODO: Remove fb.me link
0 commit comments