[Pkg-mozext-commits] [firebug] 17/82: Clean up DOM panel code
David Prévot
taffit at moszumanska.debian.org
Mon Mar 31 22:45:37 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to tag fbtest-1.11.2
in repository firebug.
commit d5d967e06b5889d6d18ab29206093c192e84bbe9
Author: Simon Lindholm <simon.lindholm10 at gmail.com>
Date: Tue Dec 18 01:27:30 2012 +0100
Clean up DOM panel code
---
extension/content/firebug/dom/domPanel.js | 188 +++++++++++++++--------------
extension/content/firebug/editor/editor.js | 2 +-
extension/content/firebug/js/watchPanel.js | 15 +--
extension/content/firebug/lib/domplate.js | 10 +-
extension/content/firebug/lib/lib.js | 7 +-
5 files changed, 114 insertions(+), 108 deletions(-)
diff --git a/extension/content/firebug/dom/domPanel.js b/extension/content/firebug/dom/domPanel.js
index d9eee6f..eb0a25d 100644
--- a/extension/content/firebug/dom/domPanel.js
+++ b/extension/content/firebug/dom/domPanel.js
@@ -174,9 +174,10 @@ const DirTablePlate = domplate(Firebug.Rep,
var panel = row.parentNode.parentNode.domPanel;
if (panel)
{
+ // XXX this should use member.value
var rowValue = panel.getRowPropertyValue(row);
- if (typeof(rowValue) == "boolean")
- panel.setPropertyValue(row, !rowValue);
+ if (typeof rowValue == "boolean")
+ panel.setPropertyValue(row, ""+!rowValue);
else
panel.editProperty(row);
Events.cancelEvent(event);
@@ -187,7 +188,7 @@ const DirTablePlate = domplate(Firebug.Rep,
toggleRow: function(row)
{
- var level = parseInt(row.getAttribute("level"));
+ var level = parseInt(row.getAttribute("level"), 10);
var table = Dom.getAncestorByClass(row, "domTable");
var toggles = table.toggles;
if (!toggles)
@@ -239,7 +240,7 @@ const DirTablePlate = domplate(Firebug.Rep,
{
for (var firstRow = row.nextSibling; firstRow; firstRow = row.nextSibling)
{
- if (parseInt(firstRow.getAttribute("level")) <= level)
+ if (parseInt(firstRow.getAttribute("level"), 10) <= level)
break;
tbody.removeChild(firstRow);
@@ -252,12 +253,11 @@ const DirTablePlate = domplate(Firebug.Rep,
Css.setClass(row, "opened");
if (isString)
{
- var rowValue = row.domObject.value
+ var rowValue = row.domObject.value;
row.lastChild.firstChild.textContent = '"' + rowValue + '"';
}
else
{
-
if (toggles)
{
var path = getPath(row);
@@ -363,10 +363,10 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
{
if (!Firebug.viewChrome)
{
+ // Unwrap native, wrapped objects.
var contentView = Wrapper.getContentView(object);
- if (!contentView && FBTrace.DBG_DOM)
- FBTrace.sysout("getObjectView: no contentView for " + object);
- return contentView || object;
+ if (contentView)
+ return contentView;
}
return object;
},
@@ -453,18 +453,25 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
Firebug.showEnumerableProperties, Firebug.showOwnProperties);
properties = Arr.sortUnique(properties);
- if (contentView.hasOwnProperty("constructor") &&
+ var hOP = Object.prototype.hasOwnProperty;
+ if (hOP.call(contentView, "constructor") &&
properties.indexOf("constructor") == -1)
{
properties.push("constructor");
}
- if (contentView.hasOwnProperty("prototype") &&
+ if (hOP.call(contentView, "prototype") &&
properties.indexOf("prototype") == -1)
{
properties.push("prototype");
}
+ if (hOP.call(contentView, "wrappedJSObject") &&
+ properties.indexOf("wrappedJSObject") == -1)
+ {
+ properties.push("wrappedJSObject");
+ }
+
// If showOwnProperties is false the __proto__ can be already in.
// If showOwnProperties is true the __proto__ should not be in.
if (contentView.__proto__ && Obj.hasProperties(contentView.__proto__) &&
@@ -475,7 +482,12 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
}
catch (exc)
{
- // workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=648560
+ if (FBTrace.DBG_ERRORS || FBTrace.DBG_DOM)
+ FBTrace.sysout("dom.getMembers: property lookups failed", exc);
+
+ // workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=648560
+ // XXX can't reproduce, and it's at most relevant to Chromebug.
+ /*
if (contentView.wrappedJSObject)
{
if (FBTrace.DBG_ERRORS || FBTrace.DBG_DOM)
@@ -495,11 +507,9 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
object = contentView;
}
+ */
}
- if (contentView.wrappedJSObject)
- properties.push("wrappedJSObject");
-
var domMembers = Dom.getDOMMembers(object);
for (var i = 0; i < properties.length; i++)
{
@@ -519,7 +529,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
var val;
try
{
- val = contentView[name]; // getter is safe
+ val = contentView[name];
}
catch (exc)
{
@@ -576,8 +586,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
{
// Sometimes we get exceptions just from trying to iterate the members
// of certain objects, like StorageList, but don't let that gum up the works
- //throw exc;
- if (FBTrace.DBG_ERRORS && FBTrace.DBG_DOM)
+ if (FBTrace.DBG_DOM)
FBTrace.sysout("dom.getMembers FAILS: ", exc);
}
@@ -622,7 +631,6 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
if (Firebug.showDOMConstants)
members.push.apply(members, domConstants);
- // The prototype is always displayed at the end.
members.push.apply(members, proto);
if (Firebug.showInlineEventHandlers)
@@ -654,7 +662,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
return members;
},
- addMember: function(object, type, props, name, value, level, order, context)
+ addMember: function()
{
try
{
@@ -669,34 +677,40 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
addMemberInternal: function(object, type, props, name, value, level, order, context)
{
- // do this first in case a call to instanceof reveals contents
+ // Do this first in case a call to instanceof (= QI, for XPCOM things) reveals contents.
var rep = Firebug.getRep(value);
var tag = rep.shortTag ? rep.shortTag : rep.tag;
var hasProperties = Obj.hasProperties(value, !Firebug.showEnumerableProperties,
Firebug.showOwnProperties);
- var valueType = typeof(value);
+ var valueType = typeof value;
var hasChildren = hasProperties && !(value instanceof FirebugReps.ErrorCopy) &&
- (valueType == "function" || (valueType == "object" && value != null)
- || (valueType == "string" && value.length > Firebug.stringCropLength));
+ ((valueType == "function") ||
+ (valueType == "object" && value != null) ||
+ (valueType == "string" && value.length > Firebug.stringCropLength));
// Special case for "arguments", which is not enumerable by for...in statement
// and so, Obj.hasProperties always returns false.
- if (!hasChildren && value) // arguments will never be falsy if the arguments exist
- hasChildren = isArguments(value);
+ hasChildren = hasChildren || (!!value && isArguments(value));
- if (value)
+ if (valueType === "function" && !hasChildren)
{
- var proto = Obj.getPrototype(value);
- // Special case for functions with a prototype that has values
- if (valueType === "function" && proto)
+ try
{
- hasChildren = hasChildren || Obj.hasProperties(proto,
- !Firebug.showEnumerableProperties, Firebug.showOwnProperties);
+ // Special case for functions with a prototype that has values
+ var proto = value.prototype;
+ if (proto)
+ {
+ hasChildren = Obj.hasProperties(proto, !Firebug.showEnumerableProperties,
+ Firebug.showOwnProperties);
+ }
}
+ catch (exc) {}
}
+ var descriptor = getPropertyDescriptor(object, name);
+
var member = {
object: object,
name: name,
@@ -710,7 +724,9 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
hasChildren: hasChildren,
tag: tag,
prefix: "",
- readOnly: false
+ readOnly: (descriptor && !descriptor.writable && !descriptor.set),
+ // XXX should probably move the tests from getContextMenuItems here
+ deletable: !(descriptor && !descriptor.configurable)
};
// The context doesn't have to be specified (e.g. in case of Watch panel that is based
@@ -731,6 +747,8 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
// Set prefix for user defined properties. This prefix help the user to distinguish
// among simple properties and those defined using getter and/or (only a) setter.
+ // XXX This should be rewritten to use 'descriptor', and I believe the unwrapping
+ // test is wrong (see issue 5377).
var o = this.getObjectView(object);
if (o && !Dom.isDOMMember(object, name) && (XPCNativeWrapper.unwrap(object) !== object))
{
@@ -751,15 +769,10 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
// only setter
if (!getter && setter)
{
- member.readOnly = true;
member.prefix = "set";
}
}
- var readOnly = isReadOnly(object, name);
- if (typeof(readOnly) != "undefined")
- member.readOnly = readOnly;
-
props.push(member);
return member;
},
@@ -961,14 +974,18 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
getRowPathName: function(row)
{
- var name = row.domObject.name;
+ var member = row.domObject, name = member.name;
- if(name.match(/^[\d]+$/))//ordinal
+ // Ordinals.
+ if (name.match(/^[\d]+$/))
return ["", "["+name+"]"];
- else if(name.match(rxIdentifier))//identifier
+
+ // Identifiers.
+ if (name.match(rxIdentifier))
return [".", name];
- else//map keys
- return ["", "[\""+name.replace(/\\/g, "\\\\").replace(/"/g,"\\\"") + "\"]"];
+
+ // Other, weird, names.
+ return ["", "[\""+name.replace(/\\/g, "\\\\").replace(/"/g,"\\\"") + "\"]"];
},
copyName: function(row)
@@ -991,7 +1008,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
getPropertyPath: function(row)
{
var path = [];
- for(var current = row; current ; current = getParentRow(current))
+ for (var current = row; current ; current = getParentRow(current))
path = this.getRowPathName(current).concat(path);
path.shift(); //don't want the first separator
return path;
@@ -1026,7 +1043,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
{
var propValue = this.getRowPropertyValue(row);
- var type = typeof(propValue);
+ var type = typeof propValue;
if (type == "undefined" || type == "number" || type == "boolean")
editValue = propValue;
else if (type == "string")
@@ -1051,17 +1068,14 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
}
else
{
- var object = getRowOwnerObject(row);
- if (!object)
- object = this.selection;
- object = this.getObjectView(object);
+ var member = row.domObject;
+ var object = this.getObjectView(member.object);
- if (object)
+ if (member.deletable)
{
- var name = getRowName(row);
try
{
- delete object[name];
+ delete object[member.name];
}
catch (exc)
{
@@ -1076,13 +1090,15 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
setPropertyValue: function(row, value) // value must be string
{
+ var member = row.domObject;
+ var name = member.name;
+
if (FBTrace.DBG_DOM)
{
- FBTrace.sysout("row: " + row);
- FBTrace.sysout("value: " + value + " type " + typeof(value), value);
+ FBTrace.sysout("setPropertyValue: " + name + " set to " +
+ (typeof value === "string" ? "\"" + value + "\"" : "non-string!?!?"), row);
}
- var name = getRowName(row);
if (name == "this")
return;
@@ -1094,8 +1110,8 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
{
if (FBTrace.DBG_DOM)
{
- FBTrace.sysout("setPropertyValue evaluate success object[" + name + "]=" +
- result + " type " + typeof(result), result);
+ FBTrace.sysout("setPropertyValue evaluate success object[" + name + "]" +
+ " set to type " + typeof result, result);
}
object[name] = result;
},
@@ -1105,19 +1121,15 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
{
if (FBTrace.DBG_DOM)
{
- FBTrace.sysout("setPropertyValue evaluate failed with exc:" + exc +
- " object[" + name + "]=" + value + " type " + typeof(value), exc);
+ FBTrace.sysout("setPropertyValue evaluate FAILED", exc);
}
// If the value doesn't parse, then just store it as a string.
// Some users will not realize they're supposed to enter a JavaScript
// expression and just type literal text
- object[name] = String(value); // unwrappedJSobject.property = string
- }
- catch (exc)
- {
- return;
+ object[name] = value;
}
+ catch (exc) {}
}
);
}
@@ -1132,7 +1144,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
try
{
// See catch block above...
- object[name] = String(value); // unwrappedJSobject.property = string
+ object[name] = value;
}
catch (exc)
{
@@ -1161,10 +1173,6 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
if (!member.breakable)
return;
- //xxxHonza: don't use getRowName to get the prop name. From some reason
- // unwatch doesn't work if row.firstChild.textContent is used.
- // It works only from within the watch handler method if the passed param
- // name is used.
var name = member.name;
if (name == "this")
return;
@@ -1345,7 +1353,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
if (object == null)
return 1000;
- if (typeof(object) == "undefined")
+ if (typeof object == "undefined")
return 1000;
else if (object instanceof SourceLink.SourceLink)
return 0;
@@ -1361,7 +1369,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
updateSelection: function(object)
{
if (FBTrace.DBG_DOM)
- FBTrace.sysout("dom.updateSelection; object=" + object, object);
+ FBTrace.sysout("dom.updateSelection", object);
var previousIndex = this.pathIndex;
var previousView = previousIndex == -1 ? null : this.viewPath[previousIndex];
@@ -1445,7 +1453,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
}
this.panelNode.scrollTop = 0;
- this.rebuild();
+ this.rebuild(false);
}
else
{
@@ -1460,7 +1468,6 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
this.rebuild(false, view ? view.scrollTop : 0);
}
-
},
getObjectPath: function(object)
@@ -1527,12 +1534,12 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
var items = [];
- if (row)
+ if (row && row.domObject)
{
- var rowName = getRowName(row);
- var rowObject = this.getRowObject(row);
- var rowValue = this.getRowPropertyValue(row);
var member = row.domObject;
+ var rowName = member.name;
+ var rowObject = member.object;
+ var rowValue = member.value;
var isWatch = Css.hasClass(row, "watchRow");
var isStackFrame = rowObject instanceof StackFrame.StackFrame;
@@ -1552,7 +1559,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
}
);
- if (typeof(rowValue) == "string" || typeof(rowValue) == "number")
+ if (typeof rowValue == "string" || typeof rowValue == "number")
{
// Functions already have a copy item in their context menu
items.push(
@@ -1580,7 +1587,7 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
tooltiptext = "dom.tip.Edit_Property";
}
- var readOnly = (!isWatch && !isStackFrame && member && member.readOnly);
+ var readOnly = (!isWatch && !isStackFrame && member.readOnly);
if (!readOnly)
{
items.push(
@@ -1593,7 +1600,8 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
);
}
- if (isWatch || (!isStackFrame && !Dom.isDOMMember(rowObject, rowName)))
+ if (isWatch ||
+ (member.deletable && !isStackFrame && !Dom.isDOMMember(rowObject, rowName)))
{
items.push(
{
@@ -1853,7 +1861,7 @@ function isPrototype(name)
return (name == "prototype" || name == "__proto__");
}
-function isReadOnly(object, propName)
+function getPropertyDescriptor(object, propName)
{
try
{
@@ -1862,14 +1870,14 @@ function isReadOnly(object, propName)
{
desc = Object.getOwnPropertyDescriptor(object, propName);
if (desc)
- break;
+ return desc;
object = Object.getPrototypeOf(object);
}
- return (desc && !desc.writable && !desc.set);
}
catch (e)
{
}
+ return undefined;
}
function getRowName(row)
@@ -1893,24 +1901,26 @@ function getRowOwnerObject(row)
function getParentRow(row)
{
- var level = parseInt(row.getAttribute("level"))-1;
- // If it's top level object the level is now set to -1, is that a problem?
+ var level = "" + (parseInt(row.getAttribute("level"), 10) - 1);
+ if (level == "-1")
+ return;
for (row = row.previousSibling; row; row = row.previousSibling)
{
- if (parseInt(row.getAttribute("level")) == level)
+ if (row.getAttribute("level") === level)
return row;
}
}
+// Return an array of JS parts that build up (and uniquely identify) a row
function getPath(row)
{
var name = getRowName(row);
var path = [name];
- var level = parseInt(row.getAttribute("level"))-1;
- for (row = row.previousSibling; row; row = row.previousSibling)
+ var level = parseInt(row.getAttribute("level"), 10) - 1;
+ for (row = row.previousSibling; row && level >= 0; row = row.previousSibling)
{
- if (parseInt(row.getAttribute("level")) == level)
+ if (parseInt(row.getAttribute("level"), 10) === level)
{
var name = getRowName(row);
path.splice(0, 0, name);
diff --git a/extension/content/firebug/editor/editor.js b/extension/content/firebug/editor/editor.js
index 9e08249..05f36a6 100644
--- a/extension/content/firebug/editor/editor.js
+++ b/extension/content/firebug/editor/editor.js
@@ -669,7 +669,7 @@ Firebug.InlineEditor.prototype = domplate(Firebug.BaseEditor,
panel.panelNode.appendChild(this.box);
this.input.select();
- if (selectionData) //transfer selection to input element
+ if (selectionData) // transfer selection to input element
this.setSelection(selectionData);
// Insert the "expander" to cover the target element with white space
diff --git a/extension/content/firebug/js/watchPanel.js b/extension/content/firebug/js/watchPanel.js
index b9d0a2a..8b74c21 100644
--- a/extension/content/firebug/js/watchPanel.js
+++ b/extension/content/firebug/js/watchPanel.js
@@ -132,6 +132,7 @@ Firebug.WatchPanel.prototype = Obj.extend(Firebug.DOMBasePanel.prototype,
var members = [];
+ var context = this.context;
if (this.watches)
{
for (var i = 0; i < this.watches.length; ++i)
@@ -139,7 +140,7 @@ Firebug.WatchPanel.prototype = Obj.extend(Firebug.DOMBasePanel.prototype,
var expr = this.watches[i];
var value = null;
- Firebug.CommandLine.evaluate(expr, this.context, null, this.context.getGlobalScope(),
+ Firebug.CommandLine.evaluate(expr, context, null, context.getGlobalScope(),
function success(result, context)
{
value = result;
@@ -151,10 +152,10 @@ Firebug.WatchPanel.prototype = Obj.extend(Firebug.DOMBasePanel.prototype,
}
);
- this.addMember(scopes[0], "watch", members, expr, value, 0);
+ this.addMember(scopes[0], "watch", members, expr, value, 0, 0, context);
if (FBTrace.DBG_DOM)
- FBTrace.sysout("watch.updateSelection " + expr + " = " + value,
+ FBTrace.sysout("watch.updateSelection \"" + expr + "\"",
{expr: expr, value: value, members: members})
}
}
@@ -163,16 +164,16 @@ Firebug.WatchPanel.prototype = Obj.extend(Firebug.DOMBasePanel.prototype,
{
var thisVar = frame.getThisValue();
if (thisVar)
- this.addMember(scopes[0], "user", members, "this", thisVar, 0);
+ this.addMember(scopes[0], "user", members, "this", thisVar, 0, 0, context);
// locals, pre-expanded
- members.push.apply(members, this.getMembers(scopes[0], 0, this.context));
+ members.push.apply(members, this.getMembers(scopes[0], 0, context));
for (var i=1; i<scopes.length; i++)
- this.addMember(scopes[i], "scopes", members, scopes[i].toString(), scopes[i], 0);
+ this.addMember(scopes[i], "scopes", members, scopes[i].toString(), scopes[i], 0, 0, context);
}
- this.expandMembers(members, this.toggles, 0, 0, this.context);
+ this.expandMembers(members, this.toggles, 0, 0, context);
this.showMembers(members, false);
if (FBTrace.DBG_STACK)
diff --git a/extension/content/firebug/lib/domplate.js b/extension/content/firebug/lib/domplate.js
index c2ba7f3..d85e321 100644
--- a/extension/content/firebug/lib/domplate.js
+++ b/extension/content/firebug/lib/domplate.js
@@ -157,7 +157,7 @@ DomplateTag.prototype =
}
else
{
- if (name == "class" && this.attrs.hasOwnProperty(name) )
+ if (name == "class" && this.attrs.hasOwnProperty(name))
this.attrs[name] += " " + val;
else
this.attrs[name] = val;
@@ -336,12 +336,12 @@ DomplateTag.prototype =
readPartNames(this.props[name], topOuts);
}
- if ( this.attrs.hasOwnProperty("class") || this.classes)
+ if (this.attrs.hasOwnProperty("class") || this.classes)
{
topBlock.push(', " class=\\""');
if (this.attrs.hasOwnProperty("class"))
addParts(this.attrs["class"], ',', topBlock, info, true);
- topBlock.push(', " "');
+ topBlock.push(', " "');
for (var name in this.classes)
{
topBlock.push(', (');
@@ -976,8 +976,8 @@ function creator(tag, cons)
{
var fn = function()
{
- var tag = arguments.callee.tag;
- var cons = arguments.callee.cons;
+ var tag = fn.tag;
+ var cons = fn.cons;
var newTag = new cons();
return newTag.merge(arguments, tag);
}
diff --git a/extension/content/firebug/lib/lib.js b/extension/content/firebug/lib/lib.js
index 26be09c..e6550d6 100644
--- a/extension/content/firebug/lib/lib.js
+++ b/extension/content/firebug/lib/lib.js
@@ -122,11 +122,6 @@ for (var p in Firefox)
FBL.deprecated = Deprecated.deprecated;
FBL.SourceLink = SourceLink.SourceLink;
-//FBL.ErrorCopy = FirebugReps.ErrorCopy;
-//FBL.ErrorMessageObj = FirebugReps.ErrorMessageObj;
-//FBL.EventCopy = Dom.EventCopy;
-//FBL.PropertyObj = FirebugReps.PropertyObj;
-
// deprecated
FBL.$ = function(id, doc)
{
@@ -164,4 +159,4 @@ FBL.reUpperCase = /[A-Z]/;
return FBL;
// ********************************************************************************************* //
-});
\ No newline at end of file
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firebug.git
More information about the Pkg-mozext-commits
mailing list