Questions on Map and Set based on SpiderMonkey implementation
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:
- If the this value is undefined, return "[object Undefined]".
- If the this value is null, return "[object Null]".
- Let O be the result of calling ToObject passing the this value as the argument.
- If O has a [[NativeBrand]] internal property, let tag be the corresponding value from the Table 23.
- Else, let tag be the string value "Object".
- 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).
random thoughts: it still looks weird to me to prefix undefined and null with "object", plus there is no undefined [[class]], neither Null one so despite the good intention, I believe null, NaN, and undefined, should return "[not an object]" as well as primitives should return "[primitive String]" as example, rather than "[object String]" since all primitives are metaphorically frozen without extensions allowed ... i.e.
var s = ""; s.whatever = 123; s.whatever; // undefined
br
On 22 January 2012 18:52, David Bruant <bruant.d at gmail.com> wrote:
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]");
FWIW, V8 behaves the same. It's not in the spec yet, but it's the behaviour you would interpolate.
On Mon, Jan 23, 2012 at 5:19 AM, Andreas Rossberg <rossberg at google.com> wrote:
On 22 January 2012 18:52, David Bruant <bruant.d at gmail.com> wrote:
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]");
FWIW, V8 behaves the same. It's not in the spec yet, but it's the behaviour you would interpolate.
As was mentioned in another thread, we agreed at the F2F that we should be writing tests for test262 for features like Maps and Sets that are implemented, even before they're described in the spec. Unfortunately, I think only companies that have executed the contribution agreement for test262 can contribute, but this seems like a good place to start. :)
On Mon, Jan 23, 2012 at 8:53 AM, Sam Tobin-Hochstadt <samth at ccs.neu.edu>wrote:
On Mon, Jan 23, 2012 at 5:19 AM, Andreas Rossberg <rossberg at google.com> wrote:
On 22 January 2012 18:52, David Bruant <bruant.d at gmail.com> wrote:
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]");
FWIW, V8 behaves the same. It's not in the spec yet, but it's the behaviour you would interpolate.
As was mentioned in another thread, we agreed at the F2F that we should be writing tests for test262 for features like Maps and Sets that are implemented, even before they're described in the spec. Unfortunately, I think only companies that have executed the contribution agreement for test262 can contribute, but this seems like a good place to start. :)
Where can I find the information about the contribution agreement for test262?
On Mon, Jan 23, 2012 at 9:23 AM, Rick Waldron <waldron.rick at gmail.com> wrote:
On Mon, Jan 23, 2012 at 8:53 AM, Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
On Mon, Jan 23, 2012 at 5:19 AM, Andreas Rossberg <rossberg at google.com> wrote:
On 22 January 2012 18:52, David Bruant <bruant.d at gmail.com> wrote:
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]");
FWIW, V8 behaves the same. It's not in the spec yet, but it's the behaviour you would interpolate.
As was mentioned in another thread, we agreed at the F2F that we should be writing tests for test262 for features like Maps and Sets that are implemented, even before they're described in the spec. Unfortunately, I think only companies that have executed the contribution agreement for test262 can contribute, but this seems like a good place to start. :)
Where can I find the information about the contribution agreement for test262?
I believe you or your employer (depending on your employment situation and contract) would need to be a member of Ecma first, which can be quite expensive: www.ecma-international.org/memento/members.htm Ecma has discussed making it easier to contribute, but this hasn't happened yet.
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.
Also, what is the benefit of Map.prototype being a map and Set.prototype being a set? This is the kind of things that are true for all object types and apparently, it has bitten (Date.prototype and WeakMap.prototype offer a communication channel for potential attackers) more than being helpful.
David
[1] hg.mozilla.org/mozilla-central/rev/6a5e20a0f741