react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / process / browser.js
80708 views// shim for using process in browser12var process = module.exports = {};34process.nextTick = (function () {5var canSetImmediate = typeof window !== 'undefined'6&& window.setImmediate;7var canMutationObserver = typeof window !== 'undefined'8&& window.MutationObserver;9var canPost = typeof window !== 'undefined'10&& window.postMessage && window.addEventListener11;1213if (canSetImmediate) {14return function (f) { return window.setImmediate(f) };15}1617var queue = [];1819if (canMutationObserver) {20var hiddenDiv = document.createElement("div");21var observer = new MutationObserver(function () {22var queueList = queue.slice();23queue.length = 0;24queueList.forEach(function (fn) {25fn();26});27});2829observer.observe(hiddenDiv, { attributes: true });3031return function nextTick(fn) {32if (!queue.length) {33hiddenDiv.setAttribute('yes', 'no');34}35queue.push(fn);36};37}3839if (canPost) {40window.addEventListener('message', function (ev) {41var source = ev.source;42if ((source === window || source === null) && ev.data === 'process-tick') {43ev.stopPropagation();44if (queue.length > 0) {45var fn = queue.shift();46fn();47}48}49}, true);5051return function nextTick(fn) {52queue.push(fn);53window.postMessage('process-tick', '*');54};55}5657return function nextTick(fn) {58setTimeout(fn, 0);59};60})();6162process.title = 'browser';63process.browser = true;64process.env = {};65process.argv = [];6667function noop() {}6869process.on = noop;70process.addListener = noop;71process.once = noop;72process.off = noop;73process.removeListener = noop;74process.removeAllListeners = noop;75process.emit = noop;7677process.binding = function (name) {78throw new Error('process.binding is not supported');79};8081// TODO(shtylman)82process.cwd = function () { return '/' };83process.chdir = function (dir) {84throw new Error('process.chdir is not supported');85};868788