Questions on Map and Set based on SpiderMonkey implementation

Herby Vojčík herby at mailbox.sk
Sun Jan 22 10:06:39 PST 2012


David Bruant wrote:
> Hi,
>
> SpiderMonkey implementation landed today. I was looking over the commit
> [1] 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:

15.2.4.2 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 
argument.
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 
searching them).

> David
>
> [1] https://hg.mozilla.org/mozilla-central/rev/6a5e20a0f741

Herby


More information about the es-discuss mailing list