Closed
Bug 618344
Opened 14 years ago
Closed 14 years ago
Web Console pprint() command should display something useful for functions
Categories
(DevTools :: General, defect, P2)
DevTools
General
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 4.0b9
People
(Reporter: bj, Assigned: msucan)
References
Details
(Whiteboard: [Web-Console-Testday])
Attachments
(1 file, 1 obsolete file)
(deleted),
patch
|
Gavin
:
approval2.0+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13 ( .NET CLR 3.5.30729; .NET4.0C)
Build Identifier: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13 ( .NET CLR 3.5.30729; .NET4.0C)
The Web Console pprint() command is supposed to format values, but when given a function it just displays blank lines.
Reproducible: Always
Steps to Reproduce:
1. Open the Web Console.
2. Type "pprint<enter>".
3. Type "pprint(pprint)<enter>".
Actual Results:
The "pprint" displays the code of JSTH_pprint, but the "pprint(pprint)" just displays blank lines.
Expected Results:
The "pprint(pprint)" command should display at least as much as the "pprint" command.
Reporter | ||
Comment 1•14 years ago
|
||
The actual build id is:
Mozilla/5.0 (X11; Linux x86_64; rv:2.0b8pre) Gecko/20101209 Firefox/4.0b8pre ID:20101209030340
Whiteboard: [Web-Console-Testday]
Version: unspecified → Trunk
Updated•14 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
Updated•14 years ago
|
Assignee | ||
Comment 2•14 years ago
|
||
If you type "pprint<enter>" it's actually the output of the normal Web Console code which takes the input string, evaluates it (the result in this case is a function, the pprint function itself). The result is then displayed in the console output, as best as possible - that's function .toSource(). The pprint() function itself is not executed.
When you type "pprint(pprint)" you are again going through evaluation, but this time the pprint() function is executed, with the given argument (the pprint function itself). The pprint function tries to iterate the given argument, as an object, to output the properties the object has. The pprint() function itself has no properties, hence you see no output.
I believe the result is expected. This is not a bug.
If we'd hack the pprint() function to do toSource() when the argument is a function, then we'd no longer follow the initial purpose of the pprint() function.
Kevin: thoughts?
Comment 3•14 years ago
|
||
(In reply to comment #2)
> If we'd hack the pprint() function to do toSource() when the argument is a
> function, then we'd no longer follow the initial purpose of the pprint()
> function.
There is noting wrong with that - just check to see if the function has any properties before using toSource()
Comment 4•14 years ago
|
||
Stepping back a bit, the original problem here is just that
pprint(someFunction)
prints a blank line, followed by the usual "undefined"
it's that blank line that's the problem. it should display *something* there.
Ultimately, pprint may be unnecessary. Firebug just uses console.log() and pretty prints objects and arrays and such automatically. That seems like a better approach.
Comment 5•14 years ago
|
||
To be clear: for this bug, we could simply display the function source.
If this is a trivial change, it may get into Firefox 4, otherwise this is likely for the next release.
Assignee | ||
Comment 6•14 years ago
|
||
I tend to agree with Kevin. Bug 598357 made improvements to how we pretty print objects and the likes. We could keep pprint as it is, or remove it (we have the properties inspector panel).
Another possibility: instead of printing a blank line, we could say "no properties in the object". However, we have string freeze - so we can't do this.
Nonetheless, it is a trivial change. Will submit a patch which does toSource() for functions in pprint() - tomorrow.
Assignee | ||
Updated•14 years ago
|
Status: NEW → ASSIGNED
OS: Linux → All
Hardware: x86_64 → All
Whiteboard: [Web-Console-Testday] → [patchclean:1217][Web-Console-Testday]
Updated•14 years ago
|
Attachment #498320 -
Flags: feedback?(rcampbell) → feedback+
Assignee | ||
Comment 8•14 years ago
|
||
Comment on attachment 498320 [details] [diff] [review]
proposed fix
Thanks Rob for the f+!
Asking for review from Shawn.
Attachment #498320 -
Flags: review?(sdwilsh)
Comment 9•14 years ago
|
||
Comment on attachment 498320 [details] [diff] [review]
proposed fix
>+++ b/toolkit/components/console/hudservice/HUDService.jsm
>+ else if (typeof aObject === "function") {
magic string! I'd like you to pull this out into a constant please (TYPEOF_FUNCTION maybe?).
>+++ b/toolkit/components/console/hudservice/tests/browser/browser_webconsole_jsterm.js
> * Contributor(s):
> * David Dahl <ddahl@mozilla.com>
> * Julian Viereck <jviereck@mozilla.com>
> * Patrick Walton <pcwalton@mozilla.com>
> * Rob Campbell <rcampbell@mozilla.com>
>+ * Mihai Èucan <mihai.sucan@gmail.com>
note that the boilerplate asks for the names to be lined up with the "n" not the "o"
>+ // check that pprint(function) shows function source, bug 618344
>+ jsterm.clearOutput();
>+ jsterm.execute("pprint(print)");
>+ label = jsterm.outputNode.querySelector(".jsterm-output-line");
>+ isnot(label.textContent.indexOf("JSTH_print"), -1,
>+ "pprint(function) shows function source");
This doesn't look it's actually checking that the function source is being printed. It should check that the output is, in fact, correct.
r=sdwilsh with that fixed.
Attachment #498320 -
Flags: review?(sdwilsh) → review+
Assignee | ||
Comment 10•14 years ago
|
||
Updated the patch as requested. Thanks for the review+!
Asking for approval2.0+.
Attachment #498320 -
Attachment is obsolete: true
Attachment #500199 -
Flags: approval2.0?
Comment 11•14 years ago
|
||
Comment on attachment 500199 [details] [diff] [review]
updated patch
I prefer the "magic string" over having to look up what TYPEOF_FUNCTION is defined as elsewhere in the file; typeof return values are fairly well known, so there isn't really any "magic". But I suppose it doesn't matter too much either way.
Attachment #500199 -
Flags: approval2.0? → approval2.0+
Assignee | ||
Updated•14 years ago
|
Whiteboard: [patchclean:1217][Web-Console-Testday] → [patchclean:1229][Web-Console-Testday][checkin]
Comment 12•14 years ago
|
||
(In reply to comment #11)
> Comment on attachment 500199 [details] [diff] [review]
> updated patch
>
> I prefer the "magic string" over having to look up what TYPEOF_FUNCTION is
> defined as elsewhere in the file; typeof return values are fairly well known,
> so there isn't really any "magic". But I suppose it doesn't matter too much
> either way.
ditto. I think that qualifies as an Übernit.
Comment 13•14 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Whiteboard: [patchclean:1229][Web-Console-Testday][checkin] → [Web-Console-Testday]
Target Milestone: --- → Firefox 4.0b9
Updated•6 years ago
|
Product: Firefox → DevTools
You need to log in
before you can comment on or make changes to this bug.
Description
•