Re: Overriding Map/etc with get/set hooks?

2014-08-11 Thread Tab Atkins Jr.
Restarting this thread, because it's still an issue a year+ on. In the Font Loading spec http://dev.w3.org/csswg/css-font-loading/, I have a FontFaceSet interface http://dev.w3.org/csswg/css-font-loading/#FontFaceSet-interface, which is a Set that contains FontFace objects, plus a few other

RE: Overriding Map/etc with get/set hooks?

2014-08-11 Thread Domenic Denicola
: Overriding Map/etc with get/set hooks? Restarting this thread, because it's still an issue a year+ on. In the Font Loading spec http://dev.w3.org/csswg/css-font-loading/, I have a FontFaceSet interface http://dev.w3.org/csswg/css-font-loading/#FontFaceSet-interface, which is a Set that contains

Re: Overriding Map/etc with get/set hooks?

2014-08-11 Thread Tab Atkins Jr.
On Mon, Aug 11, 2014 at 6:33 PM, Domenic Denicola dome...@domenicdenicola.com wrote: When I last looked at this, it seemed like a perfect use case for [Traits](http://soft.vub.ac.be/~tvcutsem/traitsjs/tutorial.html). A Set-like trait would require definitions for add, delete, and

RE: Overriding Map/etc with get/set hooks?

2014-08-11 Thread Ron Buckton
...@wirfs-brock.com Cc: Brendan Eichmailto:bren...@mozilla.com; es-discussmailto:es-discuss@mozilla.org Subject: Re: Overriding Map/etc with get/set hooks? Restarting this thread, because it's still an issue a year+ on. In the Font Loading spec http://dev.w3.org/csswg/css-font-loading/, I have

Re: Overriding Map/etc with get/set hooks?

2014-08-11 Thread Mark S. Miller
On Mon, Aug 11, 2014 at 6:33 PM, Domenic Denicola dome...@domenicdenicola.com wrote: When I last looked at this, it seemed like a perfect use case for [Traits]( http://soft.vub.ac.be/~tvcutsem/traitsjs/tutorial.html). A Set-like trait would require definitions for add, delete, and

RE: Overriding Map/etc with get/set hooks?

2014-08-11 Thread Ron Buckton
-discuss@mozilla.org Subject: RE: Overriding Map/etc with get/set hooks? Sorry for the short reply here, as I'm not at my PC. Would having an @@isValue (Map) and @@isKey (Set/Map) work? Set.prototype[@@isValue] = value = true; // default Built -in Set operations would check values against

Re: Overriding Map/etc with get/set hooks?

2014-08-11 Thread Allen Wirfs-Brock
On Aug 11, 2014, at 5:55 PM, Tab Atkins Jr. wrote: Restarting this thread, because it's still an issue a year+ on. In the Font Loading spec http://dev.w3.org/csswg/css-font-loading/, I have a FontFaceSet interface http://dev.w3.org/csswg/css-font-loading/#FontFaceSet-interface, which is a

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tab Atkins Jr.
On Tue, May 21, 2013 at 9:20 PM, Ron Buckton rbuck...@chronicles.org wrote: What if the default Map prototype had a configurable but non-writable data property for a @@coerceKey symbol that pointed to a default coercion function. You could subclass Map and provide your own @@coerceKey

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Allen Wirfs-Brock
On May 21, 2013, at 6:42 PM, Tab Atkins Jr. wrote: On Tue, May 21, 2013 at 4:19 AM, Brendan Eich bren...@mozilla.com wrote: David Bruant wrote: This description (arbitrary string keys, bidirectional link with style rule) suggests that you want a proxy (canonical values are in the style

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Allen Wirfs-Brock
On May 22, 2013, at 5:20 AM, Ron Buckton wrote: What if the default Map prototype had a configurable but non-writable data property for a @@coerceKey symbol that pointed to a default coercion function. You could subclass Map and provide your own @@coerceKey implementation. Then

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tom Van Cutsem
2013/5/21 Brendan Eich bren...@mozilla.com David Bruant wrote: This description (arbitrary string keys, bidirectional link with style rule) suggests that you want a proxy (canonical values are in the style rule, the proxy is just a façade with a bit of validation/coercion logic). That's the

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Brendan Eich
Tab Atkins Jr. wrote: On Tue, May 21, 2013 at 4:19 AM, Brendan Eichbren...@mozilla.com wrote: So Tab: why do you want to abuse Map instead of make a custom class? Restating from my earlier post: 1. when someone asks is this Map-like? in an appropriately idiomatic JS way, they get a yes

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Brendan Eich
Tab Atkins Jr. wrote: If TC39 isn't going to allow us to ever use*any* of the built-in collection classes just because we have type restrictions we need to enforce, that'll be a pretty raw deal for authors. Whining about TC39 like this is bad for business. Should I whine about W3C to even up

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tab Atkins Jr.
On Wed, May 22, 2013 at 3:40 AM, Brendan Eich bren...@mozilla.com wrote: There aren't many Map methods. Write your own workalikes if you need 'em. Done. Really? You're seriously saying that I, and every other spec author, every time we need to spec something that's just like a built-in

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tab Atkins Jr.
On Wed, May 22, 2013 at 3:44 AM, Brendan Eich bren...@mozilla.com wrote: Tab Atkins Jr. wrote: If TC39 isn't going to allow us to ever use*any* of the built-in collection classes just because we have type restrictions we need to enforce, that'll be a pretty raw deal for authors. Whining

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Brendan Eich
On May 22, 2013, at 4:58 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: On Wed, May 22, 2013 at 3:40 AM, Brendan Eich bren...@mozilla.com wrote: There aren't many Map methods. Write your own workalikes if you need 'em. Done. Really? You're seriously saying that I, and every other spec

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Brendan Eich
On May 22, 2013, at 5:10 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: On Wed, May 22, 2013 at 3:44 AM, Brendan Eich bren...@mozilla.com wrote: Tab Atkins Jr. wrote: If TC39 isn't going to allow us to ever use*any* of the built-in collection classes just because we have type restrictions

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tab Atkins Jr.
On Wed, May 22, 2013 at 9:44 AM, Brendan Eich bren...@mozilla.com wrote: NodeList extends Array now but is not literally Array plus hooks. Same for Map and the quite different thing you're specifying. NodeList is an interesting case, actually. It's an Array, but with a type restriction. Live

RE: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Domenic Denicola
From: Tab Atkins Jr. [jackalm...@gmail.com] NodeList is an interesting case, actually. It's an Array, but with a type restriction. What do you mean by that? Surely you don't mean can only store nodes: ``` var nodeList = document.querySelectorAll(div); undefined nodeList.length 22

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread David Bruant
Le 22/05/2013 19:02, Tab Atkins Jr. a écrit : On Wed, May 22, 2013 at 9:44 AM, Brendan Eich bren...@mozilla.com wrote: NodeList extends Array now but is not literally Array plus hooks. Same for Map and the quite different thing you're specifying. NodeList is an interesting case, actually.

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Andrea Giammarchi
is simply static collection, so immutable: ``` var all = document.querySelectorAll(*); var length = all.length; all[length] = 'whatever'; alert(all.length === length); [].push.call(all, 'whatever'); alert(all.length === length); ``` you can put properties because is extensible but you won't

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Andrea Giammarchi
I believe Tab is asking for something like: `var MyNodeList = new ArrayType(EntryType, length);` where `EntryType` is his own type and the result is an array like collection or map. At least, for what I understood, looks like he's asking for JS CTypes, something rumored a while ago but never

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tab Atkins Jr.
On Wed, May 22, 2013 at 10:35 AM, David Bruant bruan...@gmail.com wrote: Le 22/05/2013 19:02, Tab Atkins Jr. a écrit : On Wed, May 22, 2013 at 9:44 AM, Brendan Eich bren...@mozilla.com wrote: NodeList extends Array now but is not literally Array plus hooks. Same for Map and the quite

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tab Atkins Jr.
On Wed, May 22, 2013 at 11:00 AM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: I believe Tab is asking for something like: `var MyNodeList = new ArrayType(EntryType, length);` where `EntryType` is his own type and the result is an array like collection or map. At least, for what I

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tab Atkins Jr.
On Wed, May 22, 2013 at 1:48 AM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: On May 21, 2013, at 6:42 PM, Tab Atkins Jr. wrote: On Tue, May 21, 2013 at 4:19 AM, Brendan Eich bren...@mozilla.com wrote: David Bruant wrote: This description (arbitrary string keys, bidirectional link with style

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Andrea Giammarchi
you wrote: What do I need to do to get a Map like that? I answered but I've mistaken your original question and apologized already. regards On Wed, May 22, 2013 at 11:10 AM, Tab Atkins Jr. jackalm...@gmail.comwrote: On Wed, May 22, 2013 at 11:00 AM, Andrea Giammarchi

Re: Overriding Map/etc with get/set hooks?

2013-05-22 Thread Tab Atkins Jr.
On Wed, May 22, 2013 at 3:43 PM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: On May 22, 2013, at 7:21 PM, Tab Atkins Jr. wrote: -ride the same number of @@ methods so I don't see a major gain in that approach. [[MapData]] is just a list of tuples. All I need for my spec (and for future

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Sam Tobin-Hochstadt
On Mon, May 20, 2013 at 10:32 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: All of these are easy to do if this is just a Map (or has Map on its prototype chain), but with a custom [[MapData]] whose behavior is defined by my spec. Would another way to think about this be as a regular

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Tab Atkins Jr.
On Mon, May 20, 2013 at 11:10 PM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: On Mon, May 20, 2013 at 10:32 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: All of these are easy to do if this is just a Map (or has Map on its prototype chain), but with a custom [[MapData]] whose behavior is

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Sam Tobin-Hochstadt
On Mon, May 20, 2013 at 11:17 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: On Mon, May 20, 2013 at 11:10 PM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: On Mon, May 20, 2013 at 10:32 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: All of these are easy to do if this is just a Map (or has

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Anne van Kesteren
On Tue, May 21, 2013 at 7:24 AM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: Is it possible for the environment to change the Map during the turn? IOW, is this always true? m.set(x, 1); assert(m.get(x) === 1); If we ignore the toString() and other validation, yes. But note that setting

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Sam Tobin-Hochstadt
On Mon, May 20, 2013 at 11:32 PM, Anne van Kesteren ann...@annevk.nl wrote: On Tue, May 21, 2013 at 7:24 AM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: Is it possible for the environment to change the Map during the turn? IOW, is this always true? m.set(x, 1); assert(m.get(x) === 1);

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Tab Atkins Jr.
On Mon, May 20, 2013 at 11:24 PM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: Is it possible for the environment to change the Map during the turn? IOW, is this always true? m.set(x, 1); assert(m.get(x) === 1); Your example is not a restatement of your question. Yes, the environment can

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Sam Tobin-Hochstadt
On Mon, May 20, 2013 at 11:58 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: On Mon, May 20, 2013 at 11:24 PM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: Is it possible for the environment to change the Map during the turn? IOW, is this always true? m.set(x, 1); assert(m.get(x) === 1);

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Anne van Kesteren
On Tue, May 21, 2013 at 8:11 AM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: Ok, that's what I thought was going on. We can make some other function calls which might mutate the Map, just as with any other Map that we get from someone else. In that case, my response to Anne stands -- why is

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Sam Tobin-Hochstadt
On Tue, May 21, 2013 at 2:52 AM, Anne van Kesteren ann...@annevk.nl wrote: On Tue, May 21, 2013 at 8:11 AM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: Ok, that's what I thought was going on. We can make some other function calls which might mutate the Map, just as with any other Map that

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Anne van Kesteren
On Tue, May 21, 2013 at 11:01 AM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: No, you don't need to do anything differently. Conceptually, there are three things you need: 1. When the Map is created, before it's handed to the program, some items are added. 2. Some platform operations also

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Sam Tobin-Hochstadt
On Tue, May 21, 2013 at 3:09 AM, Anne van Kesteren ann...@annevk.nl wrote: On Tue, May 21, 2013 at 11:01 AM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: No, you don't need to do anything differently. Conceptually, there are three things you need: 1. When the Map is created, before it's

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Brendan Eich
Sam Tobin-Hochstadt wrote: If the plan is to do that, then you should_not_ use Map. That isn't a Map. But that doesn't need to be a proxy, either. It's something with a signature that could be the same as Map's, but with different semantics. I sense people have trouble drawing the line on

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread David Bruant
Le 21/05/2013 04:06, Tab Atkins Jr. a écrit : For the CSS Variables spec I need to define an object with arbitrary string keys, with the initial set determined by the custom properties set in the style rule, and on modification I need to coerce the provided key to a string, and then go mutate

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Brendan Eich
David Bruant wrote: This description (arbitrary string keys, bidirectional link with style rule) suggests that you want a proxy (canonical values are in the style rule, the proxy is just a façade with a bit of validation/coercion logic). That's the sort of use case they've been introduced

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread David Bruant
Le 21/05/2013 13:19, Brendan Eich a écrit : David Bruant wrote: This description (arbitrary string keys, bidirectional link with style rule) suggests that you want a proxy (canonical values are in the style rule, the proxy is just a façade with a bit of validation/coercion logic). That's the

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Anne van Kesteren
On Tue, May 21, 2013 at 12:19 PM, Brendan Eich bren...@mozilla.com wrote: So Tab: why do you want to abuse Map instead of make a custom class? As we tried to explain before, the believe is that a lot of Map generics will work directly on this Map-like object, similar to how we want Array methods

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Anne van Kesteren
On Tue, May 21, 2013 at 12:19 PM, Brendan Eich bren...@mozilla.com wrote: Of course, coercing key type makes the API not Map. So if the bi-directionality is important, this would be a custom Map-like class. I guess I also do not really get this. Sure JavaScript does not have a type system

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Sam Tobin-Hochstadt
On Tue, May 21, 2013 at 6:52 AM, Anne van Kesteren ann...@annevk.nl wrote: On Tue, May 21, 2013 at 12:19 PM, Brendan Eich bren...@mozilla.com wrote: Of course, coercing key type makes the API not Map. So if the bi-directionality is important, this would be a custom Map-like class. I guess I

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Brendan Eich
Anne van Kesteren wrote: On Tue, May 21, 2013 at 12:19 PM, Brendan Eichbren...@mozilla.com wrote: So Tab: why do you want to abuse Map instead of make a custom class? As we tried to explain before, the believe is that a lot of Map generics will work directly on this Map-like object, similar

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Tab Atkins Jr.
On Tue, May 21, 2013 at 4:19 AM, Brendan Eich bren...@mozilla.com wrote: David Bruant wrote: This description (arbitrary string keys, bidirectional link with style rule) suggests that you want a proxy (canonical values are in the style rule, the proxy is just a façade with a bit of

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Tab Atkins Jr.
On Tue, May 21, 2013 at 7:19 AM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: On Tue, May 21, 2013 at 6:52 AM, Anne van Kesteren ann...@annevk.nl wrote: On Tue, May 21, 2013 at 12:19 PM, Brendan Eich bren...@mozilla.com wrote: Of course, coercing key type makes the API not Map. So if the

Re: Overriding Map/etc with get/set hooks?

2013-05-21 Thread Ron Buckton
What if the default Map prototype had a configurable but non-writable data property for a @@coerceKey symbol that pointed to a default coercion function. You could subclass Map and provide your own @@coerceKey implementation. Then Map.prototype.set.call() would be forced to run the custom

RE: Overriding Map/etc with get/set hooks?

2013-05-20 Thread Domenic Denicola
Seems like this isn't really a Map? It'd be pretty confusing for something to pretend to be a Map but act in such coercive and side-effecty ways. Better to just obey the Map structural type, perhaps, to give people an interface they're used to while not pretending to be something you're not?

Re: Overriding Map/etc with get/set hooks?

2013-05-20 Thread Tab Atkins Jr.
On Mon, May 20, 2013 at 7:55 PM, Domenic Denicola dome...@domenicdenicola.com wrote: Seems like this isn't really a Map? It'd be pretty confusing for something to pretend to be a Map but act in such coercive and side-effecty ways. Better to just obey the Map structural type, perhaps, to give

Re: Overriding Map/etc with get/set hooks?

2013-05-20 Thread Domenic Denicola
Oh, I must have misread your original message. I thought it did not allow storing non-string keys. If it can allow storing any kind of key, like a Map, and it's just the initial data you're referring to, then maybe it is a Map. As long as the contract that `map.set(x, y); map.get(x) === y`

Re: Overriding Map/etc with get/set hooks?

2013-05-20 Thread Anne van Kesteren
On Tue, May 21, 2013 at 6:20 AM, Domenic Denicola dome...@domenicdenicola.com wrote: As long as the contract that `map.set(x, y); map.get(x) === y` works for any `x` and `y`, then you're probably fine. I think it would have to subclass those methods by using toString() on the argument passed.

Re: Overriding Map/etc with get/set hooks?

2013-05-20 Thread Domenic Denicola
On May 21, 2013, at 1:23, Anne van Kesteren ann...@annevk.nlmailto:ann...@annevk.nl wrote: On Tue, May 21, 2013 at 6:20 AM, Domenic Denicola dome...@domenicdenicola.commailto:dome...@domenicdenicola.com wrote: As long as the contract that `map.set(x, y); map.get(x) === y` works for any `x` and

Re: Overriding Map/etc with get/set hooks?

2013-05-20 Thread Tab Atkins Jr.
On Mon, May 20, 2013 at 10:20 PM, Domenic Denicola dome...@domenicdenicola.com wrote: Oh, I must have misread your original message. I thought it did not allow storing non-string keys. If it can allow storing any kind of key, like a Map, and it's just the initial data you're referring to,

Re: Overriding Map/etc with get/set hooks?

2013-05-20 Thread Tab Atkins Jr.
On Mon, May 20, 2013 at 10:27 PM, Domenic Denicola dome...@domenicdenicola.com wrote: Hmm, so that invariant wouldn't hold? I assume `has` would be similarly broken? Seems… not so Map like, besides perhaps having some operations with the same name as Map's. Relevant:

Re: Overriding Map/etc with get/set hooks?

2013-05-20 Thread Domenic Denicola
On May 21, 2013, at 1:28, Tab Atkins Jr. jackalm...@gmail.com wrote: On Mon, May 20, 2013 at 10:20 PM, Domenic Denicola Isdome...@domenicdenicola.com wrote: Oh, I must have misread your original message. I thought it did not allow storing non-string keys. If it can allow storing any kind