configSpidermonkey.js 2.2 KB

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