hostenv_spidermonkey.js 2.4 KB

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