ES5 {}.toString breaks JQuery

Allen Wirfs-Brock Allen.Wirfs-Brock at microsoft.com
Fri Jun 25 17:51:24 PDT 2010


Apparently JQuery (version???) has a function defined as:

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

Apparently we are seeing IE9 PPB3 failing with some JQuery-based applications that call isFunction with undefined as the argument.  ES5 {}.toString applies ToObject to its this value so toString.call(undefined) is throwing a TypeError.

Most ES5 built-ins are specified to do something like this because in ES3 they would have been passed the global object as the this value.  We discussed this and at the time it seemed like the right thing to do.  We didn't want to provide the global object to built-ins in such situations and if there is code that really is expecting to access the global object in this manner  they aren't going to get it, so throwing seems preferable to silent failures.   This is even listed in Annex E as an intentional incompatability with ES3.

However, there are a lot of instance of JQuery out there and it's conceivable that for toString and a small number of other built-in we could issue an errata to do something other than throw.  But what, return whatever globalObject.toString() returns?  Isn't that implementation dependent?  Or return {}.toString().  That might be most compatible (for such JQuery uses) but do we really want undefined/null to appear to be an object in the only specified way to access the [[Class]] internal property.).

Thoughts??

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es5-discuss/attachments/20100626/b7161278/attachment-0001.html>


More information about the es5-discuss mailing list