On Jun 18, 2014, at 4:12 PM, Brendan Eich wrote:

> Allen Wirfs-Brock wrote:
>> The spec. current says throw for this Symbol.prototype case.  The 
>> (reasonable) opposing view is that toString should never throw.  Other than 
>> the protoype-is-not-an-instance it all about unlikely edge cases where 
>> toString methods are applied to the wrong kind of object.
> 
> js> Object.create(null).toString()
> typein:1:0 TypeError: Object.create(...).toString is not a function
> 
> It happens. Better to catch that error (Symbol.prototype flowing into an 
> implicit conversion) early?

which is pretty much the approach the ES6 spec. has taken WRT toString up to 
now. Tension between catching invalid iplicit toString conversions and reliable 
toString for debugging. 

At any rate, run time tools can really depend upon toString working,  They 
probably should use something like:

function reliableToString(obj) {
   try {return obj.toString()} catch (e) {
           try {return {}.toString.call(obj)} catch (f) {
                 return "[ object ???]"}
            }
    }
}

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to