@@ -447,41 +447,44 @@ var requestHostCallback;
447447var cancelHostCallback ;
448448var shouldYieldToHost ;
449449
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 ) {
451458 // 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 ] ;
456464} else if (
457465 // If Scheduler runs in a non-DOM environment, it falls back to a naive
458466 // implementation using setTimeout.
459467 typeof window === 'undefined' ||
460468 // Check if MessageChannel is supported, too.
461469 typeof MessageChannel !== 'function'
462470) {
471+ // If this accidentally gets imported in a non-browser environment, e.g. JavaScriptCore,
472+ // fallback to a naive implementation.
463473 var _callback = null ;
464- var _currentTime = - 1 ;
465- var _flushCallback = function ( didTimeout , ms ) {
474+ var _flushCallback = function ( didTimeout ) {
466475 if ( _callback !== null ) {
467476 var cb = _callback ;
468477 _callback = null ;
469- try {
470- _currentTime = ms ;
471- cb ( didTimeout ) ;
472- } finally {
473- _currentTime = - 1 ;
474- }
478+ cb ( didTimeout ) ;
475479 }
476480 } ;
477481 requestHostCallback = function ( cb , ms ) {
478- if ( _currentTime !== - 1 ) {
482+ if ( _callback !== null ) {
479483 // Protect against re-entrancy.
480- setTimeout ( requestHostCallback , 0 , cb , ms ) ;
484+ setTimeout ( requestHostCallback , 0 , cb ) ;
481485 } else {
482486 _callback = cb ;
483- setTimeout ( _flushCallback , ms , true , ms ) ;
484- setTimeout ( _flushCallback , maxSigned31BitInt , false , maxSigned31BitInt ) ;
487+ setTimeout ( _flushCallback , 0 , false ) ;
485488 }
486489 } ;
487490 cancelHostCallback = function ( ) {
@@ -490,9 +493,6 @@ if (typeof window !== 'undefined' && window._schedMock) {
490493 shouldYieldToHost = function ( ) {
491494 return false ;
492495 } ;
493- getCurrentTime = function ( ) {
494- return _currentTime === - 1 ? 0 : _currentTime ;
495- } ;
496496} else {
497497 if ( typeof console !== 'undefined' ) {
498498 // TODO: Remove fb.me link
0 commit comments