Questions on Map and Set based on SpiderMonkey implementation
herby at mailbox.sk
Sun Jan 22 10:06:39 PST 2012
David Bruant wrote:
> SpiderMonkey implementation landed today. I was looking over the commit
>  and had a question.
> There is a test:
> assertEq(Object.prototype.toString.call(new Map), "[object Map]");
> I can't see anything about it neither in the latest spec draft nor in
> the wiki proposal. Is it how Object.prototype.toString should behave. I
> assume yes, but since there is no mention somewhere, it's probably worth
> discussing it.
> Likewise for Set.
It is how Object.prototype.toString always (at least since ES5) behaved.
It was in the spec. The newest spec has:
126.96.36.199 Object.prototype.toString ( )
When the toString method is called, the following steps are taken:
1. If the this value is undefined, return "[object Undefined]".
2. If the this value is null, return "[object Null]".
3. Let O be the result of calling ToObject passing the this value as the
4. If O has a [[NativeBrand]] internal property, let tag be the
corresponding value from the Table 23.
5. Else, let tag be the string value "Object".
6. Return the String value that is the result of concatenating the three
Strings "[object ", tag, and "]".
And the Table23 that follows contains strings for native object types,
like Number, Math, Array, JSON etc. There is nothing for Map not Set,
but there is no Map or Set there in the first place (or I failed in
>  https://hg.mozilla.org/mozilla-central/rev/6a5e20a0f741
More information about the es-discuss