PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/scripts/debug.js

http://showslow.googlecode.com/
JavaScript | 94 lines | 84 code | 6 blank | 4 comment | 28 complexity | e09edb0a665c01f771ec8cdf1ce70b1f MD5 | raw file
  1. /*==================================================
  2. * Debug Utility Functions
  3. *==================================================
  4. */
  5. SimileAjax.Debug = {
  6. silent: false
  7. };
  8. SimileAjax.Debug.log = function(msg) {
  9. var f;
  10. if ("console" in window && "log" in window.console) { // FireBug installed
  11. f = function(msg2) {
  12. console.log(msg2);
  13. }
  14. } else {
  15. f = function(msg2) {
  16. if (!SimileAjax.Debug.silent) {
  17. alert(msg2);
  18. }
  19. }
  20. }
  21. SimileAjax.Debug.log = f;
  22. f(msg);
  23. };
  24. SimileAjax.Debug.warn = function(msg) {
  25. var f;
  26. if ("console" in window && "warn" in window.console) { // FireBug installed
  27. f = function(msg2) {
  28. console.warn(msg2);
  29. }
  30. } else {
  31. f = function(msg2) {
  32. if (!SimileAjax.Debug.silent) {
  33. alert(msg2);
  34. }
  35. }
  36. }
  37. SimileAjax.Debug.warn = f;
  38. f(msg);
  39. };
  40. SimileAjax.Debug.exception = function(e, msg) {
  41. var f, params = SimileAjax.parseURLParameters();
  42. if (params.errors == "throw" || SimileAjax.params.errors == "throw") {
  43. f = function(e2, msg2) {
  44. throw(e2); // do not hide from browser's native debugging features
  45. };
  46. } else if ("console" in window && "error" in window.console) { // FireBug installed
  47. f = function(e2, msg2) {
  48. if (msg2 != null) {
  49. console.error(msg2 + " %o", e2);
  50. } else {
  51. console.error(e2);
  52. }
  53. throw(e2); // do not hide from browser's native debugging features
  54. };
  55. } else {
  56. f = function(e2, msg2) {
  57. if (!SimileAjax.Debug.silent) {
  58. alert("Caught exception: " + msg2 + "\n\nDetails: " + ("description" in e2 ? e2.description : e2));
  59. }
  60. throw(e2); // do not hide from browser's native debugging features
  61. };
  62. }
  63. SimileAjax.Debug.exception = f;
  64. f(e, msg);
  65. };
  66. SimileAjax.Debug.objectToString = function(o) {
  67. return SimileAjax.Debug._objectToString(o, "");
  68. };
  69. SimileAjax.Debug._objectToString = function(o, indent) {
  70. var indent2 = indent + " ";
  71. if (typeof o == "object") {
  72. var s = "{";
  73. for (n in o) {
  74. s += indent2 + n + ": " + SimileAjax.Debug._objectToString(o[n], indent2) + "\n";
  75. }
  76. s += indent + "}";
  77. return s;
  78. } else if (typeof o == "array") {
  79. var s = "[";
  80. for (var n = 0; n < o.length; n++) {
  81. s += SimileAjax.Debug._objectToString(o[n], indent2) + "\n";
  82. }
  83. s += indent + "]";
  84. return s;
  85. } else {
  86. return o;
  87. }
  88. };