configSpidermonkey.js 2.3 KB

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