Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Issue 5786: Show array-like objects differently than actual arrays

  • Loading branch information...
commit ca56207b8cc1084ad4cdb184f257b39444a6b86d 1 parent 1b98712
Steven Roussey authored August 04, 2012

Showing 1 changed file with 125 additions and 39 deletions. Show diff stats Hide diff stats

  1. 164  extension/content/firebug/chrome/reps.js
164  extension/content/firebug/chrome/reps.js
@@ -509,6 +509,44 @@ FirebugReps.Reference = domplate(Firebug.Rep,
509 509
 
510 510
 // ********************************************************************************************* //
511 511
 
  512
+function mightBeArray(obj, win)
  513
+{
  514
+    try
  515
+    {
  516
+        if (!obj)
  517
+            return false;
  518
+        // do this first to avoid security 1000 errors
  519
+        else if (obj instanceof Ci.nsIDOMHistory)
  520
+            return false;
  521
+        
  522
+        var view = Wrapper.getContentView(win || window);
  523
+        // do this first to avoid security 1000 errors
  524
+        if ("StorageList" in view && obj instanceof view.StorageList)
  525
+            return false;
  526
+        // do this first to avoid exceptions
  527
+        else if (obj.toString() === "[xpconnect wrapped native prototype]")
  528
+            return false;
  529
+    }
  530
+    catch (exc)
  531
+    {
  532
+        try
  533
+        {
  534
+            if (FBTrace.DBG_ERRORS)
  535
+            {
  536
+                // Something weird: without the try/catch, OOM, with no exception??
  537
+                FBTrace.sysout("mightBeArray FAILS: " + exc, exc);
  538
+                FBTrace.sysout("mightBeArray Fails on obj " + obj);
  539
+            }
  540
+        }
  541
+        catch (exexc)
  542
+        {
  543
+            FBTrace.sysout("mightBeArray double ERROR " + exexc, exexc);
  544
+        }
  545
+    }
  546
+
  547
+    return true;
  548
+}
  549
+
512 550
 FirebugReps.Arr = domplate(Firebug.Rep,
513 551
 {
514 552
     tag:
@@ -699,49 +737,13 @@ FirebugReps.Arr = domplate(Firebug.Rep,
699 737
     // BEGIN Yahoo BSD Source (modified here)  YAHOO.lang.isArray, YUI 2.2.2 June 2007
700 738
     isArray: function(obj, win)
701 739
     {
702  
-        win = win || window;
703  
-
704  
-        var view = Wrapper.getContentView(win);
705  
-
706  
-        try
  740
+        if (mightBeArray(obj, win))
707 741
         {
708  
-            if (!obj)
709  
-                return false;
710  
-            // do this first to avoid security 1000 errors
711  
-            else if (obj instanceof Ci.nsIDOMHistory)
712  
-                return false;
713  
-            // do this first to avoid security 1000 errors
714  
-            else if ("StorageList" in view && obj instanceof view.StorageList)
715  
-                return false;
716  
-            // do this first to avoid exceptions
717  
-            else if (obj.toString() === "[xpconnect wrapped native prototype]")
718  
-                return false;
719  
-            else if (isFinite(obj.length) && typeof obj.splice === "function")
  742
+            if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
720 743
                 return true;
721  
-            else if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
  744
+            else if (Arr.isArray(obj))
722 745
                 return true;
723  
-            else if (obj instanceof view.HTMLCollection)
724  
-                return true;
725  
-            else if (obj instanceof view.NodeList)
726  
-                return true;
727  
-        }
728  
-        catch (exc)
729  
-        {
730  
-            try
731  
-            {
732  
-                if (FBTrace.DBG_ERRORS)
733  
-                {
734  
-                    // Something weird: without the try/catch, OOM, with no exception??
735  
-                    FBTrace.sysout("isArray FAILS: " + exc, exc);
736  
-                    FBTrace.sysout("isArray Fails on obj " + obj);
737  
-                }
738  
-            }
739  
-            catch (exexc)
740  
-            {
741  
-                FBTrace.sysout("isArray double ERROR " + exexc, exexc);
742  
-            }
743 746
         }
744  
-
745 747
         return false;
746 748
     },
747 749
     // END Yahoo BSD SOURCE See license below.
@@ -752,6 +754,88 @@ FirebugReps.Arr = domplate(Firebug.Rep,
752 754
     }
753 755
 });
754 756
 
  757
+FirebugReps.ArrayishObject = domplate(FirebugReps.Arr,
  758
+{
  759
+    tag:
  760
+        OBJECTBOX({_repObject: "$object",
  761
+            $hasTwisty: "$object|hasSpecialProperties",
  762
+            onclick: "$onToggleProperties"},
  763
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "{["),
  764
+            FOR("item", "$object|longArrayIterator",
  765
+                TAG("$item.tag", {object: "$item.object"}),
  766
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  767
+            ),
  768
+            SPAN({"class": "arrayRightBracket", role: "presentation"}, "]}"),
  769
+            SPAN({"class": "arrayProperties", role: "group"})
  770
+        ),
  771
+
  772
+    shortTag:
  773
+        OBJECTBOX({_repObject: "$object",
  774
+            $hasTwisty: "$object|hasSpecialProperties",
  775
+            onclick: "$onToggleProperties"},
  776
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "{["),
  777
+            FOR("item", "$object|shortArrayIterator",
  778
+                TAG("$item.tag", {object: "$item.object"}),
  779
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  780
+            ),
  781
+            SPAN({"class": "arrayRightBracket"}, "]}"),
  782
+            SPAN({"class": "arrayProperties", role: "group"})
  783
+        ),
  784
+    
  785
+    isArray: function(obj, win)
  786
+    {
  787
+        if (mightBeArray(obj, win))
  788
+        {
  789
+            if (isFinite(obj.length) && typeof obj.splice === "function")
  790
+                return true;
  791
+        }
  792
+        return false;
  793
+    },
  794
+});
  795
+
  796
+FirebugReps.NodeCollection = domplate(FirebugReps.Arr,
  797
+{
  798
+    tag:
  799
+        OBJECTBOX({_repObject: "$object",
  800
+            $hasTwisty: "$object|hasSpecialProperties",
  801
+            onclick: "$onToggleProperties"},
  802
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "<["),
  803
+            FOR("item", "$object|longArrayIterator",
  804
+                TAG("$item.tag", {object: "$item.object"}),
  805
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  806
+            ),
  807
+            SPAN({"class": "arrayRightBracket", role: "presentation"}, "]>"),
  808
+            SPAN({"class": "arrayProperties", role: "group"})
  809
+        ),
  810
+
  811
+    shortTag:
  812
+        OBJECTBOX({_repObject: "$object",
  813
+            $hasTwisty: "$object|hasSpecialProperties",
  814
+            onclick: "$onToggleProperties"},
  815
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "<["),
  816
+            FOR("item", "$object|shortArrayIterator",
  817
+                TAG("$item.tag", {object: "$item.object"}),
  818
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  819
+            ),
  820
+            SPAN({"class": "arrayRightBracket"}, "]>"),
  821
+            SPAN({"class": "arrayProperties", role: "group"})
  822
+        ),
  823
+    
  824
+    isArray: function(obj, win)
  825
+    {
  826
+        if (mightBeArray(obj, win))
  827
+        {
  828
+            var view = Wrapper.getContentView(win || window);
  829
+            if (obj instanceof view.HTMLCollection)
  830
+                return true;
  831
+            else if (obj instanceof view.NodeList)
  832
+                return true;
  833
+        }
  834
+        return false;
  835
+    },
  836
+});
  837
+
  838
+        
755 839
 // ********************************************************************************************* //
756 840
 
757 841
 FirebugReps.Property = domplate(Firebug.Rep,
@@ -3205,6 +3289,8 @@ Firebug.registerRep(
3205 3289
     FirebugReps.Except,
3206 3290
     FirebugReps.XML,
3207 3291
     FirebugReps.Arr,
  3292
+    FirebugReps.NodeCollection,
  3293
+    FirebugReps.ArrayishObject,
3208 3294
     FirebugReps.XPathResult,
3209 3295
     FirebugReps.Storage,
3210 3296
     FirebugReps.StorageList,

0 notes on commit ca56207

Please sign in to comment.
Something went wrong with that request. Please try again.