Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-13 Thread Irakli Gozalishvili
Here is a link to a documentatin for the weak map based solution that Kris mentioned: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/core/namespace.html We find it invaluable and use for storing private field. Inheritance works, but we did not found that feature all that

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Herby Vojčík
Nathan Wall wrote: // ES6 Symbols // Forgive me for not knowing what the current // correct syntax is for creating a symbol: let timestamp = new Symbol(); class SimpleDate { construct(time) { this.setTime(time); }

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread David Bruant
Le 10/01/2013 17:22, Nathan Wall a écrit : Choosing symbols or a weakmap would make a huge difference in how proxy replacement would react to DOM algorithms. If the DOM in terms of accessing private properties, then proxies can replace DOM objects transparently. Their unknownPrivateSymbol trap

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Brendan Eich
Nathan Wall wrote: In the case of (1), the implementation using a private symbol will have internal accesses to the `timestamp` symbol exposed through the unknownPrivateSymbol trap. Private symbols do not trap. In the case of (2), the implementation using a private symbol will fail on a

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread David Bruant
Le 10/01/2013 17:41, Brendan Eich a écrit : Nathan Wall wrote: In the case of (1), the implementation using a private symbol will have internal accesses to the `timestamp` symbol exposed through the unknownPrivateSymbol trap. Private symbols do not trap. They do trap, but they don't leak.

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Brandon Benvie
At the very least, WeakMaps are potentially usable today (depending on the target audience) while symbols are nowhere in sight. I’ve gotten a lot of mileage out of this function, which as you said provides a similar effective result as symbols (they differ in that the WeakMap version isn’t

RE: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Domenic Denicola
It's funny: I've been considering a similar thread, but the opposite. I.e. private symbols better than weak maps? In particular, given the freezing clarification, the use cases for weak maps instead of private symbols seem to reduce to adding *new* symbols to extension-prevented objects. Is

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Brandon Benvie
They both have their place since there's many uses for both inherited and non-inherited private values. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Brendan Eich
Allen rightly has pointed out several times on es-discuss that WeakMaps require GC special handling and are costly, compared to private symbols. This is true not only for GC time, but especially for get/set runtime. Properties named by Symbols, when implemented, should have the same

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Kevin Smith
They both have their place since there's many uses for both inherited and non-inherited private values. Can we see some demonstrated use-cases for which WeakMaps are insufficient, and private properties are? I continue to hear that private symbols are a great idea without any discussion of

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Erik Arvidsson
Private symbols should be faster. No need for hashing and GC of an object with private symbols is the exact same GC as any other object. Getting the GC behavior of a WeakMap is a lot harder (and thus slower). ...also what Brendan just said. On Thu, Jan 10, 2013 at 11:50 AM, Brandon Benvie

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Erik Arvidsson
On Thu, Jan 10, 2013 at 11:55 AM, Kevin Smith khs4...@gmail.com wrote: They both have their place since there's many uses for both inherited and non-inherited private values. Can we see some demonstrated use-cases for which WeakMaps are insufficient, and private properties are? I continue

RE: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Domenic Denicola
From: Brandon Benvie [bran...@brandonbenvie.com] Sent: Thursday, January 10, 2013 11:50 They both have their place since there's many uses for both inherited and non-inherited private values. Of course, (non-)inheritance is a great point. Amusingly, using conventional OO terminology, it

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Brendan Eich
Symbols (private or public, don't forget the latter) are crucial to ES6 and not going away :-|. Besides the property access and GC costs of WeakMaps (which are probably fine, but at least inevitable, when you really do need a WeakMap), symbols allow coordination between friendly objects by

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Brendan Eich
Domenic Denicola wrote: From: Brandon Benvie [bran...@brandonbenvie.com] Sent: Thursday, January 10, 2013 11:50 They both have their place since there's many uses for both inherited and non-inherited private values. Of course, (non-)inheritance is a great point. Amusingly, using

RE: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Nathan Wall
Brendan Eich wrote: Nathan Wall wrote: In the case of (2), the implementation using a private symbol will fail on a call to `setTime` when the object is frozen (I think). Nope, we agreed that frozen objects support setting pre-existing (added before the object was made non-extensible)

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Brendan Eich
Nathan Wall wrote: Brendan Eich wrote: Nathan Wall wrote: In the case of (2), the implementation using a private symbol will fail on a call to `setTime` when the object is frozen (I think). Nope, we agreed that frozen objects support setting pre-existing (added before the object was made

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Kris Kowal
As an aside, Irakli Gozashvili and I independently realized that you could use a WeakMap for parallel objects with inheritance. Very similar to Brendan’s createStorage, we put together a parallel universe constructor. function Parallel(root) { var parallel = new WeakMap(); root = root ||

RE: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Nathan Wall
Brendan Eich: No, not if the symbol is not in the whitelist. Zero information leak is required. That's good news too. Objection withdrawn. I guess I didn't correctly understand David's point in the direct_proxies thread then :-/. I'll have to reread it more carefully. Thanks for the

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Allen Wirfs-Brock
On Jan 10, 2013, at 8:41 AM, Brendan Eich wrote: Nathan Wall wrote: In the case of (1), the implementation using a private symbol will have internal accesses to the `timestamp` symbol exposed through the unknownPrivateSymbol trap. Private symbols do not trap. In the case of (2), the

RE: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Nathan Wall
Brendan Eich: No, not if the symbol is not in the whitelist. Zero information leak is required. That's good news too. Objection withdrawn. Maybe I gave up too easy :). Is the `unknownPrivateSymbol` trap called? What's the rationale for this trap?

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Kevin Smith
Symbols (private or public, don't forget the latter) are crucial to ES6 and not going away :-|. No problem here with public symbols! They provide collision-free property naming without changing the underlying object model. Woot! But when I ask for use cases for private symbols, I get

RE: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Domenic Denicola
-discuss@mozilla.org Subject: Re: WeakMap better than Private Symbols? (was: direct_proxies problem) On Thu, Jan 10, 2013 at 11:22 AM, Nathan Wall nathan.w...@live.commailto:nathan.w...@live.com wrote: // ES6 WeakMap let timeMap = new WeakMap(), // Store WeakMap methods to maintain

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Allen Wirfs-Brock
: WeakMap better than Private Symbols? (was: direct_proxies problem) On Thu, Jan 10, 2013 at 11:22 AM, Nathan Wall nathan.w...@live.com wrote: // ES6 WeakMap let timeMap = new WeakMap(), // Store WeakMap methods to maintain integrity of the internal state

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Rick Waldron
:* Re: WeakMap better than Private Symbols? (was: direct_proxies problem) On Thu, Jan 10, 2013 at 11:22 AM, Nathan Wall nathan.w...@live.comwrote: // ES6 WeakMap let timeMap = new WeakMap(), // Store WeakMap methods to maintain integrity of the internal state

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Rick Waldron
@mozilla.org *Subject:* Re: WeakMap better than Private Symbols? (was: direct_proxies problem) On Thu, Jan 10, 2013 at 11:22 AM, Nathan Wall nathan.w...@live.com wrote: // ES6 WeakMap let timeMap = new WeakMap(), // Store WeakMap methods to maintain integrity

Re: WeakMap better than Private Symbols? (was: direct_proxies problem)

2013-01-10 Thread Brendan Eich
Nathan Wall wrote: Brendan Eich: No, not if the symbol is not in the whitelist. Zero information leak is required. That's good news too. Objection withdrawn. Maybe I gave up too easy :). Is the `unknownPrivateSymbol` trap called? What's the rationale for this trap?