用于MS AJAX Beta1 + Preview的 debug补充包
2006-10-27 00:36 Cat Chen 阅读(406) 评论(0) 编辑 收藏 举报// Sys._Debug
if (debug.trace) {
delete debug.trace
}
function Sys$_Debug$clearTrace() {
var traceElement = document.getElementById('__atlas_trace');
if (traceElement) {
var children = traceElement.childNodes;
for(var i = children.length - 2; i > 0; i--) {
traceElement.removeChild(children[i]);
}
document.getElementById('__atlas_trace').style.display = 'none';
}
}
Sys._Debug.prototype.clearTrace = Sys$_Debug$clearTrace;
function Sys$_Debug$dump(object, name, recursive, indentationPadding, loopArray) {
name = name ? name : '';
indentationPadding = indentationPadding ? indentationPadding : '';
if (object == null) {
this.trace(indentationPadding + name + ': null');
return;
}
switch(typeof(object)) {
case 'undefined':
this.trace(indentationPadding + name + ': Undefined');
break;
case 'number': case 'string': case 'boolean':
this.trace(indentationPadding + name + ': ' + object);
break;
default:
if (Date.isInstanceOfType(object) || RegExp.isInstanceOfType(object)) {
this.trace(indentationPadding + name + ': ' + object.toString());
break;
}
if (!loopArray) {
loopArray = [];
}
else if (loopArray.contains(object)) {
this.trace(indentationPadding + name + ': ');
return;
}
loopArray.add(object);
var type = Object.getType(object);
var tagName = object.tagName;
var attributes = object.attributes;
if ((type == Object) && tagName && attributes) {
this.trace(indentationPadding + name + ' {' + tagName + '}');
indentationPadding += '+';
length = attributes.length;
for (var i = 0; i < length; i++) {
var val = attributes[i].nodeValue;
if (val) {
this.dump(val, attributes[i].nodeName, recursive, indentationPadding, loopArray);
}
}
}
else {
var typeName = type.getName();
this.trace(indentationPadding + name + (typeof(typeName) == 'string' ? ' {' + typeName + '}' : ''));
if ((indentationPadding == '') || recursive) {
indentationPadding += '+';
var i, length, properties, p, v;
if (Array.isInstanceOfType(object)) {
length = object.length;
for (i = 0; i < length; i++) {
this.dump(object[i], '[' + i + ']', recursive, indentationPadding, loopArray);
}
}
if (Sys.Preview.ITypeDescriptorProvider.isImplementedBy(object)) {
var td = Sys.Preview.TypeDescriptor.getTypeDescriptor(object);
properties = td._getProperties();
for (p in properties) {
var propertyInfo = properties[p];
if (propertyInfo.name) {
v = Sys.Preview.TypeDescriptor.getProperty(object, propertyInfo.name);
this.dump(v, p, recursive, indentationPadding, loopArray);
}
}
}
else {
for (p in object) {
v = object[p];
if (!Function.isInstanceOfType(v) && !Sys.UI.DomElement.isInstanceOfType(v)) {
this.dump(v, p, recursive, indentationPadding, loopArray);
}
}
}
}
}
loopArray.remove(object);
}
}
Sys._Debug.prototype.dump = Sys$_Debug$dump;
function Sys$_Debug$trace(text) {
// Debug.writeln(text);
var traceElement = document.getElementById('__atlas_trace');
if (!traceElement) {
traceElement = document.createElement('FIELDSET');
traceElement.id = '__atlas_trace';
traceElement.style.backgroundColor = 'white';
traceElement.style.color = 'black';
traceElement.style.textAlign = 'left';
traceElement.style.font = 'normal normal normal 1em/1.1em verdana,sans-serif';
var legend = document.createElement('LEGEND');
var legendText = document.createTextNode('Debugging Trace');
legend.appendChild(legendText);
traceElement.appendChild(legend);
var clearButton = document.createElement('INPUT');
clearButton.type = 'button';
clearButton.value = 'Clear Trace';
clearButton.onclick = debug.clearTrace;
traceElement.appendChild(clearButton);
document.body.appendChild(traceElement);
}
var traceLine = document.createElement('DIV');
traceLine.innerHTML = text;
traceElement.insertBefore(traceLine, traceElement.childNodes[traceElement.childNodes.length - 1]);
traceElement.style.display = 'block';
}
Sys._Debug.prototype.trace = Sys$_Debug$trace;
$trace = debug.trace;
$dump = Function.createDelegate(debug, debug.dump);
if (debug.trace) {
delete debug.trace
}
function Sys$_Debug$clearTrace() {
var traceElement = document.getElementById('__atlas_trace');
if (traceElement) {
var children = traceElement.childNodes;
for(var i = children.length - 2; i > 0; i--) {
traceElement.removeChild(children[i]);
}
document.getElementById('__atlas_trace').style.display = 'none';
}
}
Sys._Debug.prototype.clearTrace = Sys$_Debug$clearTrace;
function Sys$_Debug$dump(object, name, recursive, indentationPadding, loopArray) {
name = name ? name : '';
indentationPadding = indentationPadding ? indentationPadding : '';
if (object == null) {
this.trace(indentationPadding + name + ': null');
return;
}
switch(typeof(object)) {
case 'undefined':
this.trace(indentationPadding + name + ': Undefined');
break;
case 'number': case 'string': case 'boolean':
this.trace(indentationPadding + name + ': ' + object);
break;
default:
if (Date.isInstanceOfType(object) || RegExp.isInstanceOfType(object)) {
this.trace(indentationPadding + name + ': ' + object.toString());
break;
}
if (!loopArray) {
loopArray = [];
}
else if (loopArray.contains(object)) {
this.trace(indentationPadding + name + ': ');
return;
}
loopArray.add(object);
var type = Object.getType(object);
var tagName = object.tagName;
var attributes = object.attributes;
if ((type == Object) && tagName && attributes) {
this.trace(indentationPadding + name + ' {' + tagName + '}');
indentationPadding += '+';
length = attributes.length;
for (var i = 0; i < length; i++) {
var val = attributes[i].nodeValue;
if (val) {
this.dump(val, attributes[i].nodeName, recursive, indentationPadding, loopArray);
}
}
}
else {
var typeName = type.getName();
this.trace(indentationPadding + name + (typeof(typeName) == 'string' ? ' {' + typeName + '}' : ''));
if ((indentationPadding == '') || recursive) {
indentationPadding += '+';
var i, length, properties, p, v;
if (Array.isInstanceOfType(object)) {
length = object.length;
for (i = 0; i < length; i++) {
this.dump(object[i], '[' + i + ']', recursive, indentationPadding, loopArray);
}
}
if (Sys.Preview.ITypeDescriptorProvider.isImplementedBy(object)) {
var td = Sys.Preview.TypeDescriptor.getTypeDescriptor(object);
properties = td._getProperties();
for (p in properties) {
var propertyInfo = properties[p];
if (propertyInfo.name) {
v = Sys.Preview.TypeDescriptor.getProperty(object, propertyInfo.name);
this.dump(v, p, recursive, indentationPadding, loopArray);
}
}
}
else {
for (p in object) {
v = object[p];
if (!Function.isInstanceOfType(v) && !Sys.UI.DomElement.isInstanceOfType(v)) {
this.dump(v, p, recursive, indentationPadding, loopArray);
}
}
}
}
}
loopArray.remove(object);
}
}
Sys._Debug.prototype.dump = Sys$_Debug$dump;
function Sys$_Debug$trace(text) {
// Debug.writeln(text);
var traceElement = document.getElementById('__atlas_trace');
if (!traceElement) {
traceElement = document.createElement('FIELDSET');
traceElement.id = '__atlas_trace';
traceElement.style.backgroundColor = 'white';
traceElement.style.color = 'black';
traceElement.style.textAlign = 'left';
traceElement.style.font = 'normal normal normal 1em/1.1em verdana,sans-serif';
var legend = document.createElement('LEGEND');
var legendText = document.createTextNode('Debugging Trace');
legend.appendChild(legendText);
traceElement.appendChild(legend);
var clearButton = document.createElement('INPUT');
clearButton.type = 'button';
clearButton.value = 'Clear Trace';
clearButton.onclick = debug.clearTrace;
traceElement.appendChild(clearButton);
document.body.appendChild(traceElement);
}
var traceLine = document.createElement('DIV');
traceLine.innerHTML = text;
traceElement.insertBefore(traceLine, traceElement.childNodes[traceElement.childNodes.length - 1]);
traceElement.style.display = 'block';
}
Sys._Debug.prototype.trace = Sys$_Debug$trace;
$trace = debug.trace;
$dump = Function.createDelegate(debug, debug.dump);