1 function rhinoDojoConfig(config, baseUrl, rhinoArgs){
3 // This module provides bootstrap configuration for running dojo in rhino.
5 // TODO: v1.6 tries to set dojo.doc and dojo.body in rhino; why?
7 // get a minimal console up
8 var log = function(hint, args){
9 print((hint ? hint + ":" : "") + args[0]);
10 for(var i = 1; i < args.length; i++){
11 print(", " + args[i]);
14 // intentionally define console in the global namespace
16 log: function(){ log(0, arguments); },
17 error: function(){ log("ERROR", arguments); },
18 warn: function(){ log("WARN", arguments); }
21 // any command line arguments with the load flag are pushed into deps
22 for(var deps = [], i = 0; i < rhinoArgs.length; i++){
23 var arg = (rhinoArgs[i] + "").split("=");
26 }else if(arg[0] == "mapPackage") {
27 var parts = arg[1].split(":"),
32 for (var j = 0; j < config.packages.length; j++) {
33 var pkg = config.packages[j];
34 if (pkg.name === name) {
35 pkg.location = location;
42 config.packages.push({
50 // provides timed callbacks using Java threads
51 if(typeof setTimeout == "undefined" || typeof clearTimeout == "undefined"){
53 clearTimeout = function(idx){
54 if(!timeouts[idx]){ return; }
58 setTimeout = function(func, delay){
66 java.lang.Thread.currentThread().sleep(this.sleepTime);
71 console.debug("Error running setTimeout thread:" + e);
76 var runnable = new java.lang.Runnable(def);
77 var thread = new java.lang.Thread(runnable);
79 return timeouts.push(thread) - 1;
83 var isLocal = function(url){
84 return (new java.io.File(url)).exists();
87 // reset the has cache with node-appropriate values;
97 "dojo-loader-catches":1,
98 "dojo-dom-ready-api":0,
99 "dojo-publish-privates":1,
105 for(var p in hasCache){
106 config.hasCache[p] = hasCache[p];
109 // reset some configuration switches with rhino-appropriate values
112 commandLineArgs:rhinoArgs,
115 locale:String(java.util.Locale.getDefault().toString().replace('_', '-').toLowerCase()),
118 injectUrl: function(url, callback){
123 require.eval(readUrl(url, "UTF-8"));
127 console.log("failed to load resource (" + url + ")");
132 getText: function(url, sync, onLoad){
133 // TODO: test https://bugzilla.mozilla.org/show_bug.cgi?id=471005; see v1.6 hostenv_rhino
134 // note: async mode not supported in rhino
135 onLoad(isLocal(url) ? readFile(url, "UTF-8") : readUrl(url, "UTF-8"));
139 for(p in rhinoConfig){
140 config[p] = rhinoConfig[p];