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 (c…

…ontributed by Steven Roussey)
  • Loading branch information...
commit 895fb77fa372eb3b1ca93635fda8f203cb4ca26f 1 parent 1121ebc
Jan Odvarko authored October 03, 2012

Showing 1 changed file with 204 additions and 60 deletions. Show diff stats Hide diff stats

  1. 264  extension/content/firebug/chrome/reps.js
264  extension/content/firebug/chrome/reps.js
@@ -513,34 +513,68 @@ FirebugReps.Reference = domplate(Firebug.Rep,
513 513
 });
514 514
 
515 515
 // ********************************************************************************************* //
  516
+// Array Helpers
516 517
 
517  
-FirebugReps.Arr = domplate(Firebug.Rep,
  518
+function mightBeArray(obj, win)
518 519
 {
519  
-    tag:
520  
-        OBJECTBOX({_repObject: "$object",
521  
-            $hasTwisty: "$object|hasSpecialProperties",
522  
-            onclick: "$onToggleProperties"},
523  
-            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
524  
-            FOR("item", "$object|longArrayIterator",
525  
-                TAG("$item.tag", {object: "$item.object"}),
526  
-                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
527  
-            ),
528  
-            SPAN({"class": "arrayRightBracket", role: "presentation"}, "]"),
529  
-            SPAN({"class": "arrayProperties", role: "group"})
530  
-        ),
  520
+    try
  521
+    {
  522
+        if (!obj)
  523
+            return false;
  524
+        // do this first to avoid security 1000 errors
  525
+        else if (obj instanceof Ci.nsIDOMHistory)
  526
+            return false;
531 527
 
532  
-    shortTag:
533  
-        OBJECTBOX({_repObject: "$object",
534  
-            $hasTwisty: "$object|hasSpecialProperties",
535  
-            onclick: "$onToggleProperties"},
536  
-            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
537  
-            FOR("item", "$object|shortArrayIterator",
538  
-                TAG("$item.tag", {object: "$item.object"}),
539  
-                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
540  
-            ),
541  
-            SPAN({"class": "arrayRightBracket"}, "]"),
542  
-            SPAN({"class": "arrayProperties", role: "group"})
543  
-        ),
  528
+        var view = Wrapper.getContentView(win || window);
  529
+
  530
+        // do this first to avoid security 1000 errors
  531
+        if ("StorageList" in view && obj instanceof view.StorageList)
  532
+            return false;
  533
+        // do this first to avoid exceptions
  534
+        else if (obj.toString() === "[xpconnect wrapped native prototype]")
  535
+            return false;
  536
+    }
  537
+    catch (exc)
  538
+    {
  539
+        try
  540
+        {
  541
+            if (FBTrace.DBG_ERRORS)
  542
+            {
  543
+                // Something weird: without the try/catch, OOM, with no exception??
  544
+                FBTrace.sysout("mightBeArray FAILS: " + exc, exc);
  545
+                FBTrace.sysout("mightBeArray Fails on obj " + obj);
  546
+            }
  547
+        }
  548
+        catch (exexc)
  549
+        {
  550
+            FBTrace.sysout("mightBeArray double ERROR " + exexc, exexc);
  551
+        }
  552
+    }
  553
+
  554
+    return true;
  555
+}
  556
+
  557
+// ********************************************************************************************* //
  558
+
  559
+FirebugReps.ArrBase = domplate(Firebug.Rep,
  560
+{
  561
+    className: "array",
  562
+    toggles: new ToggleBranch.ToggleBranch(),
  563
+
  564
+    titleTag:
  565
+        SPAN({"class": "objectTitle"}, "$object|getTitleTag"),
  566
+
  567
+    getTitle: function(object, context)
  568
+    {
  569
+        return "[" + object.length + "]";
  570
+    },
  571
+
  572
+    supportsObject: function(object, type, context)
  573
+    {
  574
+        return this.isArray(object, context ? context.window : null);
  575
+    },
  576
+
  577
+    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
544 578
 
545 579
     longArrayIterator: function(array)
546 580
     {
@@ -591,8 +625,6 @@ FirebugReps.Arr = domplate(Firebug.Rep,
591 625
         return items;
592 626
     },
593 627
 
594  
-    toggles: new ToggleBranch.ToggleBranch(),
595  
-
596 628
     getItemIndex: function(child)
597 629
     {
598 630
         var arrayIndex = 0;
@@ -667,13 +699,6 @@ FirebugReps.Arr = domplate(Firebug.Rep,
667 699
 
668 700
     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
669 701
 
670  
-    className: "array",
671  
-
672  
-    supportsObject: function(object, type, context)
673  
-    {
674  
-        return this.isArray(object, context ? context.window : null);
675  
-    },
676  
-
677 702
     highlightObject: function(object, context, target)
678 703
     {
679 704
         // Highlighting huge amount of elements on the page can cause serious performance
@@ -703,11 +728,7 @@ FirebugReps.Arr = domplate(Firebug.Rep,
703 728
     // http://code.google.com/p/fbug/issues/detail?id=874
704 729
     isArray: function(obj, win)
705 730
     {
706  
-        win = win || window;
707  
-
708  
-        var view = Wrapper.getContentView(win);
709  
-
710  
-        try
  731
+        if (mightBeArray(obj, win))
711 732
         {
712 733
             if (!obj)
713 734
                 return false;
@@ -719,37 +740,158 @@ FirebugReps.Arr = domplate(Firebug.Rep,
719 740
                 return false;
720 741
             else if (isFinite(obj.length) && typeof obj.splice === "function")
721 742
                 return true;
722  
-            else if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
  743
+            else if (Arr.isArray(obj))
  744
+                return true;
  745
+        }
  746
+
  747
+        return false;
  748
+    },
  749
+});
  750
+
  751
+// ********************************************************************************************* //
  752
+
  753
+FirebugReps.Arr = domplate(FirebugReps.ArrBase,
  754
+{
  755
+    tag:
  756
+        OBJECTBOX({_repObject: "$object",
  757
+            $hasTwisty: "$object|hasSpecialProperties",
  758
+            onclick: "$onToggleProperties"},
  759
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
  760
+            FOR("item", "$object|longArrayIterator",
  761
+                TAG("$item.tag", {object: "$item.object"}),
  762
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  763
+            ),
  764
+            SPAN({"class": "arrayRightBracket", role: "presentation"}, "]"),
  765
+            SPAN({"class": "arrayProperties", role: "group"})
  766
+        ),
  767
+
  768
+    shortTag:
  769
+        OBJECTBOX({_repObject: "$object",
  770
+            $hasTwisty: "$object|hasSpecialProperties",
  771
+            onclick: "$onToggleProperties"},
  772
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
  773
+            FOR("item", "$object|shortArrayIterator",
  774
+                TAG("$item.tag", {object: "$item.object"}),
  775
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  776
+            ),
  777
+            SPAN({"class": "arrayRightBracket"}, "]"),
  778
+            SPAN({"class": "arrayProperties", role: "group"})
  779
+        ),
  780
+
  781
+    // http://code.google.com/p/fbug/issues/detail?id=874
  782
+    isArray: function(obj, win)
  783
+    {
  784
+        if (mightBeArray(obj, win))
  785
+        {
  786
+            if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
  787
+                return true;
  788
+            else if (Arr.isArray(obj))
  789
+                return true;
  790
+        }
  791
+        return false;
  792
+    }
  793
+});
  794
+
  795
+// ********************************************************************************************* //
  796
+
  797
+FirebugReps.ArrayishObject = domplate(FirebugReps.ArrBase,
  798
+{
  799
+    tag:
  800
+        OBJECTBOX({_repObject: "$object",
  801
+            $hasTwisty: "$object|hasSpecialProperties",
  802
+            onclick: "$onToggleProperties"},
  803
+            SPAN({"class": "objectTitle"}, "$object|getTitle "),
  804
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
  805
+            FOR("item", "$object|longArrayIterator",
  806
+                TAG("$item.tag", {object: "$item.object"}),
  807
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  808
+            ),
  809
+            SPAN({"class": "arrayRightBracket", role: "presentation"}, "]"),
  810
+            SPAN({"class": "arrayProperties", role: "group"})
  811
+        ),
  812
+
  813
+    shortTag:
  814
+        OBJECTBOX({_repObject: "$object",
  815
+            $hasTwisty: "$object|hasSpecialProperties",
  816
+            onclick: "$onToggleProperties"},
  817
+            SPAN({"class": "objectTitle"}, "$object|getTitle "),
  818
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
  819
+            FOR("item", "$object|shortArrayIterator",
  820
+                TAG("$item.tag", {object: "$item.object"}),
  821
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  822
+            ),
  823
+            SPAN({"class": "arrayRightBracket"}, "]"),
  824
+            SPAN({"class": "arrayProperties", role: "group"})
  825
+        ),
  826
+
  827
+    getTitle: function(object, context)
  828
+    {
  829
+        const re =/\[object ([^\]]*)/;
  830
+        var label = Str.safeToString(object);
  831
+        var m = re.exec(label);
  832
+        return m[1] || label;
  833
+    },
  834
+
  835
+    isArray: function(obj, win)
  836
+    {
  837
+        if (mightBeArray(obj, win))
  838
+        {
  839
+            if (isFinite(obj.length) && typeof obj.splice === "function" && obj.length)
723 840
                 return true;
724  
-            else if (obj instanceof view.HTMLCollection)
  841
+            var view = Wrapper.getContentView(win || window);
  842
+            if (obj instanceof view.HTMLCollection)
725 843
                 return true;
726 844
             else if (obj instanceof view.NodeList)
727 845
                 return true;
728 846
         }
729  
-        catch (exc)
  847
+
  848
+        return false;
  849
+    },
  850
+});
  851
+
  852
+// ********************************************************************************************* //
  853
+
  854
+FirebugReps.NodeCollection = domplate(FirebugReps.Arr,
  855
+{
  856
+    tag:
  857
+        OBJECTBOX({_repObject: "$object",
  858
+            $hasTwisty: "$object|hasSpecialProperties",
  859
+            onclick: "$onToggleProperties"},
  860
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "<["),
  861
+            FOR("item", "$object|longArrayIterator",
  862
+                TAG("$item.tag", {object: "$item.object"}),
  863
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  864
+            ),
  865
+            SPAN({"class": "arrayRightBracket", role: "presentation"}, "]>"),
  866
+            SPAN({"class": "arrayProperties", role: "group"})
  867
+        ),
  868
+
  869
+    shortTag:
  870
+        OBJECTBOX({_repObject: "$object",
  871
+            $hasTwisty: "$object|hasSpecialProperties",
  872
+            onclick: "$onToggleProperties"},
  873
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "<["),
  874
+            FOR("item", "$object|shortArrayIterator",
  875
+                TAG("$item.tag", {object: "$item.object"}),
  876
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  877
+            ),
  878
+            SPAN({"class": "arrayRightBracket"}, "]>"),
  879
+            SPAN({"class": "arrayProperties", role: "group"})
  880
+        ),
  881
+
  882
+    isArray: function(obj, win)
  883
+    {
  884
+        if (mightBeArray(obj, win))
730 885
         {
731  
-            try
732  
-            {
733  
-                if (FBTrace.DBG_ERRORS)
734  
-                {
735  
-                    // Something weird: without the try/catch, OOM, with no exception??
736  
-                    FBTrace.sysout("isArray FAILS: " + exc, exc);
737  
-                    FBTrace.sysout("isArray Fails on obj " + obj);
738  
-                }
739  
-            }
740  
-            catch (exexc)
741  
-            {
742  
-                FBTrace.sysout("isArray double ERROR " + exexc, exexc);
743  
-            }
  886
+            var view = Wrapper.getContentView(win || window);
  887
+            if (obj instanceof view.HTMLCollection)
  888
+                return true;
  889
+            else if (obj instanceof view.NodeList)
  890
+                return true;
744 891
         }
745 892
 
746 893
         return false;
747 894
     },
748  
-    
749  
-    getTitle: function(object, context)
750  
-    {
751  
-        return "[" + object.length + "]";
752  
-    }
753 895
 });
754 896
 
755 897
 // ********************************************************************************************* //
@@ -3145,6 +3287,8 @@ Firebug.registerRep(
3145 3287
     FirebugReps.Except,
3146 3288
     FirebugReps.XML,
3147 3289
     FirebugReps.Arr,
  3290
+    FirebugReps.NodeCollection,
  3291
+    FirebugReps.ArrayishObject,
3148 3292
     FirebugReps.XPathResult,
3149 3293
     FirebugReps.Storage,
3150 3294
     FirebugReps.Attr,

0 notes on commit 895fb77

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