Skip to content

Commit

Permalink
Issue 5786: Show array-like objects differently than actual arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sroussey committed Aug 4, 2012
1 parent 1b98712 commit ca56207
Showing 1 changed file with 125 additions and 39 deletions.
164 changes: 125 additions & 39 deletions extension/content/firebug/chrome/reps.js
Expand Up @@ -509,6 +509,44 @@ FirebugReps.Reference = domplate(Firebug.Rep,

// ********************************************************************************************* //

function mightBeArray(obj, win)
{
try
{
if (!obj)
return false;
// do this first to avoid security 1000 errors
else if (obj instanceof Ci.nsIDOMHistory)
return false;

var view = Wrapper.getContentView(win || window);
// do this first to avoid security 1000 errors
if ("StorageList" in view && obj instanceof view.StorageList)
return false;
// do this first to avoid exceptions
else if (obj.toString() === "[xpconnect wrapped native prototype]")
return false;
}
catch (exc)
{
try
{
if (FBTrace.DBG_ERRORS)
{
// Something weird: without the try/catch, OOM, with no exception??
FBTrace.sysout("mightBeArray FAILS: " + exc, exc);
FBTrace.sysout("mightBeArray Fails on obj " + obj);
}
}
catch (exexc)
{
FBTrace.sysout("mightBeArray double ERROR " + exexc, exexc);
}
}

return true;
}

FirebugReps.Arr = domplate(Firebug.Rep,
{
tag:
Expand Down Expand Up @@ -699,49 +737,13 @@ FirebugReps.Arr = domplate(Firebug.Rep,
// BEGIN Yahoo BSD Source (modified here) YAHOO.lang.isArray, YUI 2.2.2 June 2007
isArray: function(obj, win)
{
win = win || window;

var view = Wrapper.getContentView(win);

try
if (mightBeArray(obj, win))
{
if (!obj)
return false;
// do this first to avoid security 1000 errors
else if (obj instanceof Ci.nsIDOMHistory)
return false;
// do this first to avoid security 1000 errors
else if ("StorageList" in view && obj instanceof view.StorageList)
return false;
// do this first to avoid exceptions
else if (obj.toString() === "[xpconnect wrapped native prototype]")
return false;
else if (isFinite(obj.length) && typeof obj.splice === "function")
if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
return true;
else if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
else if (Arr.isArray(obj))
return true;
else if (obj instanceof view.HTMLCollection)
return true;
else if (obj instanceof view.NodeList)
return true;
}
catch (exc)
{
try
{
if (FBTrace.DBG_ERRORS)
{
// Something weird: without the try/catch, OOM, with no exception??
FBTrace.sysout("isArray FAILS: " + exc, exc);
FBTrace.sysout("isArray Fails on obj " + obj);
}
}
catch (exexc)
{
FBTrace.sysout("isArray double ERROR " + exexc, exexc);
}
}

return false;
},
// END Yahoo BSD SOURCE See license below.
Expand All @@ -752,6 +754,88 @@ FirebugReps.Arr = domplate(Firebug.Rep,
}
});

FirebugReps.ArrayishObject = domplate(FirebugReps.Arr,
{
tag:
OBJECTBOX({_repObject: "$object",
$hasTwisty: "$object|hasSpecialProperties",
onclick: "$onToggleProperties"},
SPAN({"class": "arrayLeftBracket", role: "presentation"}, "{["),
FOR("item", "$object|longArrayIterator",
TAG("$item.tag", {object: "$item.object"}),
SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
),
SPAN({"class": "arrayRightBracket", role: "presentation"}, "]}"),
SPAN({"class": "arrayProperties", role: "group"})
),

shortTag:
OBJECTBOX({_repObject: "$object",
$hasTwisty: "$object|hasSpecialProperties",
onclick: "$onToggleProperties"},
SPAN({"class": "arrayLeftBracket", role: "presentation"}, "{["),
FOR("item", "$object|shortArrayIterator",
TAG("$item.tag", {object: "$item.object"}),
SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
),
SPAN({"class": "arrayRightBracket"}, "]}"),
SPAN({"class": "arrayProperties", role: "group"})
),

isArray: function(obj, win)
{
if (mightBeArray(obj, win))
{
if (isFinite(obj.length) && typeof obj.splice === "function")
return true;
}
return false;
},
});

FirebugReps.NodeCollection = domplate(FirebugReps.Arr,
{
tag:
OBJECTBOX({_repObject: "$object",
$hasTwisty: "$object|hasSpecialProperties",
onclick: "$onToggleProperties"},
SPAN({"class": "arrayLeftBracket", role: "presentation"}, "<["),
FOR("item", "$object|longArrayIterator",
TAG("$item.tag", {object: "$item.object"}),
SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
),
SPAN({"class": "arrayRightBracket", role: "presentation"}, "]>"),
SPAN({"class": "arrayProperties", role: "group"})
),

shortTag:
OBJECTBOX({_repObject: "$object",
$hasTwisty: "$object|hasSpecialProperties",
onclick: "$onToggleProperties"},
SPAN({"class": "arrayLeftBracket", role: "presentation"}, "<["),
FOR("item", "$object|shortArrayIterator",
TAG("$item.tag", {object: "$item.object"}),
SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
),
SPAN({"class": "arrayRightBracket"}, "]>"),
SPAN({"class": "arrayProperties", role: "group"})
),

isArray: function(obj, win)
{
if (mightBeArray(obj, win))
{
var view = Wrapper.getContentView(win || window);
if (obj instanceof view.HTMLCollection)
return true;
else if (obj instanceof view.NodeList)
return true;
}
return false;
},
});


// ********************************************************************************************* //

FirebugReps.Property = domplate(Firebug.Rep,
Expand Down Expand Up @@ -3205,6 +3289,8 @@ Firebug.registerRep(
FirebugReps.Except,
FirebugReps.XML,
FirebugReps.Arr,
FirebugReps.NodeCollection,
FirebugReps.ArrayishObject,
FirebugReps.XPathResult,
FirebugReps.Storage,
FirebugReps.StorageList,
Expand Down

0 comments on commit ca56207

Please sign in to comment.