Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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
Owner

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.

  • 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
Owner

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 4, 2012
  1. Steven Roussey

    Issue 5764: Change JSTerm's $ helper function from getElementById to …

    steve authored sroussey committed
    …querySelector
  2. Steven Roussey
  3. Steven Roussey
  4. Steven Roussey
  5. Steven Roussey
Commits on Aug 14, 2012
  1. Steven Roussey

    Merge branch 'master' into console-dollar

    sroussey authored
    Conflicts:
    	extension/content/firebug/chrome/reps.js
  2. Steven Roussey

    Use node constants

    sroussey authored
  3. Steven Roussey

    Use names in object-arrays

    sroussey authored
Commits on Sep 8, 2012
  1. Fix up the rest of console $ change

    steve authored
Commits on Sep 11, 2012
  1. Steven Roussey

    Merge branch 'master' into console-dollar

    sroussey authored
    Conflicts:
    	extension/content/firebug/chrome/reps.js
  2. Steven Roussey
Commits on Sep 12, 2012
  1. Steven Roussey
  2. Steven Roussey
This page is out of date. Refresh to see the latest.
184 extension/content/firebug/chrome/reps.js
View
@@ -514,33 +514,46 @@ FirebugReps.Reference = domplate(Firebug.Rep,
// ********************************************************************************************* //
-FirebugReps.Arr = domplate(Firebug.Rep,
+function mightBeArray(obj, win)
{
- 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"})
- ),
+ 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);
+ }
+ }
- 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"})
- ),
+ return true;
+}
+
+FirebugReps.ArrBase = domplate(Firebug.Rep,
+{
longArrayIterator: function(array)
{
@@ -699,61 +712,103 @@ FirebugReps.Arr = domplate(Firebug.Rep,
// Highlight multiple elements on the page.
Firebug.Inspector.highlightObject(arr, context);
},
+ titleTag:
+ SPAN({"class": "objectTitle"}, "$object|getTitleTag"),
+
+ getTitleTag: function(object, context)
+ {
+ return "[" + object.length + "]";
+ }
+});
+
+FirebugReps.Arr = domplate(FirebugReps.ArrBase,
+{
+ 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"})
+ ),
// http://code.google.com/p/fbug/issues/detail?id=874
- // BEGIN Yahoo BSD Source (modified here) YAHOO.lang.isArray, YUI 2.2.2 June 2007
isArray: function(obj, win)
{
- win = win || window;
+ if (mightBeArray(obj, win))
+ {
+ if (isFinite(obj.length) && typeof obj.callee === "function") // arguments
+ return true;
+ else if (Arr.isArray(obj))
+ return true;
+ }
+ return false;
+ }
+});
- var view = Wrapper.getContentView(win);
+FirebugReps.ArrayishObject = domplate(FirebugReps.ArrBase,
+{
+ tag:
+ OBJECTBOX({_repObject: "$object",
+ $hasTwisty: "$object|hasSpecialProperties",
+ onclick: "$onToggleProperties"},
+ SPAN({"class": "objectTitle"}, "$object|getTitle "),
+ 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"})
+ ),
- try
+ 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 (!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 (isFinite(obj.length) && typeof obj.callee === "function") // arguments
+ if (isFinite(obj.length) && typeof obj.splice === "function")
return true;
- else if (obj instanceof view.HTMLCollection)
+ var view = Wrapper.getContentView(win || window);
+ 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.
-
- getTitle: function(object, context)
- {
- return "[" + object.length + "]";
- }
});
+
// ********************************************************************************************* //
FirebugReps.Property = domplate(Firebug.Rep,
@@ -3146,6 +3201,7 @@ Firebug.registerRep(
FirebugReps.Except,
FirebugReps.XML,
FirebugReps.Arr,
+ FirebugReps.ArrayishObject,
FirebugReps.XPathResult,
FirebugReps.Storage,
FirebugReps.Attr,
35 extension/content/firebug/console/commandLine.js
View
@@ -1049,14 +1049,39 @@ Firebug.CommandLine.CommandHandler = Obj.extend(Object,
function FirebugCommandLineAPI(context)
{
- this.$ = function(id) // returns unwrapped elements from the page
- {
- return Wrapper.unwrapObject(context.baseWindow.document).getElementById(id);
+ this.$ = function(selector, start) // returns unwrapped elements from the page
+ {
+ var result;
+ if (start && start.querySelector && (
+ start.nodeType == Node.ELEMENT_NODE ||
+ start.nodeType == Node.DOCUMENT_NODE ||
+ start.nodeType == Node.DOCUMENT_FRAGMENT_NODE)) {
+ return start.querySelector(selector);
+ }
+
+ result = Wrapper.unwrapObject(context.baseWindow.document).querySelector(selector);
+ if (result == null && (selector||"")[0] !== "#")
+ {
+ result = Wrapper.unwrapObject(context.baseWindow.document).querySelector("#" + selector);
+ if (result != null)
+ {
+ // This should be removed in the next minor (non-bugfix) version
+ var msg = Locale.$STRF("warning.dollar_change", [selector]);
+ Firebug.Console.log(msg, context, "warn");
+ result = null;
+ }
+ }
+ return result;
};
- this.$$ = function(selector) // returns unwrapped elements from the page
+ this.$$ = function(selector, start) // returns unwrapped elements from the page
{
- var result = Wrapper.unwrapObject(context.baseWindow.document).querySelectorAll(selector);
+ var result;
+ if (start && start.querySelectorAll && (start.nodeType == Node.ELEMENT_NODE || start.nodeType == Node.DOCUMENT_NODE || start.nodeType == Node.DOCUMENT_FRAGMENT_NODE)) {
+ result = start.querySelectorAll(selector);
+ }
+ else
+ result = Wrapper.unwrapObject(context.baseWindow.document).querySelectorAll(selector);
return Arr.cloneArray(result);
};
1  extension/locale/en-US/firebug.properties
View
@@ -1367,6 +1367,7 @@ confirmation.Edit_CSS_Source=Your existing CSS edits will be discarded.\nAre you
# Console messages
warning.Console_must_be_enabled=Console must be enabled
warning.Command_line_blocked?=Command line blocked?
+warning.dollar_change=The console command line function $() has changed meaning from $=getElementById(id) to $=querySelector(selector). You might try $("#%S") instead.
message.Reload_to_activate_window_console=Reload to activate window console
# LOCALIZATION NOTE (message.sourceNotAvailableFor, message.The_resource_from_this_URL_is_not_text):
4 tests/content/commandLine/4391/issue4391.html
View
@@ -16,11 +16,11 @@
<ol>
<li>Open Firebug and enable the Console panel.</li>
-<li>Type following in to the command line: <code style="color:green">$("testElement")</code></li>
+<li>Type following in to the command line: <code style="color:green">$("#testElement")</code></li>
<li>Press Enter</li>
<li>The result should be:
<pre>
->>> $("testElement")
+>>> $("#testElement")
&ltdiv id="testElement"&gt
</pre>
<li>Load jQuery by clicking this button:
4 tests/content/commandLine/api/api.html
View
@@ -19,11 +19,11 @@
<i>'expression' -> 'result'</i>
</li>
<ol>
- <li><code>$("test1") -> &lt;div id="test1"&gt;</code></li>
+ <li><code>$("#test1") -> &lt;div id="test1"&gt;</code></li>
<li><code>$$(".a.c") -> [div.a, div.a]</code></li>
<li><code>$x("html/body/span/div[1]") -> [div.test]</code></li>
<li><code>dir(a) -> a: 10</code></li>
- <li><code>dirxml($('test3')) -> &lt;div id="test3"&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;</code></li>
+ <li><code>dirxml($('#test3')) -> &lt;div id="test3"&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;</code></li>
<li><code>keys(b) -> ["a", "name"]</code></li>
<li><code>values(b) -> [7, "a"]</code></li>
<li><code>table(a) -> Object Properties: 10 (tabular output)</code></li>
4 tests/content/commandLine/api/api.js
View
@@ -15,7 +15,7 @@ function runTest()
// parameters.
// \u00A0 == &nbsp; == #160 -> used by nodeTag domplate.
- tasks.push(executeAndVerify, "$(\"test1\")", "<div\u00A0id=\"test1\">",
+ tasks.push(executeAndVerify, "$(\"#test1\")", "<div\u00A0id=\"test1\">",
"a", "objectLink objectLink-element");
tasks.push(executeAndVerify, "$$(\".a.c\")", "[div.a, div.a]",
@@ -27,7 +27,7 @@ function runTest()
tasks.push(executeAndVerify, "dir(a)", /\s*a\s*10\s*/,
"table", "domTable");
- tasks.push(executeAndVerify, "dirxml($('test3'))",
+ tasks.push(executeAndVerify, "dirxml($('#test3'))",
"<div\u00A0id=\"test3\"><div></div></div>",
"div", "logRow logRow-dirxml");
2  tests/content/commandLine/api/cd.html
View
@@ -20,7 +20,7 @@
</li>
<ol>
<li><code>cd(frames[0]) -> "Current window:", Window cdFrame.html]</code></li>
- <li><code>$("test-iframe-1") -> &lt;div id="test-iframe-1"&gt;</code></li>
+ <li><code>$("#test-iframe-1") -> &lt;div id="test-iframe-1"&gt;</code></li>
<li><code>cd(top) -> ["Current window:", Window cd.html]</code></li>
</ol>
</ol>
2  tests/content/commandLine/api/cd.js
View
@@ -13,7 +13,7 @@ function runTest()
"[\"Current window:\", Window cdFrame.html]",
"pre", "objectBox objectBox-array");
- tasks.push(FBTest.executeCommandAndVerify, "$(\"test-iframe-1\")",
+ tasks.push(FBTest.executeCommandAndVerify, "$(\"#test-iframe-1\")",
/<div\s*id=\"test-iframe-1\">/,
"a", "objectLink objectLink-element");
4 tests/content/dom/attributes/attributes.js
View
@@ -19,11 +19,11 @@ function runTest()
tasks.push(testDomPanel);
tasks.push(executeCommandAndVerify,
- "$('testId').attributes", expectedValue,
+ "$('#testId').attributes", expectedValue,
"a", "objectLink objectLink-NamedNodeMap");
tasks.push(executeCommandAndVerify,
- "$('testId').attributes[0]",
+ "$('#testId').attributes[0]",
expectedValue2,
"a", "objectLink objectLink-Attr");
Something went wrong with that request. Please try again.