Bug 30962 - Use Object#toString to render object name in console and object tree
Summary: Use Object#toString to render object name in console and object tree
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2009-10-30 13:43 PDT by Dan Dean
Modified: 2015-02-18 01:37 PST (History)
13 users (show)

See Also:


Attachments
Image of usefulness of toString in the ExtJS framework (73 bytes, text/plain)
2010-04-15 18:55 PDT, Steven Roussey
no flags Details
Image of usefulness of toString in the ExtJS framework (35.91 KB, image/jpeg)
2010-04-15 18:57 PDT, Steven Roussey
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Dean 2009-10-30 13:43:37 PDT
I find it very useful that Firebug uses the toString method of an object to render the identifier of an object in all JS object inspections. I would love to see this bit of functionality in the WebKit Web Inspector.

Example:

console.log({
    toString: function() {
        return "[object MyAwesomeObject]";
    }
});

Firebug Console:
--> MyAwesomeObject

WebKit Console:
--> Object
Comment 1 Timothy Hatcher 2009-10-30 21:04:04 PDT
We could do this. Right now we avoid it since some default toString methods are less than desirable (string, array to name a couple.)
Comment 2 Dan Dean 2009-11-03 09:47:09 PST
(In reply to comment #1)
> We could do this. Right now we avoid it since some default toString methods are
> less than desirable (string, array to name a couple.)

I agree with you on the native types. I think the current behavior should remain for String, Array, Number, Boolean and RegExp objects. Probably a couple others too, like HTMLElement...

This functionality is very useful for custom objects, though I understand how the implementation could be rather complex.
Comment 3 Timothy Hatcher 2009-12-04 13:03:03 PST
I agree we should do this for custom object.
Comment 4 Timothy Hatcher 2009-12-04 13:03:38 PST
<rdar://problem/7444878>
Comment 5 Steven Roussey 2010-04-15 18:55:06 PDT
Created attachment 53502 [details]
Image of usefulness of toString in the ExtJS framework

Reference: http://www.extjs.com/forum/showthread.php?97007-ExtJS-debugging-help-in-Firebug
Comment 6 Steven Roussey 2010-04-15 18:57:07 PDT
Created attachment 53503 [details]
Image of usefulness of toString in the ExtJS framework

Reference: http://www.extjs.com/forum/showthread.php?97007-ExtJS-debugging-help-in-Firebug
Comment 7 Joseph Pecoraro 2015-02-18 01:37:09 PST
So we've made some improvements here. We don't parse toString's, but we do deeper analysis of object's constructor properties / native type information.

We recently improved our handling here:

  js> function Foo() {}; new Foo // Always handled this
  Foo {}

  js> Bar = function() {}; new Bar // Just made this work
  Bar {}

As for letting scripts provide a name. If we end up with "Object" given the analysis above, then we fallback to "obj.constructor.name" if it is available. A rather crude example:

  js> console.log({constructor:{name:"test"}})
  test {}

--

That said, neither Firebug nor FireFox's developer tools seem to do this anymore. I think they have likely moved to constructor.name or better inference as well.