[483] | 1 | // TODO: this file needs to be converted to the v1.7 loader |
---|
| 2 | |
---|
| 3 | // module: |
---|
| 4 | // configSpidermonkey |
---|
| 5 | // summary: |
---|
| 6 | // SpiderMonkey host environment |
---|
| 7 | |
---|
| 8 | if(dojo.config["baseUrl"]){ |
---|
| 9 | dojo.baseUrl = dojo.config["baseUrl"]; |
---|
| 10 | }else{ |
---|
| 11 | dojo.baseUrl = "./"; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | dojo._name = 'spidermonkey'; |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | dojo.isSpidermonkey = true; |
---|
| 19 | dojo.exit = function(exitcode){ |
---|
| 20 | quit(exitcode); |
---|
| 21 | }; |
---|
| 22 | |
---|
| 23 | if(typeof print == "function"){ |
---|
| 24 | console.debug = print; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | if(typeof line2pc == 'undefined'){ |
---|
| 28 | throw new Error("attempt to use SpiderMonkey host environment when no 'line2pc' global"); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | dojo._spidermonkeyCurrentFile = function(depth){ |
---|
| 32 | // |
---|
| 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). |
---|
| 36 | // |
---|
| 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. |
---|
| 40 | // |
---|
| 41 | var s = ''; |
---|
| 42 | try{ |
---|
| 43 | throw Error("whatever"); |
---|
| 44 | }catch(e){ |
---|
| 45 | s = e.stack; |
---|
| 46 | } |
---|
| 47 | // lines are like: bu_getCurrentScriptURI_spidermonkey("ScriptLoader.js")@burst/Runtime.js:101 |
---|
| 48 | var matches = s.match(/[^@]*\.js/gi); |
---|
| 49 | if(!matches){ |
---|
| 50 | throw Error("could not parse stack string: '" + s + "'"); |
---|
| 51 | } |
---|
| 52 | var fname = (typeof depth != 'undefined' && depth) ? matches[depth + 1] : matches[matches.length - 1]; |
---|
| 53 | if(!fname){ |
---|
| 54 | throw Error("could not find file name in stack string '" + s + "'"); |
---|
| 55 | } |
---|
| 56 | //print("SpiderMonkeyRuntime got fname '" + fname + "' from stack string '" + s + "'"); |
---|
| 57 | return fname; |
---|
| 58 | }; |
---|
| 59 | |
---|
| 60 | // print(dojo._spidermonkeyCurrentFile(0)); |
---|
| 61 | |
---|
| 62 | dojo._loadUri = function(uri){ |
---|
| 63 | // spidermonkey load() evaluates the contents into the global scope (which |
---|
| 64 | // is what we want). |
---|
| 65 | // TODO: sigh, load() does not return a useful value. |
---|
| 66 | // Perhaps it is returning the value of the last thing evaluated? |
---|
| 67 | // var ok = |
---|
| 68 | load(uri); |
---|
| 69 | // console.log("spidermonkey load(", uri, ") returned ", ok); |
---|
| 70 | return 1; |
---|
| 71 | }; |
---|
| 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. |
---|
| 76 | if(dojo.config["modulePaths"]){ |
---|
| 77 | for(var param in dojo.config["modulePaths"]){ |
---|
| 78 | dojo.registerModulePath(param, dojo.config["modulePaths"][param]); |
---|
| 79 | } |
---|
| 80 | } |
---|