123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- function Debugger () {
-
- this.debugWindowString = 'open("", "debugWindow", "height=400,left=10,top=10,width=600,location=no,menubar=no,scrollbars=yes,resizable=yes,status=no,toolbar=no")';
- this.debugWin = eval(this.debugWindowString);
- this.maxDebugLength = 100;
- this.startTime = new Date();
- this.stack = new Array();
- this.execprofile = new Array();
- this.action = "";
- this.lastCaller = "";
- this.dumpObjects = true;
- this.appendOutput = false;
- var dbgAppend = topparent.getGlobal("jsDebugAppendOutput");
- if (typeof dbgAppend != "undefined")
- this.appendOutput = dbgAppend;
- this.fontSize = 1;
- var dbgFont = topparent.getGlobal("jsDebugFontSize");
- if (typeof dbgFont != "undefined")
- this.fontSize = dbgFont;
- if (!this.appendOutput)
- {
- this.debugWin.document.close();
- this.debugWin.document.open();
- }
- if (!this.debugWin.document.title || this.debugWin.document.closed)
- {
- this.debugWin.document.write("<HTML><HEAD><TITLE>PPWeb Debug</TITLE></HEAD><BODY>");
- this.debugWin.document.write("<FONT SIZE=" + this.fontSize + "><B>*** Start ***</B><BR>");
- }
- else
- {
- this.debugWin.document.write("<BR><B>*** Start ***</B><BR>");
- }
- }
- Debugger.prototype.out = function () {
- var msg = "";
- var numArgs = arguments.length;
- if (numArgs <= 0) {
- return;
- }
- if (arguments.length == 2)
- {
-
-
- var caller = arguments[1];
- var action = this.action;
- if (action == "push")
- msg += "<br>";
- else if (action == "pop" && caller != this.lastCaller)
- msg += "<br>";
- this.lastCaller = caller;
- }
- else
- {
-
- msg += "<br>";
- this.lastCaller = "";
- this.action = "msg";
- }
- if (msg.indexOf("<br>") == 0)
- {
- for (var j = 0; j < this.stack.length; j++)
- msg += " ";
- }
- msg += arguments[0];
- if (msg) {
- this.debugWin.document.write(msg);
- }
- }
- Debugger.prototype.dumpArguments = function (obj) {
- this.out(this.dumpArgs(obj));
- }
- Debugger.prototype.dumpArgs = function (args) {
- var result = "";
- for (var i = 0; i < args.length; i++)
- {
- var arg = args[i];
- var argType = typeof arg;
-
- if (argType == "string" || argType == "number")
- {
- result += arg;
- }
- else if (argType == "object")
- {
- if (this.dumpObjects)
- {
- result += this.dumpObj(arg);
- }
- else
- result += arg;
- }
- else
- {
- result += "<unknown function parameter>";
- }
- if (i+1 < args.length)
- result += ", ";
- }
- return result;
- }
- Debugger.prototype.dumpObject = function (obj) {
- this.out(this.dumpObj(obj));
- }
- Debugger.prototype.dumpObj = function (obj) {
- var result = this.getObjectName( obj ) + "<br> { <br>";
- for (var prop in obj)
- {
- if (typeof prop != "function")
- result += prop + "=" + obj[prop] + "<br>";
- }
- result += " }; <br>";
- return result;
- }
- Debugger.prototype.getObjectName = function (obj) {
- if (typeof obj.constructor == "undefined")
- return "Object";
- return this.getFunctionName( obj.constructor );
- }
- Debugger.prototype.getFunctionName = function (funcref) {
- if (!funcref)
- return '';
- if (funcref.name)
- return funcref.name;
- var name = funcref + '';
- name = name.substring(name.indexOf(' ') + 1, name.indexOf('('));
- funcref.name = name;
- return name;
- }
- Debugger.prototype.createFunctionWrapper = function (scopename, funcname, precall, postcall)
- {
- var wrappedfunc;
- var scopeobject = eval(scopename);
- var funcref = scopeobject[funcname];
- scopeobject['xbDebug_orig_' + funcname] = funcref;
- wrappedfunc = function ()
- {
- var rv;
- precall(scopename, funcname, arguments);
- rv = funcref.apply(scopeobject, arguments);
- postcall(scopename, funcname, arguments, rv);
- return rv;
- };
- if (typeof(funcref.constructor) != 'undefined')
- wrappedfunc.constructor = funcref.constuctor;
- if (typeof(funcref.prototype) != 'undefined')
- wrappedfunc.prototype = funcref.prototype;
- scopeobject[funcname] = wrappedfunc;
- }
- Debugger.prototype.createMethodWrapper = function (contextname, classname, methodname, precall, postcall)
- {
- var context = eval(contextname);
- var methodref = context[classname].prototype[methodname];
- context[classname].prototype['xbDebug_orig_' + methodname] = methodref;
- var wrappedmethod = function ()
- {
- var rv;
-
- var thisref = eval('this');
-
- var argsref = arguments;
- precall(contextname + '.' + classname, methodname, argsref);
- rv = methodref.apply(thisref, argsref);
- postcall(contextname + '.' + classname, methodname, argsref, rv);
- return rv;
- };
- return wrappedmethod;
- }
- Debugger.prototype.traceBefore = function (scopename, funcname, funcarguments)
- {
- var i;
- var s = '';
- var name = scopename + '.' + funcname;
- var profile = pdb.execprofile[name];
- if (!profile)
- profile = pdb.execprofile[name] = { started: 0, time: 0, count: 0 };
-
- var s = name + '(' + pdb.storeAsString(funcarguments) + ')';
- pdb.action = "push";
- pdb.out(s, name);
- pdb.stack.push(name);
- profile.started = (new Date()).getTime();
- }
- Debugger.prototype.traceAfter = function (scopename, funcname, funcarguments, rv)
- {
- var i;
- var s = '';
- var name = scopename + '.' + funcname;
- var execprofile = pdb.execprofile[name];
- if (!execprofile)
- pdb.out('TraceAfter: execprofile not created for ' + name);
- else if (execprofile.started == 0)
- pdb.out('TraceAfter: execprofile.started == 0 for ' + name);
- else
- {
- execprofile.time = (new Date()).getTime() - execprofile.started;
- execprofile.count++;
- execprofile.started = 0;
- }
- pdb.stack.pop();
- pdb.action = "pop";
- var s = " returned: " + rv + ", execution time: " + execprofile.time;
- pdb.out(s, name);
- }
- Debugger.prototype.traceFunction = function (scopename, funcname)
- {
- this.createFunctionWrapper(scopename, funcname, this.traceBefore, this.traceAfter);
- }
- Debugger.prototype.traceObject = function (contextname, classname)
- {
- var classref = eval(contextname + '.' + classname);
- var p;
- var sp;
- if (!classref || !classref.prototype)
- return;
- for (p in classref.prototype)
- {
- sp = p;
- if (typeof(classref.prototype[sp]) == 'function' && (sp).indexOf('xbDebug_orig') == -1)
- {
- classref.prototype[sp] = this.createMethodWrapper(contextname, classname, sp, this.traceBefore, this.traceAfter);
- }
- }
- }
-
- Debugger.prototype.dumpProfile = function ()
- {
- var p;
- var execprofile;
- var avg;
- for (p in this.execprofile)
- {
- execprofile = this.execprofile[p];
- avg = Math.round ( 100 * execprofile.time/execprofile.count) /100;
- this.out('Execution profile ' + p + ' called ' + execprofile.count + ' times. Total time=' + execprofile.time + 'ms. Avg Time=' + avg + 'ms.');
- }
- }
- Debugger.prototype.storeAsString = function (obj)
- {
- var argType = typeof obj;
- var msg = "";
-
- if (argType == "string")
- {
- msg = obj;
- }
-
- else if (argType == "object")
- {
- if (obj.constructor == "Array" || typeof obj.length != undefined)
- {
- for (var i = 0; i < obj.length; i++)
- {
- msg += obj[i]
- if (i+1 < obj.length)
- msg += ", ";
- }
- }
- else
- {
- msg = pdb.dumpObj(obj);
- }
- }
- return msg;
- }
|