Note: There are a few cases of duplicates in user autocompletion which are being worked on.

ES5 {}.toString applies ToObject so {}.toString.call(undefined) throws TypeError

RESOLVED FIXED in mozilla2.0

Status

()

Core
JavaScript Engine
P1
normal
RESOLVED FIXED
7 years ago
7 years ago

People

(Reporter: brendan, Assigned: jimb)

Tracking

Trunk
mozilla2.0
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(blocking2.0 betaN+)

Details

(Reporter)

Description

7 years ago
This is breaking jQuery, which contains

        isFunction: function (obj) {
            return toString.call(obj) === "[object Function]";
        },

Talking about what to do on es5-discuss@mozilla.org 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.

/be
(Reporter)

Updated

7 years ago
Depends on: 575535
Target Milestone: mozilla1.9.3 → mozilla2.0
First comment on <http://blogs.msdn.com/b/ie/archive/2010/07/16/how-ie9-platform-preview-feedback-changed-the-javascript-standard.aspx>:
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

7 years ago
Question in comment 1 above raised on es5-discuss list at https://mail.mozilla.org/pipermail/es5-discuss/2010-July/003647.html
(Reporter)

Comment 3

7 years ago
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 Object.prototype.toString.call 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.

/be
(Reporter)

Comment 4

7 years ago
Need to get this fixed before release.

/be
blocking2.0: --- → ?

Updated

7 years ago
Assignee: brendan → jim
blocking2.0: ? → betaN+
(Reporter)

Comment 5

7 years ago
Patch 4 in bug 514570 fixes this, right?

/be
(Assignee)

Comment 6

7 years ago
Seems so:

js> ({}).toString.call(undefined)
"[object Undefined]"
js>
(Reporter)

Comment 7

7 years ago
Nice. With test coverage in that bug, this one could even be dup'ed IMHO.

/be

Comment 8

7 years ago
http://hg.mozilla.org/mozilla-central/rev/941910fb9501
Status: NEW → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.