You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
7.5 KiB
1 line
7.5 KiB
2 years ago
|
/*
DynAPI Distribution
Debugger
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/
// Note: Debugger does not have to be a DynObject - very important for blueprinted layers
function Debugger() {
this._mode='normal';
this.win = null;
this._watch={};
this._evalBuffer='';
this._buffer = dynapi._debugBuffer;
dynapi._debugBuffer = '';
// close the debug window on unload
this.closeOnUnLoad = false;
dynapi.onUnload(function() {
if (dynapi.debug.closeOnUnLoad) dynapi.debug.close();
});
this.open();
}
var p = Debugger.prototype; //dynapi.setPrototype('Debugger','DynObject');
p.close = function() {
if (this.isLoaded()) {
this.win.close();
this.win = null;
}
};
// error - output a browser generated error to the debug window
p.error = function(msg, url, lno) {
if (url && url.indexOf(dynapi.documentPath)==0) {
url = url.substring(dynapi.documentPath.length);
}
this.print('Error:'+ (lno? ' Line '+lno : '') +' ['+url+']\n '+msg);
};
// evaluates an expression in the scope of the main dynapi window
p.evaluate = function(str) {
dynapi.frame.eval(str);
this.setEvalHistory(str);
};
// get evaluation history
p.getEvalHistory=function(n){
if(!this.isLoaded()) return;
var t,f=this.win.document.debugform;
if(n>=1) {
var lim=this.win.evalHistory.length-1;
this.win.evalIndex++;
if (this.win.evalIndex>lim) this.win.evalIndex=(lim<0)?0:lim;
t=this.win.evalHistory[this.win.evalIndex];
if(t)f.eval.value=t;
}else if(n<=0){
this.win.evalIndex--;
if(this.win.evalIndex<0) this.win.evalIndex=0;
t=this.win.evalHistory[this.win.evalIndex];
if(t)f.eval.value=t;
}
};
// lists all known properties of an object
p.inspect = function(obj,showFunctions) {
this.print('Inspecting:');
var v;
if (typeof(obj)=='string') obj=eval(obj);
if (typeof(obj)=='object') {
for (var i in obj) {
if (obj[i]==null) v = 'null'
else if (typeof(obj[i])=='undefined') v = 'null';
else if (typeof(obj[i])=='function') {
if (showFunctions==false) continue;
else v = '[Function]';
}
else if (typeof(obj[i])=='object' && typeof(obj[i].length)!='undefined') v = 'Array';// ['+obj[i]+']';
else if (typeof(obj[i])=='object') v = '[Object]';
else v = obj[i];
this.print(' '+i+' = '+v);
}
}
else this.print(' undefined');
};
p.isLoaded = function() {
return (this.win!=null && this.win.document && typeof(this.win.document.debugform)=="object");
};
// opens the debugger window
p.open = function() {
var p = dynapi.library.path;
if (!this.isLoaded() && p) {
var url = dynapi.documentPath+p+'ext/debug.html#';
var w = (dynapi.ua.def||dynapi.ua.dom)? 350:355 //dynapi.ua.mac? (dynapi.ua.ie?330:300) : 350;
var h = (dynapi.ua.def||dynapi.ua.dom)? 432:485 //dynapi.ua.mac? (dynapi.ua.ie?405:365) : (dynapi.ua.def||dynapi.ua.dom)? 420:476;
this.win = window.open(url,'debugwin','width='+w+',height='+h+',scrollbars=no,status=no,toolbar=no'); //,resizable=no
this.win.opener=window;
this.win.evalHistory=[];
this.win.evalIndex=0;
this.print();
/* dynapi.frame.onerror = function(msg, url, lno) {
dynapi.debug.error(msg, url, lno);
};
*/
}
};
// output text to the debug window
p.print = function(s) {
if (s==null) s = '';
else s = s + '\n';
if (this.isLoaded()) {
this.switchMode('normal');
if (this._buffer != '') { // dump buffer
s = this._buffer + s;
this._buffer = '';
}
this.win.document.debugform.print.value += s;
this._normalModeData = this.win.document.debugform.print.value;
// Does mozilla has something like this?
if (dynapi.ua.ie) {
var po = this.win.document.debugform.print;
po.scrollTop = po.scrollHeight;
var range = po.createTextRange();
range.collapse(false);
range.select();
}
}
else this._buffer += s;
};
// reloads selected javascripts, packages or html pages
p.reload=function(t){
if (!this.isLoaded) return;
t=t+'';
if(t.substr(0,3).toLowerCase()=='go:') {
t=t.substr(3).replace(/\\/g,'/');
dynapi.frame.location.href=t;
return;
}
var i,f=t.split(';');
for(i=0;i<f.length;i++){
t=f[i];
|