2010-11-15 08:39:52 +01:00
|
|
|
/*
|
2011-11-08 17:40:44 +01:00
|
|
|
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
|
2010-11-15 08:39:52 +01:00
|
|
|
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
|
|
|
see: http://dojotoolkit.org/license for details
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-03-04 17:02:28 +01:00
|
|
|
/*
|
|
|
|
* SpiderMonkey host environment
|
|
|
|
*/
|
|
|
|
|
2010-11-15 08:39:52 +01:00
|
|
|
if(dojo.config["baseUrl"]){
|
2011-03-04 17:02:28 +01:00
|
|
|
dojo.baseUrl = dojo.config["baseUrl"];
|
2010-11-15 08:39:52 +01:00
|
|
|
}else{
|
2011-03-04 17:02:28 +01:00
|
|
|
dojo.baseUrl = "./";
|
2010-11-15 08:39:52 +01:00
|
|
|
}
|
2011-03-04 17:02:28 +01:00
|
|
|
|
|
|
|
dojo._name = 'spidermonkey';
|
|
|
|
|
|
|
|
/*=====
|
|
|
|
dojo.isSpidermonkey = {
|
2011-11-08 17:40:44 +01:00
|
|
|
// summary: Detect spidermonkey
|
2010-11-15 08:39:52 +01:00
|
|
|
};
|
2011-03-04 17:02:28 +01:00
|
|
|
=====*/
|
|
|
|
|
|
|
|
dojo.isSpidermonkey = true;
|
2011-11-08 17:40:44 +01:00
|
|
|
dojo.exit = function(exitcode){
|
|
|
|
quit(exitcode);
|
2010-11-15 08:39:52 +01:00
|
|
|
}
|
2011-03-04 17:02:28 +01:00
|
|
|
|
|
|
|
if(typeof print == "function"){
|
|
|
|
console.debug = print;
|
2010-11-15 08:39:52 +01:00
|
|
|
}
|
2011-03-04 17:02:28 +01:00
|
|
|
|
|
|
|
if(typeof line2pc == 'undefined'){
|
|
|
|
throw new Error("attempt to use SpiderMonkey host environment when no 'line2pc' global");
|
2010-11-15 08:39:52 +01:00
|
|
|
}
|
2011-03-04 17:02:28 +01:00
|
|
|
|
|
|
|
dojo._spidermonkeyCurrentFile = function(depth){
|
2011-11-08 17:40:44 +01:00
|
|
|
//
|
2011-03-04 17:02:28 +01:00
|
|
|
// This is a hack that determines the current script file by parsing a
|
|
|
|
// generated stack trace (relying on the non-standard "stack" member variable
|
|
|
|
// of the SpiderMonkey Error object).
|
2011-11-08 17:40:44 +01:00
|
|
|
//
|
2011-03-04 17:02:28 +01:00
|
|
|
// If param depth is passed in, it'll return the script file which is that far down
|
|
|
|
// the stack, but that does require that you know how deep your stack is when you are
|
|
|
|
// calling.
|
2011-11-08 17:40:44 +01:00
|
|
|
//
|
2011-03-04 17:02:28 +01:00
|
|
|
var s = '';
|
|
|
|
try{
|
|
|
|
throw Error("whatever");
|
|
|
|
}catch(e){
|
|
|
|
s = e.stack;
|
|
|
|
}
|
|
|
|
// lines are like: bu_getCurrentScriptURI_spidermonkey("ScriptLoader.js")@burst/Runtime.js:101
|
|
|
|
var matches = s.match(/[^@]*\.js/gi);
|
2011-11-08 17:40:44 +01:00
|
|
|
if(!matches){
|
2011-03-04 17:02:28 +01:00
|
|
|
throw Error("could not parse stack string: '" + s + "'");
|
|
|
|
}
|
|
|
|
var fname = (typeof depth != 'undefined' && depth) ? matches[depth + 1] : matches[matches.length - 1];
|
2011-11-08 17:40:44 +01:00
|
|
|
if(!fname){
|
2011-03-04 17:02:28 +01:00
|
|
|
throw Error("could not find file name in stack string '" + s + "'");
|
|
|
|
}
|
|
|
|
//print("SpiderMonkeyRuntime got fname '" + fname + "' from stack string '" + s + "'");
|
|
|
|
return fname;
|
2010-11-15 08:39:52 +01:00
|
|
|
}
|
2011-03-04 17:02:28 +01:00
|
|
|
|
2011-11-08 17:40:44 +01:00
|
|
|
// print(dojo._spidermonkeyCurrentFile(0));
|
2011-03-04 17:02:28 +01:00
|
|
|
|
|
|
|
dojo._loadUri = function(uri){
|
|
|
|
// spidermonkey load() evaluates the contents into the global scope (which
|
|
|
|
// is what we want).
|
2011-11-08 17:40:44 +01:00
|
|
|
// TODO: sigh, load() does not return a useful value.
|
2011-03-04 17:02:28 +01:00
|
|
|
// Perhaps it is returning the value of the last thing evaluated?
|
|
|
|
var ok = load(uri);
|
|
|
|
// console.log("spidermonkey load(", uri, ") returned ", ok);
|
|
|
|
return 1;
|
2010-11-15 08:39:52 +01:00
|
|
|
}
|
2011-03-04 17:02:28 +01:00
|
|
|
|
|
|
|
//Register any module paths set up in djConfig. Need to do this
|
|
|
|
//in the hostenvs since hostenv_browser can read djConfig from a
|
|
|
|
//script tag's attribute.
|
2010-11-15 08:39:52 +01:00
|
|
|
if(dojo.config["modulePaths"]){
|
2011-03-04 17:02:28 +01:00
|
|
|
for(var param in dojo.config["modulePaths"]){
|
|
|
|
dojo.registerModulePath(param, dojo.config["modulePaths"][param]);
|
|
|
|
}
|
2010-11-15 08:39:52 +01:00
|
|
|
}
|