Re: Weak event listener

2013-04-03 Thread Marius Gundersen
I've been through the thread and I haven't read any use case that *requires* Weak References. Only use cases where they make life easier to various degrees. It's been agreed that in most cases, adding an explicit .dispose() or equivalent protocol could work too. Very few things added to ES6 is

Re: Weak event listener

2013-04-03 Thread Mark S. Miller
On Wed, Apr 3, 2013 at 2:13 AM, Marius Gundersen gunder...@gmail.comwrote: I've been through the thread and I haven't read any use case that *requires* Weak References. Only use cases where they make life easier to various degrees. It's been agreed that in most cases, adding an explicit

Re: Weak event listener

2013-04-03 Thread David Bruant
Le 03/04/2013 11:13, Marius Gundersen a écrit : A core part of the problem here is that the distinction between an 'important' reference - one that must keep an object alive - and an 'incidental' reference, that only need exist as long as it target does... This is a concept which cannot be

Re: Weak event listener

2013-04-03 Thread Mark S. Miller
On Wed, Apr 3, 2013 at 11:20 AM, David Bruant bruan...@gmail.com wrote: Le 03/04/2013 11:13, Marius Gundersen a écrit : A core part of the problem here is that the distinction between an 'important' reference - one that must keep an object alive - and an 'incidental' reference, that only

Re: Weak event listener

2013-04-03 Thread David Bruant
Le 03/04/2013 21:18, Mark S. Miller a écrit : Do languages which added WeakRefs have a form of revokable reference too? What difference would it make? E has both. In practice, my sense is that their use cases are disjoint, and that both are needed. Do you have examples of use? May

Re: Weak event listener

2013-04-03 Thread Mark S. Miller
On Wed, Apr 3, 2013 at 1:10 PM, David Bruant bruan...@gmail.com wrote: Le 03/04/2013 21:18, Mark S. Miller a écrit : Do languages which added WeakRefs have a form of revokable reference too? What difference would it make? E has both. In practice, my sense is that their use cases are

Re: Weak event listener

2013-04-02 Thread Bill Frantz
On 4/1/13 at 5:40 AM, sa...@ccs.neu.edu (Sam Tobin-Hochstadt) wrote: Using `.dispose()` is manual management of the allocation and deallocation of object. Manual memory management is fundamentally non-modular -- you can't encapsulate it in a library, and it requires describing memory management

Re: Weak event listener

2013-04-02 Thread Kevin Gadd
An important distinction here - and one I think Bill and Brendan and others have gotten at some, and I've been trying to get at - is that weak references (and similar concepts, like weak maps and weak event listeners) unfortunately encompass a set of different problems and end up being used to

Re: Weak event listener

2013-04-01 Thread David Bruant
Le 27/03/2013 00:22, Kevin Gadd a écrit : OK, it seems like Weak References are now being discussed without the context of previous discussions of weak references, which is a little annoying. Non-contrived real-world use cases that require Weak References (or a primitive with similar

Re: Weak event listener

2013-04-01 Thread Sam Tobin-Hochstadt
On Mon, Apr 1, 2013 at 8:34 AM, David Bruant bruan...@gmail.com wrote: Le 27/03/2013 00:22, Kevin Gadd a écrit : OK, it seems like Weak References are now being discussed without the context of previous discussions of weak references, which is a little annoying. Non-contrived real-world use

Re: Weak event listener

2013-04-01 Thread Brendan Eich
Right. David, I thought I had you convinced at: http://www.mail-archive.com/es-discuss@mozilla.org/msg21480.html /be Sam Tobin-Hochstadt wrote: On Mon, Apr 1, 2013 at 8:34 AM, David Bruantbruan...@gmail.com wrote: Le 27/03/2013 00:22, Kevin Gadd a écrit : OK, it seems like Weak

Re: Weak event listener

2013-03-27 Thread David Bruant
Le 27/03/2013 00:22, Allen Wirfs-Brock a écrit : On Mar 26, 2013, at 2:57 PM, David Bruant wrote: Le 26/03/2013 21:12, Allen Wirfs-Brock a écrit : On Mar 26, 2013, at 12:18 PM, Mark S. Miller wrote: WeakSet may or may not happen by ES6. But even if it doesn't, WeakSet is trivially shimmable

Re: Weak event listener

2013-03-27 Thread Brendan Eich
Please read the memory safety and weak references thread. The issue is not just SES, which might remove an iterator in preparing the environment. Stock JS must not be vulnerable to jit-spray attacks due to enumerable weak maps. /be David Bruant wrote: I agree, but I don't see how it

Re: Weak event listener

2013-03-27 Thread Jason Orendorff
On Tue, Mar 26, 2013 at 3:05 PM, Brendan Eich bren...@mozilla.com wrote: Hi Jason, agree on your request for non-contrived use-cases. I wrote about the general observer pub/sub problem here: http://www.mail-archive.com/es-discuss@mozilla.org/msg21480.html Hope it helps. M. It does.

Re: Weak event listener

2013-03-27 Thread David Bruant
Le 27/03/2013 15:52, Brendan Eich a écrit : Please read the memory safety and weak references thread. The issue is not just SES, which might remove an iterator in preparing the environment. Stock JS must not be vulnerable to jit-spray attacks due to enumerable weak maps. From what I

Re: Weak event listener

2013-03-27 Thread Brendan Eich
David Bruant wrote: Le 27/03/2013 15:52, Brendan Eich a écrit : Please read the memory safety and weak references thread. The issue is not just SES, which might remove an iterator in preparing the environment. Stock JS must not be vulnerable to jit-spray attacks due to enumerable weak maps.

Re: Weak event listener

2013-03-27 Thread Sam Tobin-Hochstadt
On Mar 27, 2013 6:40 PM, Brendan Eich bren...@mozilla.com wrote: David Bruant wrote: Le 27/03/2013 15:52, Brendan Eich a écrit : Please read the memory safety and weak references thread. The issue is not just SES, which might remove an iterator in preparing the environment. Stock JS must

Re: Weak event listener

2013-03-27 Thread Brendan Eich
Sam Tobin-Hochstadt wrote: Changing the disagreement to be about JS vs. its impls is off the mark. Can you re-defend enumerability of weakmaps now that I've pointed out the security risk does not apply only to SES users, to be addressed by SES removing the @iterator? I don't think this is

Re: Weak event listener

2013-03-27 Thread Sam Tobin-Hochstadt
On Wed, Mar 27, 2013 at 9:09 PM, Brendan Eich bren...@mozilla.com wrote: What Dion's attack shows is that conservative stack scanning, when combined with any ability to observe GC, will leak some information about the addresses of objects. This can almost certainly be generalized to any

Re: Weak event listener

2013-03-27 Thread Brendan Eich
Sam Tobin-Hochstadt wrote: However, I think this demonstration makes a much stronger case against conservative GC. Dion's attack requires, fundamentally, three things: 1. Conservative GC (of any form). 2. Some data structure that the browser holds weakly if at all, but can be held strongly

Re: Weak event listener

2013-03-26 Thread Marius Gundersen
So to summarize: - This would be very useful in large MVC applications with many independent components. - Even with WeakMaps there is no way to implement weak event listeners, since WeakMaps cannot be iterated. A weak reference implementation would solve this. - The main problem with weak event

Re: Weak event listener

2013-03-26 Thread Juan Ignacio Dopazo
2013/3/25 Erik Arvidsson erik.arvids...@gmail.com WeakMap would not work in this specific case since a WeakMap cannot be iteratered. I thought there was an iterable WeakSet for ES6. Was it postponed to ES7 or just dropped? Thanks, Juan ___

Re: Weak event listener

2013-03-26 Thread Tom Van Cutsem
2013/3/26 Juan Ignacio Dopazo dopazo.j...@gmail.com 2013/3/25 Erik Arvidsson erik.arvids...@gmail.com WeakMap would not work in this specific case since a WeakMap cannot be iteratered. I thought there was an iterable WeakSet for ES6. Was it postponed to ES7 or just dropped? I doubt

Re: Weak event listener

2013-03-26 Thread Rick Waldron
On Tue, Mar 26, 2013 at 9:46 AM, Tom Van Cutsem tomvc...@gmail.com wrote: 2013/3/26 Juan Ignacio Dopazo dopazo.j...@gmail.com 2013/3/25 Erik Arvidsson erik.arvids...@gmail.com WeakMap would not work in this specific case since a WeakMap cannot be iteratered. I thought there was an

RE: Weak event listener

2013-03-26 Thread Domenic Denicola
From: Rick Waldron [waldron.r...@gmail.com] TC39 reached consensus on the inclusion of WeakSet, though it needs to be designed: https://github.com/rwldrn/tc39-notes/blob/master/es6/2012-09/sept-19.md#weakset Is this ES6 timeframe, or ES7? I have run into a few use cases for it since hearing

Re: Weak event listener

2013-03-26 Thread Rick Waldron
On Tue, Mar 26, 2013 at 12:23 PM, Domenic Denicola dome...@domenicdenicola.com wrote: From: Rick Waldron [waldron.r...@gmail.com] TC39 reached consensus on the inclusion of WeakSet, though it needs to be designed:

Re: Weak event listener

2013-03-26 Thread Sam Tobin-Hochstadt
On Tue, Mar 26, 2013 at 12:28 PM, Rick Waldron waldron.r...@gmail.com wrote: On Tue, Mar 26, 2013 at 12:23 PM, Domenic Denicola dome...@domenicdenicola.com wrote: From: Rick Waldron [waldron.r...@gmail.com] TC39 reached consensus on the inclusion of WeakSet, though it needs to be

Re: Weak event listener

2013-03-26 Thread Mark S. Miller
WeakSet may or may not happen by ES6. But even if it doesn't, WeakSet is trivially shimmable on WeakMap. WeakRef will definitely not happen earlier than ES7. I do hope it will happen in ES7, but this discussion has yet to happen. On Tue, Mar 26, 2013 at 4:30 PM, Sam Tobin-Hochstadt

Re: Weak event listener

2013-03-26 Thread Jason Orendorff
On Mon, Mar 25, 2013 at 9:29 PM, Erik Arvidsson erik.arvids...@gmail.com wrote: WeakMap would not work in this specific case since a WeakMap cannot be iteratered. What would work here is determinism: https://gist.github.com/jorendorff/5245857 For this, a deterministic API is just as easy to

Re: Weak event listener

2013-03-26 Thread Brendan Eich
Hi Jason, agree on your request for non-contrived use-cases. I wrote about the general observer pub/sub problem here: http://www.mail-archive.com/es-discuss@mozilla.org/msg21480.html Hope it helps. One specific thought below. Jason Orendorff wrote: What would work here is determinism:

Re: Weak event listener

2013-03-26 Thread Allen Wirfs-Brock
On Mar 26, 2013, at 12:18 PM, Mark S. Miller wrote: WeakSet may or may not happen by ES6. But even if it doesn't, WeakSet is trivially shimmable on WeakMap. Which is why it isn't the in the spec. yet. It was introduced in support of Proxy private Symbol white list, but it is still unclear

Re: Weak event listener

2013-03-26 Thread Brandon Benvie
On 3/26/2013 1:03 PM, David Bruant wrote: I'm starting to wonder whether bringing weakrefs is equivalent to having iterable WeakMaps... And if so, why not make WeakMaps iterable? This is a question I had as well. An iterable WeakMap is nearly the same as a Map full of WeakRefs, is it not? Just

Re: Weak event listener

2013-03-26 Thread David Bruant
Le 26/03/2013 21:26, Brandon Benvie a écrit : On 3/26/2013 1:03 PM, David Bruant wrote: I'm starting to wonder whether bringing weakrefs is equivalent to having iterable WeakMaps... And if so, why not make WeakMaps iterable? This is a question I had as well. An iterable WeakMap is nearly the

Re: Weak event listener

2013-03-26 Thread David Bruant
Le 26/03/2013 21:12, Allen Wirfs-Brock a écrit : On Mar 26, 2013, at 12:18 PM, Mark S. Miller wrote: WeakSet may or may not happen by ES6. But even if it doesn't, WeakSet is trivially shimmable on WeakMap. Set is also shimmable on top of Map. If Set is in, there are as many reason to have

Re: Weak event listener

2013-03-26 Thread David Bruant
Le 26/03/2013 22:56, Mark S. Miller a écrit : Because the weak-map-maker constructor grants no privilege and can be generally accessible, whereas the weak-ref-maker grants the privilege of being able to observe the non-determinism of GC, and so should not be made accessible to code that

Re: Weak event listener

2013-03-26 Thread Mark Miller
On Tue, Mar 26, 2013 at 10:14 PM, David Bruant bruan...@gmail.com wrote: Le 26/03/2013 22:56, Mark S. Miller a écrit : Because the weak-map-maker constructor grants no privilege and can be generally accessible, whereas the weak-ref-maker grants the privilege of being able to observe the

Re: Weak event listener

2013-03-26 Thread Allen Wirfs-Brock
On Mar 26, 2013, at 2:57 PM, David Bruant wrote: Le 26/03/2013 21:12, Allen Wirfs-Brock a écrit : On Mar 26, 2013, at 12:18 PM, Mark S. Miller wrote: WeakSet may or may not happen by ES6. But even if it doesn't, WeakSet is trivially shimmable on WeakMap. Set is also shimmable on top of

Re: Weak event listener

2013-03-26 Thread Kevin Gadd
OK, it seems like Weak References are now being discussed without the context of previous discussions of weak references, which is a little annoying. Non-contrived real-world use cases that require Weak References (or a primitive with similar capabilities, like a Map with weak values instead of

Re: Weak event listener

2013-03-26 Thread Mark S. Miller
On Tue, Mar 26, 2013 at 11:22 PM, Kevin Gadd kevin.g...@gmail.com wrote: OK, it seems like Weak References are now being discussed without the context of previous discussions of weak references, which is a little annoying. Non-contrived real-world use cases that require Weak References (or a

Weak event listener

2013-03-25 Thread Marius Gundersen
I tried posting this before, but it seems to have gotten lost on the internet. One thing which is impossible to make in JavaScript today is a weakly referenced event listener system. In such a system an event listener is not strongly referenced by the event system, so events are only dispatched

Re: Weak event listener

2013-03-25 Thread Kevin Gadd
Most use cases I've personally seen for weak events would be satisfied by a WeakMap of weak event target - event handler. Having the event handler itself be weak instead of the event target seems strange to me; it introduces a bunch of nondeterministic behavior that isn't desirable - sometimes

Re: Weak event listener

2013-03-25 Thread Erik Arvidsson
WeakMap would not work in this specific case since a WeakMap cannot be iteratered. WeakRefs are needed to do data binding and pub sub systems like these. WeakRefs are very likely to be part of ES7. We haven't really talked much about them formally but informally TC39 members seems to agree.

Re: Weak event listener

2013-03-25 Thread Peter Michaux
On Mon, Mar 25, 2013 at 2:55 AM, Marius Gundersen gunder...@gmail.com wrote: One thing which is impossible to make in JavaScript today is a weakly referenced event listener system. In such a system an event listener is not strongly referenced by the event system, so events are only dispatched

Re: Weak event listener

2013-03-25 Thread Benoit Marchant
Very true, I'm wondering if based on usage today it could make sense to have this as default behavior on current API? Benoit On Mar 25, 2013, at 19:51, Peter Michaux petermich...@gmail.com wrote: On Mon, Mar 25, 2013 at 2:55 AM, Marius Gundersen gunder...@gmail.com wrote: One thing which