File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 375375 // shim for using process in browser
376376
377377 var process = module . exports = { } ;
378+
379+ // cached from whatever global is present so that test runners that stub it
380+ // don't break things. But we need to wrap it in a try catch in case it is
381+ // wrapped in strict mode code which doesn't define any globals. It's inside a
382+ // function because try/catches deoptimize in certain engines.
383+
384+ var cachedSetTimeout ;
385+ var cachedClearTimeout ;
386+
387+ ( function ( ) {
388+ try {
389+ cachedSetTimeout = setTimeout ;
390+ } catch ( e ) {
391+ cachedSetTimeout = function ( ) {
392+ throw new Error ( 'setTimeout is not defined' ) ;
393+ }
394+ }
395+ try {
396+ cachedClearTimeout = clearTimeout ;
397+ } catch ( e ) {
398+ cachedClearTimeout = function ( ) {
399+ throw new Error ( 'clearTimeout is not defined' ) ;
400+ }
401+ }
402+ } ( ) )
378403 var queue = [ ] ;
379404 var draining = false ;
380405 var currentQueue ;
399424 if ( draining ) {
400425 return ;
401426 }
402- var timeout = setTimeout ( cleanUpNextTick ) ;
427+ var timeout = cachedSetTimeout ( cleanUpNextTick ) ;
403428 draining = true ;
404429
405430 var len = queue . length ;
416441 }
417442 currentQueue = null ;
418443 draining = false ;
419- clearTimeout ( timeout ) ;
444+ cachedClearTimeout ( timeout ) ;
420445 }
421446
422447 process . nextTick = function ( fun ) {
428453 }
429454 queue . push ( new Item ( fun , args ) ) ;
430455 if ( queue . length === 1 && ! draining ) {
431- setTimeout ( drainQueue , 0 ) ;
456+ cachedSetTimeout ( drainQueue , 0 ) ;
432457 }
433458 } ;
434459
You can’t perform that action at this time.
0 commit comments