2150 |
mathias |
1 |
/*
|
|
|
2 |
* SpiderMonkey host environment
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
if(djConfig["baseUrl"]){
|
|
|
6 |
dojo.baseUrl = djConfig["baseUrl"];
|
|
|
7 |
}else{
|
|
|
8 |
dojo.baseUrl = "./";
|
|
|
9 |
}
|
|
|
10 |
|
|
|
11 |
dojo._name = 'spidermonkey';
|
|
|
12 |
dojo.isSpidermonkey = true;
|
|
|
13 |
dojo.exit = function(exitcode){
|
|
|
14 |
quit(exitcode);
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
if(typeof print == "function"){
|
|
|
18 |
console.debug = print;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
if(typeof line2pc == 'undefined'){
|
|
|
22 |
throw new Error("attempt to use SpiderMonkey host environment when no 'line2pc' global");
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
dojo._spidermonkeyCurrentFile = function(depth){
|
|
|
26 |
//
|
|
|
27 |
// This is a hack that determines the current script file by parsing a
|
|
|
28 |
// generated stack trace (relying on the non-standard "stack" member variable
|
|
|
29 |
// of the SpiderMonkey Error object).
|
|
|
30 |
//
|
|
|
31 |
// If param depth is passed in, it'll return the script file which is that far down
|
|
|
32 |
// the stack, but that does require that you know how deep your stack is when you are
|
|
|
33 |
// calling.
|
|
|
34 |
//
|
|
|
35 |
var s = '';
|
|
|
36 |
try{
|
|
|
37 |
throw Error("whatever");
|
|
|
38 |
}catch(e){
|
|
|
39 |
s = e.stack;
|
|
|
40 |
}
|
|
|
41 |
// lines are like: bu_getCurrentScriptURI_spidermonkey("ScriptLoader.js")@burst/Runtime.js:101
|
|
|
42 |
var matches = s.match(/[^@]*\.js/gi);
|
|
|
43 |
if(!matches){
|
|
|
44 |
throw Error("could not parse stack string: '" + s + "'");
|
|
|
45 |
}
|
|
|
46 |
var fname = (typeof depth != 'undefined' && depth) ? matches[depth + 1] : matches[matches.length - 1];
|
|
|
47 |
if(!fname){
|
|
|
48 |
throw Error("could not find file name in stack string '" + s + "'");
|
|
|
49 |
}
|
|
|
50 |
//print("SpiderMonkeyRuntime got fname '" + fname + "' from stack string '" + s + "'");
|
|
|
51 |
return fname;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
// print(dojo._spidermonkeyCurrentFile(0));
|
|
|
55 |
|
|
|
56 |
dojo._loadUri = function(uri){
|
|
|
57 |
// spidermonkey load() evaluates the contents into the global scope (which
|
|
|
58 |
// is what we want).
|
|
|
59 |
// TODO: sigh, load() does not return a useful value.
|
|
|
60 |
// Perhaps it is returning the value of the last thing evaluated?
|
|
|
61 |
var ok = load(uri);
|
|
|
62 |
// console.debug("spidermonkey load(", uri, ") returned ", ok);
|
|
|
63 |
return 1;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
//Register any module paths set up in djConfig. Need to do this
|
|
|
67 |
//in the hostenvs since hostenv_browser can read djConfig from a
|
|
|
68 |
//script tag's attribute.
|
|
|
69 |
if(djConfig["modulePaths"]){
|
|
|
70 |
for(var param in djConfig["modulePaths"]){
|
|
|
71 |
dojo.registerModulePath(param, djConfig["modulePaths"][param]);
|
|
|
72 |
}
|
|
|
73 |
}
|