UNPKG

24.6 kBJavaScriptView Raw
1(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2/*
3 * EJS Embedded JavaScript templates
4 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18*/
19
20"use strict";
21
22var utils = require('./utils')
23 , ejs
24 , templateCache = {}
25 , jsCache = {}
26 , includeFile
27 , includeSource
28 , resolveInclude
29 , compile
30 , rethrow
31 , _DEFAULT_DELIMITER = '%'
32 , _REGEX_STRING = '(<%%)|(<%=)|(<%-)|(<%#)|(<%)|(%>)|(-%>)'
33 , _OPTS_MAP = {
34 cache: 'cache'
35 , filename: 'filename'
36 , delimiter: 'delimiter'
37 , scope: 'context'
38 , context: 'context'
39 , debug: 'debug'
40 , compileDebug: 'compileDebug'
41 , client: 'client'
42 };
43
44resolveInclude = function (name, filename) {
45 var path = require('path')
46 , dirname = path.dirname
47 , extname = path.extname
48 , resolve = path.resolve
49 , includePath = resolve(dirname(filename), name)
50 , ext = extname(name);
51 if (!ext) {
52 includePath += '.ejs';
53 }
54 return includePath;
55};
56
57includeFile = function (path, options) {
58 var fn
59 , opts = utils.shallowCopy({}, options || /* istanbul ignore next */ {})
60 , fs = require('fs')
61 , includePath
62 , template;
63 if (!opts.filename) {
64 throw new Error('`include` requires the \'filename\' option.');
65 }
66 includePath = resolveInclude(path, opts.filename);
67 if (opts.cache) {
68 template = templateCache[includePath];
69 if (!template) {
70 template = fs.readFileSync(includePath).toString().trim();
71 templateCache[includePath] = template;
72 }
73 }
74 else {
75 template = fs.readFileSync(includePath).toString().trim();
76 }
77
78 opts.filename = includePath;
79 fn = exports.compile(template, opts);
80 return fn;
81};
82
83includeSource = function (path, options) {
84 var fn
85 , opts = utils.shallowCopy({}, options || {})
86 , fs = require('fs')
87 , includePath
88 , template;
89 if (!opts.filename) {
90 throw new Error('`include` requires the \'filename\' option.');
91 }
92 includePath = resolveInclude(path, opts.filename);
93 if (opts.cache) {
94 template = templateCache[includePath];
95 if (!template) {
96 template = fs.readFileSync(includePath).toString().trim();
97 templateCache[includePath] = template;
98 }
99 }
100 else {
101 template = fs.readFileSync(includePath).toString().trim();
102 }
103
104 opts.filename = includePath;
105 var templ = new Template(template, opts);
106 templ.generateSource();
107 return templ.source;
108};
109
110rethrow = function (err, str, filename, lineno){
111 var lines = str.split('\n')
112 , start = Math.max(lineno - 3, 0)
113 , end = Math.min(lines.length, lineno + 3);
114
115 // Error context
116 var context = lines.slice(start, end).map(function(line, i){
117 var curr = i + start + 1;
118 return (curr == lineno ? ' >> ' : ' ')
119 + curr
120 + '| '
121 + line;
122 }).join('\n');
123
124 // Alter exception message
125 err.path = filename;
126 err.message = (filename || 'ejs') + ':'
127 + lineno + '\n'
128 + context + '\n\n'
129 + err.message;
130
131 throw err;
132}
133
134compile = exports.compile = function (template, opts) {
135 var templ = new Template(template, opts);
136 return templ.compile();
137};
138
139// template, [data], [opts]
140// Have to include an empty data object if you want opts and no data
141exports.render = function () {
142 var args = Array.prototype.slice.call(arguments)
143 , template = args.shift()
144 , data = args.shift() || {}
145 , opts = args.shift() || {}
146 , fn
147 , filename;
148
149 // No options object -- if there are optiony names
150 // in the data, copy them to options
151 if (arguments.length == 2) {
152 for (var p in _OPTS_MAP) {
153 if (typeof data[p] != 'undefined') {
154 opts[_OPTS_MAP[p]] = data[p];
155 }
156 }
157 }
158 // v1 compat
159 // 'scope' is 'context'
160 // FIXME: Remove this in a future version
161 if (opts.scope) {
162 if (!opts.context) {
163 opts.context = opts.scope;
164 }
165 delete opts.scope;
166 }
167
168 if (opts.cache) {
169 filename = opts.filename;
170 if (!filename) {
171 throw new Error('cache option requires a filename');
172 }
173 fn = jsCache[filename];
174 if (!fn) {
175 fn = exports.compile(template, opts);
176 jsCache[filename] = fn;
177 }
178 }
179 else {
180 fn = exports.compile(template, opts);
181 }
182 return fn.call(opts.context, data);
183};
184
185// path, [data] [opts], cb
186// Have to include an empty data object if you want opts and no data
187exports.renderFile = function () {
188 var read = require('fs').readFile
189 , args = Array.prototype.slice.call(arguments)
190 , path = args.shift()
191 , cb = args.pop()
192 , data = args.shift() || {}
193 , opts = args.pop() || {}
194 , template
195 , handleTemplate;
196
197 // Set the filename for includes
198 opts.filename = path;
199
200 handleTemplate = function (template) {
201 var result
202 , failed = false;
203 try {
204 result = exports.render(template, data, opts);
205 }
206 catch(err) {
207 cb(err);
208 failed = true;
209 }
210 if (!failed) cb(null, result);
211 };
212
213 template = templateCache[path];
214 if (opts.cache && template) {
215 handleTemplate(template);
216 }
217 else {
218 read(path, function (err, data) {
219 var tmpl;
220 if (err) {
221 return cb(err);
222 }
223 tmpl = data.toString().trim();
224 if (opts.cache) {
225 templateCache[path] = tmpl;
226 }
227 handleTemplate(tmpl);
228 });
229 }
230};
231
232exports.clearCache = function () {
233 templateCache = {};
234 jsCache = {};
235};
236
237var Template = function (text, opts) {
238 opts = opts || {};
239 var options = {};
240 this.templateText = text;
241 this.mode = null;
242 this.truncate = false;
243 this.currentLine = 1;
244 this.source = '';
245 options.client = opts.client || false;
246 options.escapeFunction = opts.escape || utils.escapeXML;
247 options.compileDebug = opts.compileDebug !== false;
248 options.debug = !!opts.debug;
249 options.filename = opts.filename;
250 options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
251 options._with = opts._with != null ? opts._with : true
252 this.opts = options;
253
254 this.regex = this.createRegex();
255};
256
257Template.prototype = new function () {
258
259 this.modes = {
260 EVAL: 'eval'
261 , ESCAPED: 'escaped'
262 , RAW: 'raw'
263 , APPEND: 'append'
264 , COMMENT: 'comment'
265 , LITERAL: 'literal'
266 };
267
268 this.createRegex = function () {
269 var str = _REGEX_STRING
270 , delim = utils.escapeRegExpChars(this.opts.delimiter);
271 str = str.replace(/%/g, delim);
272 return new RegExp(str);
273 };
274
275 this.compile = function () {
276 var self = this
277 , src
278 , fn
279 , opts = this.opts
280 , escape = opts.escapeFunction;
281
282 if (!this.source) {
283 this.generateSource();
284 var appended = 'var __output = "";';
285 if (opts._with !== false) appended += ' with (locals || {}) { ';
286 this.source = appended + this.source;
287 if (opts._with !== false) this.source += '}';
288 this.source += 'return __output.trim();';
289 }
290
291 if (opts.compileDebug) {
292 src = 'var __line = 1' +
293 ', __lines = ' + JSON.stringify(this.templateText) +
294 ', __filename = ' + (opts.filename ?
295 JSON.stringify(opts.filename) : 'undefined') +
296 '; try {' +
297 this.source + '} catch (e) { rethrow(e, __lines, __filename, __line); }';
298 }
299 else {
300 src = this.source;
301 }
302
303 if (opts.debug) {
304 console.log(src);
305 }
306
307 if (opts.client) {
308 src = 'escape = escape || ' + escape.toString() + ';\n' + src;
309 src = 'rethrow = rethrow || ' + rethrow.toString() + ';\n' + src;
310 }
311
312 try {
313 fn = new Function('locals, escape, include, rethrow', src);
314 }
315 catch(e) {
316 if (e instanceof SyntaxError) {
317 if (opts.filename) {
318 e.message += ' in ' + opts.filename;
319 }
320 e.message += ' while compiling ejs';
321 throw e;
322 }
323 }
324
325 if (opts.client) {
326 return fn;
327 }
328
329 // Return a callable function which will execute the function
330 // created by the source-code, with the passed data as locals
331 return function (data) {
332 var include = function (path, includeData) {
333 var d = utils.shallowCopy({}, data);
334 if (includeData) {
335 d = utils.shallowCopy(d, includeData);
336 }
337 return includeFile(path, opts).apply(this, [d]);
338 };
339 return fn.apply(this, [data || {}, escape, include, rethrow]);
340 };
341
342 };
343
344 this.generateSource = function () {
345 var self = this
346 , matches = this.parseTemplateText()
347 , d = this.opts.delimiter;
348
349 if (matches && matches.length) {
350 matches.forEach(function (line, index) {
351 var closing
352 , include
353 , includeOpts
354 , includeSrc;
355 // If this is an opening tag, check for closing tags
356 // FIXME: May end up with some false positives here
357 // Better to store modes as k/v with '<' + delimiter as key
358 // Then this can simply check against the map
359 if (line.indexOf('<' + d) === 0) {
360 closing = matches[index + 2];
361 if (!(closing == d + '>' || closing == '-' + d + '>')) {
362 throw new Error('Could not find matching close tag for "' + line + '".');
363 }
364 }
365 // HACK: backward-compat `include` preprocessor directives
366 if ((include = line.match(/^\s*include\s+(\S+)/))) {
367 includeOpts = utils.shallowCopy({}, self.opts);
368 includeSrc = includeSource(include[1], includeOpts);
369 includeSrc = ";(function(){" + includeSrc + "})();";
370 self.source += includeSrc;
371 }
372 else {
373 self.scanLine(line);
374 }
375 });
376 }
377
378 };
379
380 this.parseTemplateText = function () {
381 var str = this.templateText
382 , pat = this.regex
383 , result = pat.exec(str)
384 , arr = []
385 , firstPos
386 , lastPos;
387
388 while (result) {
389 firstPos = result.index;
390 lastPos = pat.lastIndex;
391
392 if (firstPos !== 0) {
393 arr.push(str.substring(0, firstPos));
394 str = str.slice(firstPos);
395 }
396
397 arr.push(result[0]);
398 str = str.slice(result[0].length);
399 result = pat.exec(str);
400 }
401
402 if (str !== '') {
403 arr.push(str);
404 }
405
406 return arr;
407 };
408
409 this.scanLine = function (line) {
410 var self = this
411 , d = this.opts.delimiter
412 , newLineCount = 0
413 , _addOutput;
414
415 _addOutput = function () {
416 if (self.truncate) {
417 line = line.replace('\n', '');
418 }
419
420 // Preserve literal slashes
421 line = line.replace(/\\/g, '\\\\');
422
423 // Convert linebreaks
424 line = line.replace(/\n/g, '\\n');
425 line = line.replace(/\r/g, '\\r');
426
427 // Escape double-quotes
428 // - this will be the delimiter during execution
429 line = line.replace(/"/g, '\\"');
430 self.source += ';__output += "' + line + '";';
431 };
432
433 newLineCount = (line.split('\n').length - 1);
434
435 switch (line) {
436 case '<' + d:
437 this.mode = this.modes.EVAL;
438 break;
439 case '<' + d + '=':
440 this.mode = this.modes.ESCAPED;
441 break;
442 case '<' + d + '-':
443 this.mode = this.modes.RAW;
444 break;
445 case '<' + d + '#':
446 this.mode = this.modes.COMMENT;
447 break;
448 case '<' + d + d:
449 this.mode = this.modes.LITERAL;
450 this.source += ';__output += "' + line.replace('<' + d + d, '<' + d) + '";';
451 break;
452 case d + '>':
453 case '-' + d + '>':
454 if (this.mode == this.modes.LITERAL) {
455 _addOutput();
456 }
457
458 this.mode = null;
459 this.truncate = line.indexOf('-') === 0;
460 break;
461 default:
462 // In script mode, depends on type of tag
463 if (this.mode) {
464 // Strip double-slash comments in all exec modes
465 switch (this.mode) {
466 case this.modes.EVAL:
467 case this.modes.ESCAPED:
468 case this.modes.RAW:
469 line = line.replace(/\/\/.*$/, '');
470 }
471 switch (this.mode) {
472 // Just executing code
473 case this.modes.EVAL:
474 this.source += ';' + line;
475 break;
476 // Exec, esc, and output
477 case this.modes.ESCAPED:
478 // Add the exec'd, escaped result to the output
479 this.source += ';__output += escape(' +
480 line.replace(/;\S*/, '').trim() + ');';
481 break;
482 // Exec and output
483 case this.modes.RAW:
484 // Add the exec'd result to the output
485 this.source += ';__output += ' + line.trim() + ';';
486 break;
487 case this.modes.COMMENT:
488 // Do nothing
489 break;
490 // Literal <%% mode, append as raw output
491 case this.modes.LITERAL:
492 _addOutput();
493 break;
494 }
495 }
496 // In string mode, just add the output
497 else {
498 _addOutput();
499 }
500 }
501
502 if (newLineCount) {
503 this.currentLine += newLineCount;
504 this.source += ';__line = ' + this.currentLine + ';';
505 }
506 };
507};
508
509// Express support
510exports.__express = exports.renderFile;
511
512// Add require support
513/* istanbul ignore else */
514if (require.extensions) {
515 require.extensions['.ejs'] = function (module, filename) {
516 filename = filename || /* istanbul ignore next */ module.filename;
517 var fs = require('fs')
518 , options = {
519 filename: filename
520 , client: true
521 }
522 , template = fs.readFileSync(filename).toString().trim()
523 , fn = compile(template, options);
524 module._compile('module.exports = ' + fn.toString() + ';', filename);
525 };
526}
527
528/* istanbul ignore if */
529if (typeof window != 'undefined') {
530 window.ejs = exports;
531}
532
533},{"./utils":2,"fs":3,"path":4}],2:[function(require,module,exports){
534/*
535 * EJS Embedded JavaScript templates
536 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
537 *
538 * Licensed under the Apache License, Version 2.0 (the "License");
539 * you may not use this file except in compliance with the License.
540 * You may obtain a copy of the License at
541 *
542 * http://www.apache.org/licenses/LICENSE-2.0
543 *
544 * Unless required by applicable law or agreed to in writing, software
545 * distributed under the License is distributed on an "AS IS" BASIS,
546 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
547 * See the License for the specific language governing permissions and
548 * limitations under the License.
549 *
550*/
551
552"use strict";
553
554exports.escapeRegExpChars = (function () {
555 var specials = [ '^', '$', '/', '.', '*', '+', '?', '|', '(', ')',
556 '[', ']', '{', '}', '\\' ];
557 var sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
558 return function (string) {
559 var str = string || '';
560 str = String(str);
561 return str.replace(sRE, '\\$1');
562 };
563})();
564
565exports.escapeXML = function (markup) {
566 var chars = {
567 '&': '&amp;'
568 , '<': '&lt;'
569 , '>': '&gt;'
570 , '"': '&quot;'
571 , '\'': '&#39;'
572 }
573 , str = String(markup);
574 Object.keys(chars).forEach(function (k) {
575 str = str.replace(new RegExp(k, 'g'), chars[k]);
576 });
577 return str;
578};
579
580exports.shallowCopy = function (to, from) {
581 for (var p in from) {
582 to[p] = from[p];
583 }
584 return to;
585};
586
587
588},{}],3:[function(require,module,exports){
589
590},{}],4:[function(require,module,exports){
591(function (process){
592// Copyright Joyent, Inc. and other Node contributors.
593//
594// Permission is hereby granted, free of charge, to any person obtaining a
595// copy of this software and associated documentation files (the
596// "Software"), to deal in the Software without restriction, including
597// without limitation the rights to use, copy, modify, merge, publish,
598// distribute, sublicense, and/or sell copies of the Software, and to permit
599// persons to whom the Software is furnished to do so, subject to the
600// following conditions:
601//
602// The above copyright notice and this permission notice shall be included
603// in all copies or substantial portions of the Software.
604//
605// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
606// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
607// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
608// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
609// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
610// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
611// USE OR OTHER DEALINGS IN THE SOFTWARE.
612
613// resolves . and .. elements in a path array with directory names there
614// must be no slashes, empty elements, or device names (c:\) in the array
615// (so also no leading and trailing slashes - it does not distinguish
616// relative and absolute paths)
617function normalizeArray(parts, allowAboveRoot) {
618 // if the path tries to go above the root, `up` ends up > 0
619 var up = 0;
620 for (var i = parts.length - 1; i >= 0; i--) {
621 var last = parts[i];
622 if (last === '.') {
623 parts.splice(i, 1);
624 } else if (last === '..') {
625 parts.splice(i, 1);
626 up++;
627 } else if (up) {
628 parts.splice(i, 1);
629 up--;
630 }
631 }
632
633 // if the path is allowed to go above the root, restore leading ..s
634 if (allowAboveRoot) {
635 for (; up--; up) {
636 parts.unshift('..');
637 }
638 }
639
640 return parts;
641}
642
643// Split a filename into [root, dir, basename, ext], unix version
644// 'root' is just a slash, or nothing.
645var splitPathRe =
646 /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
647var splitPath = function(filename) {
648 return splitPathRe.exec(filename).slice(1);
649};
650
651// path.resolve([from ...], to)
652// posix version
653exports.resolve = function() {
654 var resolvedPath = '',
655 resolvedAbsolute = false;
656
657 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
658 var path = (i >= 0) ? arguments[i] : process.cwd();
659
660 // Skip empty and invalid entries
661 if (typeof path !== 'string') {
662 throw new TypeError('Arguments to path.resolve must be strings');
663 } else if (!path) {
664 continue;
665 }
666
667 resolvedPath = path + '/' + resolvedPath;
668 resolvedAbsolute = path.charAt(0) === '/';
669 }
670
671 // At this point the path should be resolved to a full absolute path, but
672 // handle relative paths to be safe (might happen when process.cwd() fails)
673
674 // Normalize the path
675 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
676 return !!p;
677 }), !resolvedAbsolute).join('/');
678
679 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
680};
681
682// path.normalize(path)
683// posix version
684exports.normalize = function(path) {
685 var isAbsolute = exports.isAbsolute(path),
686 trailingSlash = substr(path, -1) === '/';
687
688 // Normalize the path
689 path = normalizeArray(filter(path.split('/'), function(p) {
690 return !!p;
691 }), !isAbsolute).join('/');
692
693 if (!path && !isAbsolute) {
694 path = '.';
695 }
696 if (path && trailingSlash) {
697 path += '/';
698 }
699
700 return (isAbsolute ? '/' : '') + path;
701};
702
703// posix version
704exports.isAbsolute = function(path) {
705 return path.charAt(0) === '/';
706};
707
708// posix version
709exports.join = function() {
710 var paths = Array.prototype.slice.call(arguments, 0);
711 return exports.normalize(filter(paths, function(p, index) {
712 if (typeof p !== 'string') {
713 throw new TypeError('Arguments to path.join must be strings');
714 }
715 return p;
716 }).join('/'));
717};
718
719
720// path.relative(from, to)
721// posix version
722exports.relative = function(from, to) {
723 from = exports.resolve(from).substr(1);
724 to = exports.resolve(to).substr(1);
725
726 function trim(arr) {
727 var start = 0;
728 for (; start < arr.length; start++) {
729 if (arr[start] !== '') break;
730 }
731
732 var end = arr.length - 1;
733 for (; end >= 0; end--) {
734 if (arr[end] !== '') break;
735 }
736
737 if (start > end) return [];
738 return arr.slice(start, end - start + 1);
739 }
740
741 var fromParts = trim(from.split('/'));
742 var toParts = trim(to.split('/'));
743
744 var length = Math.min(fromParts.length, toParts.length);
745 var samePartsLength = length;
746 for (var i = 0; i < length; i++) {
747 if (fromParts[i] !== toParts[i]) {
748 samePartsLength = i;
749 break;
750 }
751 }
752
753 var outputParts = [];
754 for (var i = samePartsLength; i < fromParts.length; i++) {
755 outputParts.push('..');
756 }
757
758 outputParts = outputParts.concat(toParts.slice(samePartsLength));
759
760 return outputParts.join('/');
761};
762
763exports.sep = '/';
764exports.delimiter = ':';
765
766exports.dirname = function(path) {
767 var result = splitPath(path),
768 root = result[0],
769 dir = result[1];
770
771 if (!root && !dir) {
772 // No dirname whatsoever
773 return '.';
774 }
775
776 if (dir) {
777 // It has a dirname, strip trailing slash
778 dir = dir.substr(0, dir.length - 1);
779 }
780
781 return root + dir;
782};
783
784
785exports.basename = function(path, ext) {
786 var f = splitPath(path)[2];
787 // TODO: make this comparison case-insensitive on windows?
788 if (ext && f.substr(-1 * ext.length) === ext) {
789 f = f.substr(0, f.length - ext.length);
790 }
791 return f;
792};
793
794
795exports.extname = function(path) {
796 return splitPath(path)[3];
797};
798
799function filter (xs, f) {
800 if (xs.filter) return xs.filter(f);
801 var res = [];
802 for (var i = 0; i < xs.length; i++) {
803 if (f(xs[i], i, xs)) res.push(xs[i]);
804 }
805 return res;
806}
807
808// String.prototype.substr - negative index don't work in IE8
809var substr = 'ab'.substr(-1) === 'b'
810 ? function (str, start, len) { return str.substr(start, len) }
811 : function (str, start, len) {
812 if (start < 0) start = str.length + start;
813 return str.substr(start, len);
814 }
815;
816
817}).call(this,require('_process'))
818},{"_process":5}],5:[function(require,module,exports){
819// shim for using process in browser
820
821var process = module.exports = {};
822
823process.nextTick = (function () {
824 var canSetImmediate = typeof window !== 'undefined'
825 && window.setImmediate;
826 var canMutationObserver = typeof window !== 'undefined'
827 && window.MutationObserver;
828 var canPost = typeof window !== 'undefined'
829 && window.postMessage && window.addEventListener
830 ;
831
832 if (canSetImmediate) {
833 return function (f) { return window.setImmediate(f) };
834 }
835
836 var queue = [];
837
838 if (canMutationObserver) {
839 var hiddenDiv = document.createElement("div");
840 var observer = new MutationObserver(function () {
841 var queueList = queue.slice();
842 queue.length = 0;
843 queueList.forEach(function (fn) {
844 fn();
845 });
846 });
847
848 observer.observe(hiddenDiv, { attributes: true });
849
850 return function nextTick(fn) {
851 if (!queue.length) {
852 hiddenDiv.setAttribute('yes', 'no');
853 }
854 queue.push(fn);
855 };
856 }
857
858 if (canPost) {
859 window.addEventListener('message', function (ev) {
860 var source = ev.source;
861 if ((source === window || source === null) && ev.data === 'process-tick') {
862 ev.stopPropagation();
863 if (queue.length > 0) {
864 var fn = queue.shift();
865 fn();
866 }
867 }
868 }, true);
869
870 return function nextTick(fn) {
871 queue.push(fn);
872 window.postMessage('process-tick', '*');
873 };
874 }
875
876 return function nextTick(fn) {
877 setTimeout(fn, 0);
878 };
879})();
880
881process.title = 'browser';
882process.browser = true;
883process.env = {};
884process.argv = [];
885
886function noop() {}
887
888process.on = noop;
889process.addListener = noop;
890process.once = noop;
891process.off = noop;
892process.removeListener = noop;
893process.removeAllListeners = noop;
894process.emit = noop;
895
896process.binding = function (name) {
897 throw new Error('process.binding is not supported');
898};
899
900// TODO(shtylman)
901process.cwd = function () { return '/' };
902process.chdir = function (dir) {
903 throw new Error('process.chdir is not supported');
904};
905
906},{}]},{},[1]);