b7d678ac354ed2093303852b7637a9f4e0be7ed6.svn-base 2.2 KB

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