Skip to content

Commit

Permalink
Issue 6106: Highlighting everything in a pseudo-array doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlindholm committed Nov 30, 2012
1 parent 8f428a2 commit b3d3f96
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 139 deletions.
147 changes: 16 additions & 131 deletions extension/content/firebug/chrome/reps.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,48 +523,6 @@ FirebugReps.Reference = domplate(Firebug.Rep,
},
});

// ********************************************************************************************* //
// Array Helpers

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.ArrBase = domplate(FirebugReps.Obj,
Expand All @@ -580,9 +538,9 @@ FirebugReps.ArrBase = domplate(FirebugReps.Obj,
return "[" + object.length + "]";
},

supportsObject: function(object, type, context)
supportsObject: function(object, type)
{
return this.isArray(object, context ? context.window : null);
return this.isArray(object);
},

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Expand Down Expand Up @@ -736,27 +694,10 @@ FirebugReps.ArrBase = domplate(FirebugReps.Obj,
Firebug.Inspector.highlightObject(arr, context);
},

// http://code.google.com/p/fbug/issues/detail?id=874
isArray: function(obj, win)
isArray: function(obj)
{
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 exceptions
else if (obj.toString && obj.toString() === "[xpconnect wrapped native prototype]")
return false;
else if (isFinite(obj.length) && typeof obj.splice === "function")
return true;
else if (Arr.isArray(obj))
return true;
}

return false;
},
}
});

// ********************************************************************************************* //
Expand Down Expand Up @@ -790,15 +731,16 @@ FirebugReps.Arr = domplate(FirebugReps.ArrBase,
),

// http://code.google.com/p/fbug/issues/detail?id=874
isArray: function(obj, win)
isArray: function(obj)
{
if (mightBeArray(obj, win))
try
{
if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
if (Arr.isArray(obj))
return true;
else if (Arr.isArray(obj))
else if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
return true;
}
catch (exc) {}
return false;
}
});
Expand Down Expand Up @@ -863,25 +805,10 @@ FirebugReps.ArrayLikeObject = domplate(FirebugReps.ArrBase,
return "";
},

isArray: function(obj, win)
isArray: function(obj)
{
if (mightBeArray(obj, win))
{
var view = Wrapper.getContentView(win || window);
var arr = Wrapper.unwrapObject(obj);

if (isFinite(obj.length) && typeof obj.splice === "function" && obj.length)
return true;
else if (arr instanceof view.HTMLCollection)
return true;
else if (arr instanceof view.NodeList)
return true;
else if (arr instanceof Ci.nsIDOMDOMTokenList)
return true;
}

return false;
},
return Arr.isArrayLike(obj);
}
});

// ********************************************************************************************* //
Expand Down Expand Up @@ -1479,7 +1406,6 @@ FirebugReps.TextNode = domplate(Firebug.Rep,

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

var regexpConstructorRE = /RegExp/;
FirebugReps.RegExp = domplate(Firebug.Rep,
{
tag:
Expand All @@ -1495,8 +1421,7 @@ FirebugReps.RegExp = domplate(Firebug.Rep,
{
try
{
return type == "object" && object && object.constructor && object.constructor.toString &&
regexpConstructorRE.test(object.constructor.toString());
return type == "object" && Object.prototype.toString.call(object) === "[object RegExp]";
}
catch (err)
{
Expand Down Expand Up @@ -3359,14 +3284,14 @@ FirebugReps.ErrorCopy = function(message)
// Registration

Firebug.registerRep(
FirebugReps.nsIDOMHistory, // make this early to avoid exceptions
FirebugReps.Undefined,
FirebugReps.Null,
FirebugReps.Number,
FirebugReps.RegExp,
FirebugReps.String,
FirebugReps.nsIDOMHistory, // make this early to avoid exceptions
FirebugReps.ApplicationCache, // this also
FirebugReps.RegExp,
FirebugReps.Window,
FirebugReps.ApplicationCache, // must come before Arr (array) else exceptions.
FirebugReps.ErrorMessage,
FirebugReps.Element,
FirebugReps.TextNode,
Expand Down Expand Up @@ -3399,43 +3324,3 @@ return Firebug.Reps = FirebugReps;

// ********************************************************************************************* //
}});

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

/*
* The following is http://developer.yahoo.com/yui/license.txt and applies to only code labeled
* "Yahoo BSD Source" in only this file reps.js. John J. Barton June 2007.
*
Software License Agreement (BSD License)
Copyright (c) 2006, Yahoo! Inc.
All rights reserved.
Redistribution and use of this software in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of Yahoo! Inc. nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// ********************************************************************************************* //
7 changes: 4 additions & 3 deletions extension/content/firebug/html/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ define([
"firebug/lib/locale",
"firebug/lib/events",
"firebug/lib/wrapper",
"firebug/lib/array",
"firebug/lib/css",
"firebug/lib/dom",
"firebug/lib/xml",
"firebug/chrome/window",
"firebug/lib/system",
"firebug/html/highlighterCache"
],
function(Obj, Firebug, Firefox, FirebugReps, Locale, Events, Wrapper, Css, Dom, Xml,
function(Obj, Firebug, Firefox, FirebugReps, Locale, Events, Wrapper, Arr, Css, Dom, Xml,
Win, System, HighlighterCache) {

// ********************************************************************************************* //
Expand Down Expand Up @@ -71,7 +72,7 @@ Firebug.Inspector = Obj.extend(Firebug.Module,
var i, elt, elementLen, oldContext, usingColorArray;
var highlighter = highlightType ? getHighlighter(highlightType) : this.defaultHighlighter;

if (!elementArr || !FirebugReps.Arr.isArray(elementArr, context.window))
if (!elementArr || !Arr.isArrayLike(elementArr))
{
// highlight a single element
if (!elementArr || !Dom.isElement(elementArr) ||
Expand Down Expand Up @@ -139,7 +140,7 @@ Firebug.Inspector = Obj.extend(Firebug.Module,
}

this.clearAllHighlights();
usingColorArray = FirebugReps.Arr.isArray(colorObj, context.window);
usingColorArray = Arr.isArray(colorObj);

if (context && context.window && context.window.document)
{
Expand Down
33 changes: 28 additions & 5 deletions extension/content/firebug/lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,41 @@ function(FBTrace) {
// ********************************************************************************************* //
// Constants

const Ci = Components.interfaces;
var Arr = {};

// ********************************************************************************************* //
// Arrays

Arr.isArray = function(obj)
Arr.isArray = Array.isArray || function(obj)
{
if (Array.isArray)
return Array.isArray(obj);

return Object.prototype.toString.call(obj) === "[object Array]";
}
};

Arr.isArrayLike = function(obj)
{
try
{
if (typeof obj !== "object")
return false;
if (!isFinite(obj.length))
return false;
if (Arr.isArray(obj))
return true;
if (typeof obj.callee === "function") // arguments
return true;
if (typeof obj.splice === "function") // jQuery etc.
return true;
if (obj instanceof Ci.nsIDOMHTMLCollection)
return true;
if (obj instanceof Ci.nsIDOMNodeList)
return true;
if (obj instanceof Ci.nsIDOMDOMTokenList)
return true;
}
catch (exc) {}
return false;
};

// At least sometimes the keys will be on user-level window objects
Arr.keys = function(map)
Expand Down

0 comments on commit b3d3f96

Please sign in to comment.