Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Console dollar #37

Closed
wants to merge 13 commits into from

2 participants

Steven Roussey Sebastian Zartner
Steven Roussey
Owner

This covers issues 5764, 5779, 5786

Sebastian Zartner
Collaborator

Three points:

  • $() doesn't seem to work for me as expected (try $(".class1") on Joe's test case)
  • Better use constants instead of magic numbers.
  • Add a comment that the warning should be removed in a future version

Sebastian

Owner
  • Wow, that is an old page of Joe's! It also loads prototype.js on the page, so Firebug will use that version of $, of course. I deal with more PrototypeJS stuff than jQuery stuff, believe it or not. So, yeah, this is a problem with the two JS libs defining incompatible versions, and our switching around. This is an example of the bogus bug reports you will get. ;)

  • Yeah, I will change if we decide to keep this functionality (or before)

  • Yes, one release later I think, we should pull the warning. I'll comment it up.

Collaborator
  • Wow, that is an old page of Joe's!

Yes. Though I use it a lot for reproducing issues.

It also loads prototype.js on the page, so Firebug will use that version of $

Oh my! I totally forgot about that! Sorry, Steven! So I tested it on other sites and it's working as expected.

This is an example of the bogus bug reports you will get. ;)

Right. I wonder why we don't get this kind of reports more often already...

  • Yeah, I will change if we decide to keep this functionality (or before)

  • Yes, one release later I think, we should pull the warning. I'll comment it up.

Good.

Sebastian

Sebastian Zartner
Collaborator

The changes for issue 5786 are unrelated. Why did you put them in there?

Sebastian

Steven Roussey
Owner

Sorry, didn't have all the commits pushed to the repo

Steven Roussey sroussey closed this September 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
184  extension/content/firebug/chrome/reps.js
@@ -514,33 +514,46 @@ FirebugReps.Reference = domplate(Firebug.Rep,
514 514
 
515 515
 // ********************************************************************************************* //
516 516
 
517  
-FirebugReps.Arr = domplate(Firebug.Rep,
  517
+function mightBeArray(obj, win)
518 518
 {
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  
-        ),
  519
+    try
  520
+    {
  521
+        if (!obj)
  522
+            return false;
  523
+        // do this first to avoid security 1000 errors
  524
+        else if (obj instanceof Ci.nsIDOMHistory)
  525
+            return false;
  526
+        
  527
+        var view = Wrapper.getContentView(win || window);
  528
+        // do this first to avoid security 1000 errors
  529
+        if ("StorageList" in view && obj instanceof view.StorageList)
  530
+            return false;
  531
+        // do this first to avoid exceptions
  532
+        else if (obj.toString() === "[xpconnect wrapped native prototype]")
  533
+            return false;
  534
+    }
  535
+    catch (exc)
  536
+    {
  537
+        try
  538
+        {
  539
+            if (FBTrace.DBG_ERRORS)
  540
+            {
  541
+                // Something weird: without the try/catch, OOM, with no exception??
  542
+                FBTrace.sysout("mightBeArray FAILS: " + exc, exc);
  543
+                FBTrace.sysout("mightBeArray Fails on obj " + obj);
  544
+            }
  545
+        }
  546
+        catch (exexc)
  547
+        {
  548
+            FBTrace.sysout("mightBeArray double ERROR " + exexc, exexc);
  549
+        }
  550
+    }
531 551
 
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  
-        ),
  552
+    return true;
  553
+}
  554
+
  555
+FirebugReps.ArrBase = domplate(Firebug.Rep,
  556
+{
544 557
 
545 558
     longArrayIterator: function(array)
546 559
     {
@@ -699,61 +712,103 @@ FirebugReps.Arr = domplate(Firebug.Rep,
699 712
         // Highlight multiple elements on the page.
700 713
         Firebug.Inspector.highlightObject(arr, context);
701 714
     },
  715
+    titleTag:
  716
+        SPAN({"class": "objectTitle"}, "$object|getTitleTag"),
  717
+
  718
+    getTitleTag: function(object, context)
  719
+    {
  720
+        return "[" + object.length + "]";
  721
+    } 
  722
+});
  723
+    
  724
+FirebugReps.Arr = domplate(FirebugReps.ArrBase,
  725
+{
  726
+    tag:
  727
+        OBJECTBOX({_repObject: "$object",
  728
+            $hasTwisty: "$object|hasSpecialProperties",
  729
+            onclick: "$onToggleProperties"},
  730
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
  731
+            FOR("item", "$object|longArrayIterator",
  732
+                TAG("$item.tag", {object: "$item.object"}),
  733
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  734
+            ),
  735
+            SPAN({"class": "arrayRightBracket", role: "presentation"}, "]"),
  736
+            SPAN({"class": "arrayProperties", role: "group"})
  737
+        ),
  738
+
  739
+    shortTag:
  740
+        OBJECTBOX({_repObject: "$object",
  741
+            $hasTwisty: "$object|hasSpecialProperties",
  742
+            onclick: "$onToggleProperties"},
  743
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
  744
+            FOR("item", "$object|shortArrayIterator",
  745
+                TAG("$item.tag", {object: "$item.object"}),
  746
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  747
+            ),
  748
+            SPAN({"class": "arrayRightBracket"}, "]"),
  749
+            SPAN({"class": "arrayProperties", role: "group"})
  750
+        ),
702 751
 
703 752
     // http://code.google.com/p/fbug/issues/detail?id=874
704  
-    // BEGIN Yahoo BSD Source (modified here)  YAHOO.lang.isArray, YUI 2.2.2 June 2007
705 753
     isArray: function(obj, win)
706 754
     {
707  
-        win = win || window;
  755
+        if (mightBeArray(obj, win))
  756
+        {
  757
+            if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
  758
+                return true;
  759
+            else if (Arr.isArray(obj))
  760
+                return true;
  761
+        }
  762
+        return false;
  763
+    }
  764
+});
708 765
 
709  
-        var view = Wrapper.getContentView(win);
  766
+FirebugReps.ArrayishObject = domplate(FirebugReps.ArrBase,
  767
+{
  768
+    tag:
  769
+        OBJECTBOX({_repObject: "$object",
  770
+            $hasTwisty: "$object|hasSpecialProperties",
  771
+            onclick: "$onToggleProperties"},
  772
+            SPAN({"class": "objectTitle"}, "$object|getTitle "),
  773
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
  774
+            FOR("item", "$object|longArrayIterator",
  775
+                TAG("$item.tag", {object: "$item.object"}),
  776
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  777
+            ),
  778
+            SPAN({"class": "arrayRightBracket", role: "presentation"}, "]"),
  779
+            SPAN({"class": "arrayProperties", role: "group"})
  780
+        ),
710 781
 
711  
-        try
  782
+    shortTag:
  783
+        OBJECTBOX({_repObject: "$object",
  784
+            $hasTwisty: "$object|hasSpecialProperties",
  785
+            onclick: "$onToggleProperties"},
  786
+            SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["),
  787
+            FOR("item", "$object|shortArrayIterator",
  788
+                TAG("$item.tag", {object: "$item.object"}),
  789
+                SPAN({"class": "arrayComma", role: "presentation"}, "$item.delim")
  790
+            ),
  791
+            SPAN({"class": "arrayRightBracket"}, "]"),
  792
+            SPAN({"class": "arrayProperties", role: "group"})
  793
+        ),
  794
+    
  795
+    isArray: function(obj, win)
  796
+    {
  797
+        if (mightBeArray(obj, win))
712 798
         {
713  
-            if (!obj)
714  
-                return false;
715  
-            // do this first to avoid security 1000 errors
716  
-            else if (obj instanceof Ci.nsIDOMHistory)
717  
-                return false;
718  
-            // do this first to avoid exceptions
719  
-            else if (obj.toString && obj.toString() === "[xpconnect wrapped native prototype]")
720  
-                return false;
721  
-            else if (isFinite(obj.length) && typeof obj.splice === "function")
722  
-                return true;
723  
-            else if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
  799
+            if (isFinite(obj.length) && typeof obj.splice === "function")
724 800
                 return true;
725  
-            else if (obj instanceof view.HTMLCollection)
  801
+            var view = Wrapper.getContentView(win || window);
  802
+            if (obj instanceof view.HTMLCollection)
726 803
                 return true;
727 804
             else if (obj instanceof view.NodeList)
728 805
                 return true;
729 806
         }
730  
-        catch (exc)
731  
-        {
732  
-            try
733  
-            {
734  
-                if (FBTrace.DBG_ERRORS)
735  
-                {
736  
-                    // Something weird: without the try/catch, OOM, with no exception??
737  
-                    FBTrace.sysout("isArray FAILS: " + exc, exc);
738  
-                    FBTrace.sysout("isArray Fails on obj " + obj);
739  
-                }
740  
-            }
741  
-            catch (exexc)
742  
-            {
743  
-                FBTrace.sysout("isArray double ERROR " + exexc, exexc);
744  
-            }
745  
-        }
746  
-
747 807
         return false;
748 808
     },
749  
-    // END Yahoo BSD SOURCE See license below.
750  
-
751  
-    getTitle: function(object, context)
752  
-    {
753  
-        return "[" + object.length + "]";
754  
-    }
755 809
 });
756 810
 
  811
+
757 812
 // ********************************************************************************************* //
758 813
 
759 814
 FirebugReps.Property = domplate(Firebug.Rep,
@@ -3146,6 +3201,7 @@ Firebug.registerRep(
3146 3201
     FirebugReps.Except,
3147 3202
     FirebugReps.XML,
3148 3203
     FirebugReps.Arr,
  3204
+    FirebugReps.ArrayishObject,
3149 3205
     FirebugReps.XPathResult,
3150 3206
     FirebugReps.Storage,
3151 3207
     FirebugReps.Attr,
35  extension/content/firebug/console/commandLine.js
@@ -1049,14 +1049,39 @@ Firebug.CommandLine.CommandHandler = Obj.extend(Object,
1049 1049
 
1050 1050
 function FirebugCommandLineAPI(context)
1051 1051
 {
1052  
-    this.$ = function(id)  // returns unwrapped elements from the page
1053  
-    {
1054  
-        return Wrapper.unwrapObject(context.baseWindow.document).getElementById(id);
  1052
+    this.$ = function(selector, start)  // returns unwrapped elements from the page
  1053
+    {
  1054
+        var result;
  1055
+        if (start && start.querySelector && (
  1056
+                start.nodeType == Node.ELEMENT_NODE ||
  1057
+                start.nodeType == Node.DOCUMENT_NODE ||
  1058
+                start.nodeType == Node.DOCUMENT_FRAGMENT_NODE)) {
  1059
+            return start.querySelector(selector);
  1060
+        }
  1061
+        
  1062
+        result = Wrapper.unwrapObject(context.baseWindow.document).querySelector(selector);
  1063
+        if (result == null && (selector||"")[0] !== "#")
  1064
+        {
  1065
+            result = Wrapper.unwrapObject(context.baseWindow.document).querySelector("#" + selector);
  1066
+            if (result != null)
  1067
+            {
  1068
+                // This should be removed in the next minor (non-bugfix) version
  1069
+                var msg = Locale.$STRF("warning.dollar_change", [selector]);
  1070
+                Firebug.Console.log(msg, context, "warn");
  1071
+                result = null;
  1072
+            }
  1073
+        }
  1074
+        return result;
1055 1075
     };
1056 1076
 
1057  
-    this.$$ = function(selector) // returns unwrapped elements from the page
  1077
+    this.$$ = function(selector, start) // returns unwrapped elements from the page
1058 1078
     {
1059  
-        var result = Wrapper.unwrapObject(context.baseWindow.document).querySelectorAll(selector);
  1079
+        var result;
  1080
+        if (start && start.querySelectorAll && (start.nodeType == Node.ELEMENT_NODE || start.nodeType == Node.DOCUMENT_NODE || start.nodeType == Node.DOCUMENT_FRAGMENT_NODE)) {
  1081
+            result = start.querySelectorAll(selector);
  1082
+        }
  1083
+        else
  1084
+            result = Wrapper.unwrapObject(context.baseWindow.document).querySelectorAll(selector);
1060 1085
         return Arr.cloneArray(result);
1061 1086
     };
1062 1087
 
1  extension/locale/en-US/firebug.properties
@@ -1367,6 +1367,7 @@ confirmation.Edit_CSS_Source=Your existing CSS edits will be discarded.\nAre you
1367 1367
 # Console messages
1368 1368
 warning.Console_must_be_enabled=Console must be enabled
1369 1369
 warning.Command_line_blocked?=Command line blocked?
  1370
+warning.dollar_change=The console command line function $() has changed meaning from $=getElementById(id) to $=querySelector(selector). You might try $("#%S") instead.
1370 1371
 message.Reload_to_activate_window_console=Reload to activate window console
1371 1372
 
1372 1373
 # LOCALIZATION NOTE (message.sourceNotAvailableFor, message.The_resource_from_this_URL_is_not_text):
4  tests/content/commandLine/4391/issue4391.html
@@ -16,11 +16,11 @@
16 16
 
17 17
 <ol>
18 18
 <li>Open Firebug and enable the Console panel.</li>
19  
-<li>Type following in to the command line: <code style="color:green">$("testElement")</code></li>
  19
+<li>Type following in to the command line: <code style="color:green">$("#testElement")</code></li>
20 20
 <li>Press Enter</li>
21 21
 <li>The result should be:
22 22
 <pre>
23  
->>> $("testElement")
  23
+>>> $("#testElement")
24 24
 &ltdiv id="testElement"&gt
25 25
 </pre>
26 26
 <li>Load jQuery by clicking this button:
4  tests/content/commandLine/api/api.html
@@ -19,11 +19,11 @@
19 19
     <i>'expression' -> 'result'</i>
20 20
 </li>
21 21
 <ol>
22  
-    <li><code>$("test1") -> &lt;div id="test1"&gt;</code></li>
  22
+    <li><code>$("#test1") -> &lt;div id="test1"&gt;</code></li>
23 23
     <li><code>$$(".a.c") -> [div.a, div.a]</code></li>
24 24
     <li><code>$x("html/body/span/div[1]") -> [div.test]</code></li>
25 25
     <li><code>dir(a) -> a: 10</code></li>
26  
-    <li><code>dirxml($('test3')) -> &lt;div id="test3"&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;</code></li>
  26
+    <li><code>dirxml($('#test3')) -> &lt;div id="test3"&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;</code></li>
27 27
     <li><code>keys(b) -> ["a", "name"]</code></li>
28 28
     <li><code>values(b) -> [7, "a"]</code></li>
29 29
     <li><code>table(a) -> Object Properties: 10 (tabular output)</code></li>
4  tests/content/commandLine/api/api.js
@@ -15,7 +15,7 @@ function runTest()
15 15
             // parameters.
16 16
 
17 17
             // \u00A0 == &nbsp; == #160 -> used by nodeTag domplate.
18  
-            tasks.push(executeAndVerify, "$(\"test1\")", "<div\u00A0id=\"test1\">",
  18
+            tasks.push(executeAndVerify, "$(\"#test1\")", "<div\u00A0id=\"test1\">",
19 19
                 "a", "objectLink objectLink-element");
20 20
 
21 21
             tasks.push(executeAndVerify, "$$(\".a.c\")", "[div.a, div.a]",
@@ -27,7 +27,7 @@ function runTest()
27 27
             tasks.push(executeAndVerify, "dir(a)", /\s*a\s*10\s*/,
28 28
                 "table", "domTable");
29 29
 
30  
-            tasks.push(executeAndVerify, "dirxml($('test3'))",
  30
+            tasks.push(executeAndVerify, "dirxml($('#test3'))",
31 31
                 "<div\u00A0id=\"test3\"><div></div></div>",
32 32
                 "div", "logRow logRow-dirxml");
33 33
 
2  tests/content/commandLine/api/cd.html
@@ -20,7 +20,7 @@
20 20
 </li>
21 21
 <ol>
22 22
     <li><code>cd(frames[0]) -> "Current window:", Window cdFrame.html]</code></li>
23  
-    <li><code>$("test-iframe-1") -> &lt;div id="test-iframe-1"&gt;</code></li>
  23
+    <li><code>$("#test-iframe-1") -> &lt;div id="test-iframe-1"&gt;</code></li>
24 24
     <li><code>cd(top) -> ["Current window:", Window cd.html]</code></li>
25 25
 </ol>
26 26
 </ol>
2  tests/content/commandLine/api/cd.js
@@ -13,7 +13,7 @@ function runTest()
13 13
                 "[\"Current window:\", Window cdFrame.html]",
14 14
                 "pre", "objectBox objectBox-array");
15 15
 
16  
-            tasks.push(FBTest.executeCommandAndVerify, "$(\"test-iframe-1\")",
  16
+            tasks.push(FBTest.executeCommandAndVerify, "$(\"#test-iframe-1\")",
17 17
                 /<div\s*id=\"test-iframe-1\">/,
18 18
                 "a", "objectLink objectLink-element");
19 19
 
4  tests/content/dom/attributes/attributes.js
@@ -19,11 +19,11 @@ function runTest()
19 19
             tasks.push(testDomPanel);
20 20
 
21 21
             tasks.push(executeCommandAndVerify,
22  
-                "$('testId').attributes", expectedValue,
  22
+                "$('#testId').attributes", expectedValue,
23 23
                 "a", "objectLink objectLink-NamedNodeMap");
24 24
 
25 25
             tasks.push(executeCommandAndVerify,
26  
-                "$('testId').attributes[0]",
  26
+                "$('#testId').attributes[0]",
27 27
                 expectedValue2,
28 28
                 "a", "objectLink objectLink-Attr");
29 29
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.