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