1 |
|
2 | var process = module.exports = {};
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var cachedSetTimeout;
|
10 | var cachedClearTimeout;
|
11 |
|
12 | function defaultSetTimout() {
|
13 | throw new Error('setTimeout has not been defined');
|
14 | }
|
15 | function defaultClearTimeout () {
|
16 | throw new Error('clearTimeout has not been defined');
|
17 | }
|
18 | (function () {
|
19 | try {
|
20 | if (typeof setTimeout === 'function') {
|
21 | cachedSetTimeout = setTimeout;
|
22 | } else {
|
23 | cachedSetTimeout = defaultSetTimout;
|
24 | }
|
25 | } catch (e) {
|
26 | cachedSetTimeout = defaultSetTimout;
|
27 | }
|
28 | try {
|
29 | if (typeof clearTimeout === 'function') {
|
30 | cachedClearTimeout = clearTimeout;
|
31 | } else {
|
32 | cachedClearTimeout = defaultClearTimeout;
|
33 | }
|
34 | } catch (e) {
|
35 | cachedClearTimeout = defaultClearTimeout;
|
36 | }
|
37 | } ())
|
38 | function runTimeout(fun) {
|
39 | if (cachedSetTimeout === setTimeout) {
|
40 |
|
41 | return setTimeout(fun, 0);
|
42 | }
|
43 |
|
44 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
45 | cachedSetTimeout = setTimeout;
|
46 | return setTimeout(fun, 0);
|
47 | }
|
48 | try {
|
49 |
|
50 | return cachedSetTimeout(fun, 0);
|
51 | } catch(e){
|
52 | try {
|
53 |
|
54 | return cachedSetTimeout.call(null, fun, 0);
|
55 | } catch(e){
|
56 |
|
57 | return cachedSetTimeout.call(this, fun, 0);
|
58 | }
|
59 | }
|
60 |
|
61 |
|
62 | }
|
63 | function runClearTimeout(marker) {
|
64 | if (cachedClearTimeout === clearTimeout) {
|
65 |
|
66 | return clearTimeout(marker);
|
67 | }
|
68 |
|
69 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
70 | cachedClearTimeout = clearTimeout;
|
71 | return clearTimeout(marker);
|
72 | }
|
73 | try {
|
74 |
|
75 | return cachedClearTimeout(marker);
|
76 | } catch (e){
|
77 | try {
|
78 |
|
79 | return cachedClearTimeout.call(null, marker);
|
80 | } catch (e){
|
81 |
|
82 |
|
83 | return cachedClearTimeout.call(this, marker);
|
84 | }
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 | }
|
90 | var queue = [];
|
91 | var draining = false;
|
92 | var currentQueue;
|
93 | var queueIndex = -1;
|
94 |
|
95 | function cleanUpNextTick() {
|
96 | if (!draining || !currentQueue) {
|
97 | return;
|
98 | }
|
99 | draining = false;
|
100 | if (currentQueue.length) {
|
101 | queue = currentQueue.concat(queue);
|
102 | } else {
|
103 | queueIndex = -1;
|
104 | }
|
105 | if (queue.length) {
|
106 | drainQueue();
|
107 | }
|
108 | }
|
109 |
|
110 | function drainQueue() {
|
111 | if (draining) {
|
112 | return;
|
113 | }
|
114 | var timeout = runTimeout(cleanUpNextTick);
|
115 | draining = true;
|
116 |
|
117 | var len = queue.length;
|
118 | while(len) {
|
119 | currentQueue = queue;
|
120 | queue = [];
|
121 | while (++queueIndex < len) {
|
122 | if (currentQueue) {
|
123 | currentQueue[queueIndex].run();
|
124 | }
|
125 | }
|
126 | queueIndex = -1;
|
127 | len = queue.length;
|
128 | }
|
129 | currentQueue = null;
|
130 | draining = false;
|
131 | runClearTimeout(timeout);
|
132 | }
|
133 |
|
134 | process.nextTick = function (fun) {
|
135 | var args = new Array(arguments.length - 1);
|
136 | if (arguments.length > 1) {
|
137 | for (var i = 1; i < arguments.length; i++) {
|
138 | args[i - 1] = arguments[i];
|
139 | }
|
140 | }
|
141 | queue.push(new Item(fun, args));
|
142 | if (queue.length === 1 && !draining) {
|
143 | runTimeout(drainQueue);
|
144 | }
|
145 | };
|
146 |
|
147 |
|
148 | function Item(fun, array) {
|
149 | this.fun = fun;
|
150 | this.array = array;
|
151 | }
|
152 | Item.prototype.run = function () {
|
153 | this.fun.apply(null, this.array);
|
154 | };
|
155 | process.title = 'browser';
|
156 | process.browser = true;
|
157 | process.env = {};
|
158 | process.argv = [];
|
159 | process.version = '';
|
160 | process.versions = {};
|
161 |
|
162 | function noop() {}
|
163 |
|
164 | process.on = noop;
|
165 | process.addListener = noop;
|
166 | process.once = noop;
|
167 | process.off = noop;
|
168 | process.removeListener = noop;
|
169 | process.removeAllListeners = noop;
|
170 | process.emit = noop;
|
171 | process.prependListener = noop;
|
172 | process.prependOnceListener = noop;
|
173 |
|
174 | process.listeners = function (name) { return [] }
|
175 |
|
176 | process.binding = function (name) {
|
177 | throw new Error('process.binding is not supported');
|
178 | };
|
179 |
|
180 | process.cwd = function () { return '/' };
|
181 | process.chdir = function (dir) {
|
182 | throw new Error('process.chdir is not supported');
|
183 | };
|
184 | process.umask = function() { return 0; };
|