2
2
// shim for using process in browser
3
3
4
4
var process = module . exports = { } ;
5
+
6
+ // cached from whatever global is present so that test runners that stub it
7
+ // don't break things. But we need to wrap it in a try catch in case it is
8
+ // wrapped in strict mode code which doesn't define any globals. It's inside a
9
+ // function because try/catches deoptimize in certain engines.
10
+
11
+ var cachedSetTimeout ;
12
+ var cachedClearTimeout ;
13
+
14
+ ( function ( ) {
15
+ try {
16
+ cachedSetTimeout = setTimeout ;
17
+ } catch ( e ) {
18
+ cachedSetTimeout = function ( ) {
19
+ throw new Error ( 'setTimeout is not defined' ) ;
20
+ }
21
+ }
22
+ try {
23
+ cachedClearTimeout = clearTimeout ;
24
+ } catch ( e ) {
25
+ cachedClearTimeout = function ( ) {
26
+ throw new Error ( 'clearTimeout is not defined' ) ;
27
+ }
28
+ }
29
+ } ( ) )
5
30
var queue = [ ] ;
6
31
var draining = false ;
7
32
var currentQueue ;
8
33
var queueIndex = - 1 ;
9
34
10
35
function cleanUpNextTick ( ) {
36
+ if ( ! draining || ! currentQueue ) {
37
+ return ;
38
+ }
11
39
draining = false ;
12
40
if ( currentQueue . length ) {
13
41
queue = currentQueue . concat ( queue ) ;
@@ -23,7 +51,7 @@ function drainQueue() {
23
51
if ( draining ) {
24
52
return ;
25
53
}
26
- var timeout = setTimeout ( cleanUpNextTick ) ;
54
+ var timeout = cachedSetTimeout ( cleanUpNextTick ) ;
27
55
draining = true ;
28
56
29
57
var len = queue . length ;
@@ -40,7 +68,7 @@ function drainQueue() {
40
68
}
41
69
currentQueue = null ;
42
70
draining = false ;
43
- clearTimeout ( timeout ) ;
71
+ cachedClearTimeout ( timeout ) ;
44
72
}
45
73
46
74
process . nextTick = function ( fun ) {
@@ -52,7 +80,7 @@ process.nextTick = function (fun) {
52
80
}
53
81
queue . push ( new Item ( fun , args ) ) ;
54
82
if ( queue . length === 1 && ! draining ) {
55
- setTimeout ( drainQueue , 0 ) ;
83
+ cachedSetTimeout ( drainQueue , 0 ) ;
56
84
}
57
85
} ;
58
86
@@ -92,6 +120,7 @@ process.chdir = function (dir) {
92
120
process . umask = function ( ) { return 0 ; } ;
93
121
94
122
} , { } ] , 2 :[ function ( require , module , exports ) {
123
+ ( function ( Buffer ) {
95
124
// uuid.js
96
125
//
97
126
// Copyright (c) 2010-2012 Robert Kieffer
@@ -365,6 +394,7 @@ process.umask = function() { return 0; };
365
394
}
366
395
} ) ( 'undefined' !== typeof window ? window : null ) ;
367
396
397
+ } ) . call ( this , require ( "buffer" ) . Buffer )
368
398
} , { } ] , 3 :[ function ( require , module , exports ) {
369
399
( function ( process ) {
370
400
var
0 commit comments