ppwbdebug.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: pps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2017
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // Debug Library (optional)
  9. function Debugger () {
  10. window.onerror = function (msg,url,line){ alert("Line " + line + ": " + msg); return true; };
  11. //Member assignment...
  12. this.debugWin = open("", "debugWindow", "directories=no,hotkeys=no,innerHeight=500,innerWidth=300,location=no,menubar=yes,screenX=0,screenY=0,scrollbars=yes,resizeable=yes,status=no,titlebar=no,toolbar=no");
  13. this.maxDebugLength = 100;
  14. this.startTime = new Date();
  15. this.level = 1;
  16. if (typeof pdbSettingLevel == "number")
  17. this.level = pdbSettingLevel;
  18. this.dumpObjects = false;
  19. if (typeof pdbSettingObjectDump == "boolean")
  20. this.dumpObjects = pdbSettingObjectDump;
  21. this.appendOutput = false;
  22. if (typeof pdbSettingAppendOutput == "boolean")
  23. this.appendOutput = pdbSettingAppendOutput;
  24. this.fontSize = 1;
  25. if (typeof pdbSettingFontSize == "number")
  26. this.fontSize = pdbSettingFontSize;
  27. //Function assignment...
  28. this.out = pdbPrintMsg;
  29. this.dump = pdbDumpObject;
  30. this.dumpArgs = pdbDumpArguments;
  31. this.getObjectName = pdbGetObjectName;
  32. this.getFunctionName = pdbGetFunctionName;
  33. this.checkHide = pdbCheckHide;
  34. if (!this.appendOutput)
  35. {
  36. this.debugWin.document.close();
  37. this.debugWin.document.open();
  38. }
  39. if (!this.debugWin.document.title || this.debugWin.document.closed)
  40. {
  41. this.debugWin.document.write("<HTML><HEAD><TITLE>PPWeb Debug</TITLE></HEAD><BODY>");
  42. this.debugWin.document.write("<FONT SIZE=" + this.fontSize + "><B>*** Start ***</B><BR><UL><LI>");
  43. }
  44. else
  45. {
  46. this.debugWin.document.write("</UL><BR><B>*** Start ***</B><BR><UL><LI>");
  47. }
  48. }
  49. //DON'T call ANY of these directly...
  50. //call pdb.[func name] (see above)
  51. function pdbPrintMsg() {
  52. // this is a variable argument function called through pdb.out()
  53. // it is used to write to the debug window
  54. // suitable calls:
  55. //
  56. // pdb.out("This is a message") >> simply prints the message...
  57. // pdb.out(arguments); >> "call stack" type of message...identifies the calling func and its arguments
  58. // pdb.out(arguments, "Another message") or pdb.out("Another message", arguments);
  59. // pdb.out(object); >> calls the toString method of the object
  60. // pdb.out(property); >> prints the property name and value;
  61. // Also, if the last argument is a number, it is interpreted as the "message level".
  62. // if logging level >= message level
  63. // print message
  64. // else
  65. // skip it
  66. // If the message level is omitted, it is assumed to be 1 (ie. "terse" message...always present)
  67. var msg = "";
  68. var indent = false;
  69. var numArgs = arguments.length;
  70. if (numArgs <= 0) {
  71. return;
  72. }
  73. if (typeof arguments[numArgs-1] == "number") {
  74. if (this.level < arguments[numArgs-1])
  75. return;
  76. }
  77. for (var i = 0; i < numArgs; i++)
  78. {
  79. var arg = arguments[i];
  80. var argType = typeof arg;
  81. if (argType == "string")
  82. {
  83. msg += arg + "<br>";
  84. }
  85. else if (argType == "object")
  86. {
  87. if (typeof arg.callee != "undefined" && typeof arg.length != "undefined")
  88. {
  89. msg += this.getFunctionName(arg.callee) + " ( ";
  90. if (arg.length > 0)
  91. msg += this.dumpArgs(arg);
  92. msg += " ) ";
  93. }
  94. else
  95. {
  96. msg = arg.toString();
  97. }
  98. }
  99. else if (argType == "number" && (i+1 != numArgs))
  100. {
  101. msg += "\n" + arg.toString();
  102. }
  103. if ( i+2 < numArgs || ( i+1 == numArgs && argType != "number") )
  104. {
  105. if (!indent)
  106. {
  107. msg += "<UL>";
  108. indent = true;
  109. }
  110. msg += "<LI>";
  111. }
  112. }
  113. if (indent)
  114. msg += "</LI></UL>";
  115. var newTime = new Date();
  116. var timeOut = newTime.getHours() + ":" + newTime.getMinutes() + "." + newTime.getSeconds() + ":" + newTime.getMilliseconds();
  117. if (msg) {
  118. this.debugWin.document.write(timeOut + ": " + msg + "\n<LI>");
  119. // this.debugWin.scrollBy(0,100);
  120. }
  121. line = msg;
  122. if (line.length > this.maxDebugLength)
  123. line = "..." + line.substring(line.length - this.maxDebugLength);
  124. }
  125. function pdbDumpArguments (args) {
  126. var result = "";
  127. for (var i = 0; i < args.length; i++)
  128. {
  129. var arg = args[i];
  130. var argType = typeof arg;
  131. if (argType == "string" || argType == "number")
  132. {
  133. result += arg;
  134. }
  135. else if (argType == "object")
  136. {
  137. if (this.dumpObjects)
  138. {
  139. result += this.dump(arg);
  140. }
  141. else
  142. result += arg;
  143. }
  144. else
  145. {
  146. result += "<unknown function parameter>";
  147. }
  148. if (i+1 < args.length)
  149. result += ", ";
  150. }
  151. return result;
  152. }
  153. function pdbDumpObject (obj) {
  154. var result = this.getObjectName( obj ) + " { <br>";
  155. for (var prop in obj)
  156. {
  157. result += "variable: " + prop + ", value: " + obj[prop] + "<br>";
  158. }
  159. return result;
  160. }
  161. function pdbGetObjectName (obj) {
  162. if (typeof obj.constructor == "undefined")
  163. return "Object";
  164. return this.getFunctionName( obj.constructor );
  165. }
  166. function pdbGetFunctionName (func) {
  167. var funcBody = func.toString();
  168. var funcName = funcBody.substring(funcBody.indexOf(" "), funcBody.indexOf("{") );
  169. funcName = funcName.substring(0,funcName.indexOf("("));
  170. return funcName;
  171. }
  172. function pdbCheckHide() {
  173. for (n in _menus) {
  174. menu = _menus[n];
  175. if (menu._active) {
  176. var str = menu._id + ": Still Active !!";
  177. debug(str);
  178. menu._active = false;
  179. }
  180. }
  181. }