browser.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. (function() {
  2. var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
  3. var __module = nodeEnv ? module : {exports:{}};
  4. var __filename = 'preview-scripts/__node_modules/process/browser.js';
  5. var __require = nodeEnv ? function (request) {
  6. return cc.require(request);
  7. } : function (request) {
  8. return __quick_compile_project__.require(request, __filename);
  9. };
  10. function __define (exports, require, module) {
  11. if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}// shim for using process in browser
  12. var process = module.exports = {};
  13. // cached from whatever global is present so that test runners that stub it
  14. // don't break things. But we need to wrap it in a try catch in case it is
  15. // wrapped in strict mode code which doesn't define any globals. It's inside a
  16. // function because try/catches deoptimize in certain engines.
  17. var cachedSetTimeout;
  18. var cachedClearTimeout;
  19. function defaultSetTimout() {
  20. throw new Error('setTimeout has not been defined');
  21. }
  22. function defaultClearTimeout () {
  23. throw new Error('clearTimeout has not been defined');
  24. }
  25. (function () {
  26. try {
  27. if (typeof setTimeout === 'function') {
  28. cachedSetTimeout = setTimeout;
  29. } else {
  30. cachedSetTimeout = defaultSetTimout;
  31. }
  32. } catch (e) {
  33. cachedSetTimeout = defaultSetTimout;
  34. }
  35. try {
  36. if (typeof clearTimeout === 'function') {
  37. cachedClearTimeout = clearTimeout;
  38. } else {
  39. cachedClearTimeout = defaultClearTimeout;
  40. }
  41. } catch (e) {
  42. cachedClearTimeout = defaultClearTimeout;
  43. }
  44. } ())
  45. function runTimeout(fun) {
  46. if (cachedSetTimeout === setTimeout) {
  47. //normal enviroments in sane situations
  48. return setTimeout(fun, 0);
  49. }
  50. // if setTimeout wasn't available but was latter defined
  51. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  52. cachedSetTimeout = setTimeout;
  53. return setTimeout(fun, 0);
  54. }
  55. try {
  56. // when when somebody has screwed with setTimeout but no I.E. maddness
  57. return cachedSetTimeout(fun, 0);
  58. } catch(e){
  59. try {
  60. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  61. return cachedSetTimeout.call(null, fun, 0);
  62. } catch(e){
  63. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  64. return cachedSetTimeout.call(this, fun, 0);
  65. }
  66. }
  67. }
  68. function runClearTimeout(marker) {
  69. if (cachedClearTimeout === clearTimeout) {
  70. //normal enviroments in sane situations
  71. return clearTimeout(marker);
  72. }
  73. // if clearTimeout wasn't available but was latter defined
  74. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  75. cachedClearTimeout = clearTimeout;
  76. return clearTimeout(marker);
  77. }
  78. try {
  79. // when when somebody has screwed with setTimeout but no I.E. maddness
  80. return cachedClearTimeout(marker);
  81. } catch (e){
  82. try {
  83. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  84. return cachedClearTimeout.call(null, marker);
  85. } catch (e){
  86. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  87. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  88. return cachedClearTimeout.call(this, marker);
  89. }
  90. }
  91. }
  92. var queue = [];
  93. var draining = false;
  94. var currentQueue;
  95. var queueIndex = -1;
  96. function cleanUpNextTick() {
  97. if (!draining || !currentQueue) {
  98. return;
  99. }
  100. draining = false;
  101. if (currentQueue.length) {
  102. queue = currentQueue.concat(queue);
  103. } else {
  104. queueIndex = -1;
  105. }
  106. if (queue.length) {
  107. drainQueue();
  108. }
  109. }
  110. function drainQueue() {
  111. if (draining) {
  112. return;
  113. }
  114. var timeout = runTimeout(cleanUpNextTick);
  115. draining = true;
  116. var len = queue.length;
  117. while(len) {
  118. currentQueue = queue;
  119. queue = [];
  120. while (++queueIndex < len) {
  121. if (currentQueue) {
  122. currentQueue[queueIndex].run();
  123. }
  124. }
  125. queueIndex = -1;
  126. len = queue.length;
  127. }
  128. currentQueue = null;
  129. draining = false;
  130. runClearTimeout(timeout);
  131. }
  132. process.nextTick = function (fun) {
  133. var args = new Array(arguments.length - 1);
  134. if (arguments.length > 1) {
  135. for (var i = 1; i < arguments.length; i++) {
  136. args[i - 1] = arguments[i];
  137. }
  138. }
  139. queue.push(new Item(fun, args));
  140. if (queue.length === 1 && !draining) {
  141. runTimeout(drainQueue);
  142. }
  143. };
  144. // v8 likes predictible objects
  145. function Item(fun, array) {
  146. this.fun = fun;
  147. this.array = array;
  148. }
  149. Item.prototype.run = function () {
  150. this.fun.apply(null, this.array);
  151. };
  152. process.title = 'browser';
  153. process.browser = true;
  154. process.env = {};
  155. process.argv = [];
  156. process.version = ''; // empty string to avoid regexp issues
  157. process.versions = {};
  158. function noop() {}
  159. process.on = noop;
  160. process.addListener = noop;
  161. process.once = noop;
  162. process.off = noop;
  163. process.removeListener = noop;
  164. process.removeAllListeners = noop;
  165. process.emit = noop;
  166. process.prependListener = noop;
  167. process.prependOnceListener = noop;
  168. process.listeners = function (name) { return [] }
  169. process.binding = function (name) {
  170. throw new Error('process.binding is not supported');
  171. };
  172. process.cwd = function () { return '/' };
  173. process.chdir = function (dir) {
  174. throw new Error('process.chdir is not supported');
  175. };
  176. process.umask = function() { return 0; };
  177. }
  178. if (nodeEnv) {
  179. __define(__module.exports, __require, __module);
  180. }
  181. else {
  182. __quick_compile_project__.registerModuleFunc(__filename, function () {
  183. __define(__module.exports, __require, __module);
  184. });
  185. }
  186. })();