react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / insert-module-globals / node_modules / process / browser.js
80737 views// shim for using process in browser12var process = module.exports = {};3var queue = [];4var draining = false;5var currentQueue;6var queueIndex = -1;78function cleanUpNextTick() {9draining = false;10if (currentQueue.length) {11queue = currentQueue.concat(queue);12} else {13queueIndex = -1;14}15if (queue.length) {16drainQueue();17}18}1920function drainQueue() {21if (draining) {22return;23}24var timeout = setTimeout(cleanUpNextTick);25draining = true;2627var len = queue.length;28while(len) {29currentQueue = queue;30queue = [];31while (++queueIndex < len) {32currentQueue[queueIndex].run();33}34queueIndex = -1;35len = queue.length;36}37currentQueue = null;38draining = false;39clearTimeout(timeout);40}4142process.nextTick = function (fun) {43var args = new Array(arguments.length - 1);44if (arguments.length > 1) {45for (var i = 1; i < arguments.length; i++) {46args[i - 1] = arguments[i];47}48}49queue.push(new Item(fun, args));50if (queue.length === 1 && !draining) {51setTimeout(drainQueue, 0);52}53};5455// v8 likes predictible objects56function Item(fun, array) {57this.fun = fun;58this.array = array;59}60Item.prototype.run = function () {61this.fun.apply(null, this.array);62};63process.title = 'browser';64process.browser = true;65process.env = {};66process.argv = [];67process.version = ''; // empty string to avoid regexp issues68process.versions = {};6970function noop() {}7172process.on = noop;73process.addListener = noop;74process.once = noop;75process.off = noop;76process.removeListener = noop;77process.removeAllListeners = noop;78process.emit = noop;7980process.binding = function (name) {81throw new Error('process.binding is not supported');82};8384// TODO(shtylman)85process.cwd = function () { return '/' };86process.chdir = function (dir) {87throw new Error('process.chdir is not supported');88};89process.umask = function() { return 0; };909192