Permalink
Browse files

abstracted the environment detection

  • Loading branch information...
1 parent 479a459 commit c05c8ed4160afba538b51d877a93af3f2a1e7782 Alex Young committed Oct 23, 2009
Showing with 30 additions and 12 deletions.
  1. +30 −12 riot.js
View
42 riot.js
@@ -5,21 +5,39 @@ var Riot = {
contexts: [],
run: function(tests) {
+ switch (this.detectEnvironment()) {
+ case 'xpcomcore':
+ Riot.formatter = new Riot.Formatters.XPComCore();
+ Riot.runAndReport(tests);
+ Sys.exit(Riot.exitCode);
+ break;
+ case 'rhino':
+ Riot.formatter = new Riot.Formatters.Text();
+ Riot.runAndReport(tests);
+ java.lang.System.exit(Riot.exitCode);
+ break;
+ case 'browser':
+ Riot.formatter = new Riot.Formatters.HTML();
+ var onload = window.onload;
+ window.onload = function() {
+ if (onload) { window.onload(); }
+ Riot.runAndReport(tests);
+ };
+ break;
+ }
+ },
+
+ detectEnvironment: function() {
+ if (typeof this.env !== 'undefined') {
+ return this.env;
+ }
+
if (typeof XPCOMCore !== 'undefined') {
- Riot.formatter = new Riot.Formatters.XPComCore();
- Riot.runAndReport(tests);
- Sys.exit(Riot.exitCode);
+ return 'xpcomcore';
} else if (typeof window === 'undefined') {
- Riot.formatter = new Riot.Formatters.Text();
- Riot.runAndReport(tests);
- java.lang.System.exit(Riot.exitCode);
+ return 'rhino';
} else {
- Riot.formatter = new Riot.Formatters.HTML();
- var onload = window.onload;
- window.onload = function() {
- if (onload) { window.onload(); }
- Riot.runAndReport(tests);
- };
+ return 'browser';
}
},

0 comments on commit c05c8ed

Please sign in to comment.