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