1 |
|
2 |
|
3 | var process = module.exports = {};
|
4 |
|
5 | process.nextTick = (function () {
|
6 | var canSetImmediate = typeof window !== 'undefined'
|
7 | && window.setImmediate;
|
8 | var canPost = typeof window !== 'undefined'
|
9 | && window.postMessage && window.addEventListener
|
10 | ;
|
11 |
|
12 | if (canSetImmediate) {
|
13 | return function (f) { return window.setImmediate(f) };
|
14 | }
|
15 |
|
16 | if (canPost) {
|
17 | var queue = [];
|
18 | window.addEventListener('message', function (ev) {
|
19 | var source = ev.source;
|
20 | if ((source === window || source === null) && ev.data === 'process-tick') {
|
21 | ev.stopPropagation();
|
22 | if (queue.length > 0) {
|
23 | var fn = queue.shift();
|
24 | fn();
|
25 | }
|
26 | }
|
27 | }, true);
|
28 |
|
29 | return function nextTick(fn) {
|
30 | queue.push(fn);
|
31 | window.postMessage('process-tick', '*');
|
32 | };
|
33 | }
|
34 |
|
35 | return function nextTick(fn) {
|
36 | setTimeout(fn, 0);
|
37 | };
|
38 | })();
|
39 |
|
40 | process.title = 'browser';
|
41 | process.browser = true;
|
42 | process.env = {};
|
43 | process.argv = [];
|
44 |
|
45 | process.binding = function (name) {
|
46 | throw new Error('process.binding is not supported');
|
47 | }
|
48 |
|
49 |
|
50 | process.cwd = function () { return '/' };
|
51 | process.chdir = function (dir) {
|
52 | throw new Error('process.chdir is not supported');
|
53 | };
|