Closed
Bug 688400
Opened 13 years ago
Closed 12 years ago
Web Console throws a TypeError when trying to display objects with no toString method
Categories
(DevTools :: Console, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 23
People
(Reporter: bruant.d, Unassigned)
References
Details
In latest Nightly:
< Object.create(null)
> TypeError: aResult.toString is not a function
In this case, one could rather expect to see an empty object. Also, "aResult" doesn't refer to anything I have defined.
Reporter | ||
Updated•13 years ago
|
OS: Linux → All
Hardware: x86_64 → All
Version: unspecified → 9 Branch
Comment 1•12 years ago
|
||
we now get the somewhat more descriptive:
> TypeError: can't convert null to primitive type
I think this is OK.
Status: NEW → RESOLVED
Closed: 12 years ago
Component: Developer Tools → Developer Tools: Console
Resolution: --- → WORKSFORME
Reporter | ||
Comment 2•12 years ago
|
||
(In reply to Rob Campbell [:rc] (:robcee) from comment #1)
> we now get the somewhat more descriptive:
>
> > TypeError: can't convert null to primitive type
>
> I think this is OK.
This is not ok. Object.create(null) has no reason to throw an error at all!
Object.create(null) returns an object with null as its prototype, no error. See ECMAScript 5 15.2.3.5
Status: RESOLVED → REOPENED
Resolution: WORKSFORME → ---
Reporter | ||
Comment 3•12 years ago
|
||
I bet that the console.log implementation, when trying to display an object, does something like:
object.toString()
This cannot work for objects with null as [[Prototype]], because they don't have a toString method I guess (hence the TypeError)
What you need is probably to go for:
Object.prototype.toString.call(object)
If I'm wrong, please post a link to the console.log code I'll see where I think console.log is wrong.
Comment 4•12 years ago
|
||
This kind of bug is now easy to debug with the Browser Debugger. Make sure you have the following prefs set first:
devtools.debugger.remote-enabled: true
devtools.chrome.enabled: true
Now open the Browser Debugger from the Web Developer menu and toggle the 'Pause on exceptions' setting in the gear menu.
If you then follow the STR from comment 0, the debugger will pause in the exact spot where the TypeError is thrown.
Reporter | ||
Comment 5•12 years ago
|
||
(In reply to Panos Astithas [:past] from comment #4)
> This kind of bug is now easy to debug with the Browser Debugger.
HOLY COW! THIS IS SO AWESOME!
> If you then follow the STR from comment 0, the debugger will pause in the
> exact spot where the TypeError is thrown.
It doesn't seem easy to figure out the issue, but I'll investigate.
Thanks for the tip !
Comment 6•12 years ago
|
||
David: thanks for your bug report. As far as I know, the code tries a few tricks before giving up. The exception is displayed as a placeholder for something we can't display / can't convert to a string. I could just display null, but that would be the same as displaying null - which would cause confusion.
I agree the TypeError exception is far from ideal. We could go for <cannot convert to to string> or <no string> or just [object Object]. Ideas are welcome.
Reporter | ||
Comment 7•12 years ago
|
||
(In reply to Mihai Sucan [:msucan] from comment #6)
> I agree the TypeError exception is far from ideal. We could go for <cannot
> convert to to string> or <no string> or just [object Object]. Ideas are
> welcome.
Object.create(null) is an object, so "{}" would be the most relevant thing to print or at least, the same thing than console.log({}) (which prints [object Object]).
Likewise,
var o = Object.create(null); o.a = 1; console.log(o)
should logs the same than
console.log({a:1});
In both case, a clickable {a:1} is fine.
Unfortunately, the console currently doesn't help to distinguish the [[Prototype]]. One idea would be that in the object popup, a link could open a popup for the prototype. I'm filing another bug for this.
Comment 8•12 years ago
|
||
(In reply to David Bruant from comment #7)
> Unfortunately, the console currently doesn't help to distinguish the
> [[Prototype]]. One idea would be that in the object popup, a link could open
> a popup for the prototype. I'm filing another bug for this.
Bug 794823 will fix that.
Comment 9•12 years ago
|
||
(In reply to Panos Astithas [:past] from comment #8)
> (In reply to David Bruant from comment #7)
> > Unfortunately, the console currently doesn't help to distinguish the
> > [[Prototype]]. One idea would be that in the object popup, a link could open
> > a popup for the prototype. I'm filing another bug for this.
>
> Bug 794823 will fix that.
Actually, the followup bug 808370 is the one to follow.
Reporter | ||
Comment 12•12 years ago
|
||
Fixed indeed after Bug 783499.
Thanks :-)
Status: REOPENED → RESOLVED
Closed: 12 years ago → 12 years ago
Resolution: --- → FIXED
Updated•12 years ago
|
Target Milestone: --- → Firefox 23
Updated•6 years ago
|
Product: Firefox → DevTools
You need to log in
before you can comment on or make changes to this bug.
Description
•