{}+{} incosistency

Till Schneidereit till at tillschneidereit.net
Wed Apr 13 15:19:38 UTC 2016

On Wed, Apr 13, 2016 at 4:32 PM, Caitlin Potter <caitpotter88 at gmail.com>

> My read of section (
> https://tc39.github.io/ecma262/#sec-addition-operator-plus-runtime-semantics-evaluation
> ),
> is that V8 is getting this right.
> ToPrimitive on `{}` will, by default, return “[object Object]” — We first
> call `Object.prototype.valueOf()`, which returns `this` (see
> Following this, we call `toString()`, and get “[object Object]”.
> Subsequent steps of the algorithm just concatenate the two strings
> together. So it looks like the other vendors are getting this wrong?

I don't think that reading is right. Steps 5 and 6 call ToPrimitive without
a PreferredType. For objects without a @@toPrimitive property, that ends up
calling OrdinaryToPrimitive(input, "number"), which results in NaN. So step
7 isn't called - instead we end up running steps 8-10.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160413/38a168f5/attachment-0001.html>

More information about the es-discuss mailing list