Last Comment Bug 575522 - ES5 {}.toString applies ToObject so {} throws TypeError
: ES5 {}.toString applies ToObject so {} throws TypeError
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
P1 normal (vote)
: mozilla2.0
Assigned To: Jim Blandy :jimb
: Jason Orendorff [:jorendorff]
Depends on: 575535
Blocks: es5
  Show dependency treegraph
Reported: 2010-06-28 23:57 PDT by Brendan Eich [:brendan]
Modified: 2010-10-14 22:44 PDT (History)
14 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Description User image Brendan Eich [:brendan] 2010-06-28 23:57:31 PDT
This is breaking jQuery, which contains

        isFunction: function (obj) {
            return === "[object Function]";

Talking about what to do on led to the proposal from Mark Miller that ES5 be changed by erratum (in time for ISO, barely) to specify "[object undefined]" for |this| bound to undefined, and "[object null]" for |this| bound to null. This smells better than retreating to "[object Window]" or whatever the global class calls itself.

I propose trying this out in Firefox 4 beta 2 in order to see if we can get away with it.

I hope Microsoft can try Mark's proposal out in an IE9 Developer Preview, as well. More test coverage, more eyeballs.

Comment 1 User image Dão Gottwald [:dao] 2010-07-17 02:03:01 PDT
First comment on <>:
I'm unsure why you are going to return [Object undefined] while the type of the 'undefined' value is 'Undefined', as stated in the ES5 spec. Same goes for 'null' whose type is 'Null'. To be consistant, you should return "[Object Undefined]" and "[Object Null]", or is there any reason why you should not ?
Comment 2 User image Mark S. Miller 2010-07-17 13:38:27 PDT
Question in comment 1 above raised on es5-discuss list at
Comment 3 User image Brendan Eich [:brendan] 2010-07-17 15:04:22 PDT
Dão, probably a nit, just for the record: in no case would "object" in "[object ...]" be capitalized.

The other class names either correspond to constructors, whose names are consistently capitalized, or to internal [[Class]] values such as "Arguments". In the latter case you can't extract the name from and construct a program that new's it, so there's no consistent requirement that the name spell any existing property name.

But "null" and "undefined" do name reserved identifiers or (now in ES5) constant bindings. So "Null" and "Undefined" are a bit cleaner and more consistent. Thanks for bringing this up.

Comment 4 User image Brendan Eich [:brendan] 2010-08-31 17:16:30 PDT
Need to get this fixed before release.

Comment 5 User image Brendan Eich [:brendan] 2010-10-04 09:28:19 PDT
Patch 4 in bug 514570 fixes this, right?

Comment 6 User image Jim Blandy :jimb 2010-10-04 11:28:10 PDT
Seems so:

js> ({})
"[object Undefined]"
Comment 7 User image Brendan Eich [:brendan] 2010-10-04 14:32:30 PDT
Nice. With test coverage in that bug, this one could even be dup'ed IMHO.


Note You need to log in before you can comment on or make changes to this bug.