-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove PrivateMap #11
Comments
I do not understand what a hypothetical |
So, let's assume that we have a new Symbol subtype that is private. What would the semantics be?
When you take these constraints together, you're left with the observable semantics of a WeakMap. (Leaving aside GC considerations of course.) That's the reasoning behind using WeakMap for private fields. Furthermore, the WeakMap interface (get/set/has/delete) allows you to pass the access capability across membranes because you can proxy and potentially revoke access to the weak map object. A value type like symbol wouldn't work cross-membrane for private state. One might argue that that isn't important. The private state thing is still a work in progress. : ) |
I don't think for proxy is a real problem for private state. Rather, the additional possibility. If the symbol key is accessible from the outside, it's not private property.
Remember old
Yes, indeed an advantage. But private symbols could implement such a proxy / getters / setters as simple properties (though more difficult). It would be nice to implement both types of private properties for different cases and the |
I asked @erights to explain to me why private symbols don't interact well with membranes at the last TC39 meeting, and I even took notes!! Here they are cleaned up a bit: Conceptually, you have two operations:
In the private symbol scenario, In the weak map scenario, Each of the three objects Any solution must satisfy these two correctness constraints:
Given these two constraints, we can see why private symbols can't work:
A long time ago on es-discuss, there was talk of various complicated mechanisms that let the private symbol sometimes pass through the proxies and sometimes not, but according to @erights in general each mechanism they discovered failed at least one of the eight cases, and attempts to plug those holes just ended up adding much more complexity. In the end the complexity turned out to be needless if you just invert the relationship and use the weak map mechanism! Here's another way of looking at the situation that might be more intuitive: Let's say See also: bottom section of http://wiki.ecmascript.org/doku.php?id=strawman:relationships That said, I think implementers are still pushing back against |
Thanks!!!! On Thu, Dec 4, 2014 at 3:32 PM, Domenic Denicola [email protected]
Text by me above is hereby placed in the public domain Cheers, |
Interesting. Thanks. |
@erights, enlightening. |
My solution: Yes, these properties can be obtained through Object.getOwnPropertySymbols. BUUUT!! Private property is not protected against hackers !! It's only an abstraction, which allows to avoid conflicts NAMES !! In addition, we may well make 2 functions:
|
No idea about the meaning of "dry/wet membrane". Can someone explain it please? |
If I understand correctly, the simplified explanation is as follows: Even if we added Basically, when you do Both of these can be intercepted by a proxy that wraps the original object and traps all property lookups to that object. The first time a method is invoked that tries to access the |
Hi @spion yes, that is an accurate summary of the most important issue. By itself one could imagine "fixing" this problem with a more complex API, which an earlier proposal actually tried to do. But that got really complicated and left other fundamental problems unsolved. Rather that re-explain here what those remaining problems are, once wiki.ecmascript.org is back online (attn @dherman ) I can point you at some useful explanations. |
Since "clear" was removed from WeakMap, we no longer have strong motivation for PrivateMap.
The text was updated successfully, but these errors were encountered: