1 // shim for using process in browser
3 var process = module.exports = {};
5 process.nextTick = (function () {
6 var canSetImmediate = typeof window !== 'undefined'
7 && window.setImmediate;
8 var canPost = typeof window !== 'undefined'
9 && window.postMessage && window.addEventListener
12 if (canSetImmediate) {
13 return function (f) { return window.setImmediate(f) };
18 window.addEventListener('message', function (ev) {
19 var source = ev.source;
20 if ((source === window || source === null) && ev.data === 'process-tick') {
22 if (queue.length > 0) {
23 var fn = queue.shift();
29 return function nextTick(fn) {
31 window.postMessage('process-tick', '*');
35 return function nextTick(fn) {
40 process.title = 'browser';
41 process.browser = true;
45 process.binding = function (name) {
46 throw new Error('process.binding is not supported');
50 process.cwd = function () { return '/' };
51 process.chdir = function (dir) {
52 throw new Error('process.chdir is not supported');