Re: Private Slots

2013-01-26 Thread Mark S. Miller
On Wed, Jan 16, 2013 at 3:53 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: On Jan 16, 2013, at 3:20 PM, Brandon Benvie wrote: It's worth noting that private Symbols *are* used by the ES6 spec to solve a number of other problems currently. They are used to provide easy to use hooks for

Re: Private Slots

2013-01-17 Thread Andreas Rossberg
On 15 January 2013 17:16, Kevin Smith khs4...@gmail.com wrote: It's really none of your business when you try to freeze my object whether any of (a) pre-existing private-symbol-named properties remain writable; (b) weakmap-encoded private state remains writable; (c) objects-as-closures

Re: Private Slots

2013-01-17 Thread Claus Reinke
I have suggested before that it would be good to put control over object iteration into the hands of the object authors, by enabling them to override the slot iteration method. I might be missing something, but isn't this basically covered with the enumerable flag? There are several object

Re: Private Slots

2013-01-17 Thread Claus Reinke
It's really none of your business when you try to freeze my object whether any of (a) pre-existing private-symbol-named properties remain writable; (b) weakmap-encoded private state remains writable; (c) objects-as-closures environment variables remain writable. Really. Not. Your (user).

Re: Private Slots

2013-01-16 Thread Brendan Eich
Well stated, respect. I think you are underweighting the utility of private symbols. The counter-argument I want to make is: what if high-integrity privacy (via weakmaps as you propose) as a popular practice would take off, but with weakmaps there's no optimization (PICs, TI) as there is for

Re: Private Slots

2013-01-16 Thread Brandon Benvie
To compare the various scenarios, this is what (I believe) it looks like for SES. In ES5, SES currently censors gOPN I believe, in order to implement the equivalent of private keys and/or WeakMap. Given an ES6 runtime environment that only supported unique symbols, it would have to censor

Re: Private Slots

2013-01-16 Thread Claus Reinke
Below is a slight variation of the closure hack that allows using private properties through this. The idea is to use the public 'this' as prototype for the private 'this', using 'bind' to give instance methods access to the private 'this' Bound methods. Smart! I come to wonder why you even need

Re: Private Slots

2013-01-16 Thread Mark S. Miller
On Wed, Jan 16, 2013 at 11:47 AM, Brandon Benvie bran...@brandonbenvie.com wrote: To compare the various scenarios, this is what (I believe) it looks like for SES. In ES5, SES currently censors gOPN I believe, in order to implement the equivalent of private keys and/or WeakMap. SES includes

Re: Private Slots

2013-01-16 Thread Brandon Benvie
Indeed, I used SES as a kind of template for this theoretical future framework faced with the wcenarios. It was a response to the idea that private symbols are primarily valuable for a SES type use case where security is paramount, versus regular encapsulation which is handled adequately by unique

Re: Private Slots

2013-01-16 Thread Mark S. Miller
My position on private symbols. My position on classes is and has always been that classes are worth introducing into the language *only* if they give us, or can be used with, an affordable means for true object encapsulation. Assuming Allen is right about what actual implementors will do (which

Re: Private Slots

2013-01-16 Thread Brendan Eich
Mark S. Miller wrote: My position on private symbols. My position on classes is and has always been that classes are worth introducing into the language*only* if they give us, or can be used with, an affordable means for true object encapsulation. Assuming Allen is right about what actual

Re: Private Slots

2013-01-16 Thread Russell Leggett
On Wed, Jan 16, 2013 at 3:48 PM, Brendan Eich bren...@mozilla.com wrote: Mark S. Miller wrote: My position on private symbols. My position on classes is and has always been that classes are worth introducing into the language*only* if they give us, or can be used with, an affordable

Re: Private Slots

2013-01-16 Thread Allen Wirfs-Brock
On Jan 16, 2013, at 12:57 PM, Russell Leggett wrote: On Wed, Jan 16, 2013 at 3:48 PM, Brendan Eich bren...@mozilla.com wrote: Mark S. Miller wrote: My position on private symbols. My position on classes is and has always been that classes are worth introducing into the language*only* if

Re: Private Slots

2013-01-16 Thread David Bruant
Le 16/01/2013 21:48, Brendan Eich a écrit : Mark S. Miller wrote: My position on private symbols. My position on classes is and has always been that classes are worth introducing into the language*only* if they give us, or can be used with, an affordable means for true object encapsulation.

Re: Private Slots

2013-01-16 Thread Brandon Benvie
It's worth noting that private Symbols *are* used by the ES6 spec to solve a number of other problems currently. They are used to provide easy to use hooks for overriding builtin functionality: @@hasInstance, @@create, @@toStringTag, @@iterator, and @@ToPrimitive. Some of these (@@toStringTag,

Re: Private Slots

2013-01-16 Thread Allen Wirfs-Brock
On Jan 16, 2013, at 3:20 PM, Brandon Benvie wrote: It's worth noting that private Symbols *are* used by the ES6 spec to solve a number of other problems currently. They are used to provide easy to use hooks for overriding builtin functionality: @@hasInstance, @@create, @@toStringTag,

Re: Private Slots

2013-01-16 Thread Brandon Benvie
That's exactly how I was thinking of it. @@hasInstance and @@create live on Function.prototype so the only protection a sandbox has from letting any and all comers muck with them is in them not being reflected. Overriding Function.prototype.@@create (and the custom ones e.g. Boolean.@@create)

Re: Private Slots

2013-01-16 Thread Allen Wirfs-Brock
On Jan 16, 2013, at 4:03 PM, Brandon Benvie wrote: That's exactly how I was thinking of it. @@hasInstance and @@create live on Function.prototype so the only protection a sandbox has from letting any and all comers muck with them is in them not being reflected. Overriding

RE: Private Slots

2013-01-16 Thread Nathan Wall
In this light, it may also make sense to make Function.prototype.@@create and Function.prototype.@@hasInstance non-writable, non-configurable. Regardless of the defaults, SES could presumably defend itself in the same same way. If you make Function.prototype.@@create non-writable,

Re: Private Slots

2013-01-16 Thread Brandon Benvie
That's true, restricting their ability to be modified quells that concern. The only other concern would be to make sure there isn't any extension points left open in the default builtins. For example, if Object.@@create wasn't specified by default (and the algorithm still ended up deferring to it,

Re: Private Slots

2013-01-16 Thread Brandon Benvie
It is difficult to use by its nature, it's the kind of thing that implementors or maybe library authors would make use of. It exposes a hook for what previously was a low level spec operation (the object allocation part of construction). On Wed, Jan 16, 2013 at 7:34 PM, Nathan Wall

Re: Private Slots

2013-01-16 Thread Allen Wirfs-Brock
On Jan 16, 2013, at 4:34 PM, Nathan Wall wrote: In this light, it may also make sense to make Function.prototype.@@create and Function.prototype.@@hasInstance non-writable, non-configurable. Regardless of the defaults, SES could presumably defend itself in the same same way. If you

Re: Private Slots

2013-01-16 Thread Allen Wirfs-Brock
On Jan 16, 2013, at 4:34 PM, Brandon Benvie wrote: That's true, restricting their ability to be modified quells that concern. The only other concern would be to make sure there isn't any extension points left open in the default builtins. For example, if Object.@@create wasn't specified

Re: Private Slots

2013-01-16 Thread Kevin Smith
My position on private symbols. My position on classes is and has always been that classes are worth introducing into the language *only* if they give us, or can be used with, an affordable means for true object encapsulation. Classes want encapsulation, yes. But do they want

Re: Private Slots

2013-01-16 Thread Kevin Smith
That's what happens with private in Java (I don't think most Java devs think that the Reflect API makes their private attributes actually not private). Java devs could make everything public, they choose not to because the cost of putting public is the same as the cost of putting private and

Re: Private Slots

2013-01-16 Thread Kevin Smith
An explicit goal of ES6 is to support self hosting of important native libraries including the DOM. Self hosting libraries will be practical only if the self hosted implementation can approach native performance and that includes any overhead for branding, where it is required. In my

Re: Private Slots

2013-01-15 Thread Brendan Eich
Kevin Smith wrote: I think of this fact as rather supporting my view, because freezing is no longer freezing the whole object, as before. It's really none of your business when you try to freeze my object whether any of (a) pre-existing private-symbol-named properties remain writable; (b)

Re: Private Slots

2013-01-15 Thread David Bruant
Le 14/01/2013 19:21, Claus Reinke a écrit : From the teachability perspective, I'm tired of explaining the closure hack to explain private properties. Even to some who are experienced webdevs, I have to explain that they can't access the private property through this.. The language needs to

Re: Private Slots

2013-01-15 Thread Claus Reinke
It's really none of your business when you try to freeze my object whether any of (a) pre-existing private-symbol-named properties remain writable; (b) weakmap-encoded private state remains writable; (c) objects-as-closures environment variables remain writable. Really. Not. Your (user).

Re: Private Slots

2013-01-15 Thread Russell Leggett
I have suggested before that it would be good to put control over object iteration into the hands of the object authors, by enabling them to override the slot iteration method. One would need to find a way of doing so without exposing private names, but it should allow object authors to

Re: Private Slots

2013-01-15 Thread Kevin Smith
It's really none of your business when you try to freeze my object whether any of (a) pre-existing private-symbol-named properties remain writable; (b) weakmap-encoded private state remains writable; (c) objects-as-closures environment variables remain writable. Really. Not. Your.

Re: Private Slots

2013-01-15 Thread Kevin Smith
The variable was called s standing for secret. The example I gave was dummy, but examples in the wild are legion. Take your favorite node library. Anytime it defines a _property, this is where there should be a private name. Again, that's arguable. Certainly it would be better expressed

Re: Private Slots

2013-01-15 Thread Brendan Eich
Brendan Eich wrote: Object.freeze deals in certain observables. It does not free (freeze, of course.) closure state, or weakmap-encoded state, or (per the ES6 proposal) private-symbol-named property state where such properties already exist. Those are not directly observable by the

RE: Private Slots

2013-01-15 Thread Nathan Wall
Sure - and approaches like this (or simpler - people are clever!) can  be factored away into a neat library, without having to mess with the underlying object model. ES6 provides WeakMaps and Proxies. Why not see what people do with those before introducing private slots? Is it really

Re: Private Slots

2013-01-15 Thread Kevin Smith
(b) is a change from ES5 but you don't object to weak maps -- why not? WeakMaps provide a new feature without extending the object model. They are external to objects, if you like. (c) is not a change from JS's object model! Sure - but I'm not objecting to closed-over state (in any

Re: Private Slots

2013-01-15 Thread Brendan Eich
Kevin Smith wrote: (b) is a change from ES5 but you don't object to weak maps -- why not? WeakMaps provide a new feature without extending the object model. They are external to objects, if you like. They are a kind of object, on the contrary. (c) is not a change from JS's

Re: Private Slots

2013-01-15 Thread David Bruant
Le 15/01/2013 17:16, Kevin Smith a écrit : The variable was called s standing for secret. The example I gave was dummy, but examples in the wild are legion. Take your favorite node library. Anytime it defines a _property, this is where there should be a private name. Again,

Re: Private Slots

2013-01-15 Thread David Bruant
Le 15/01/2013 21:06, Herby Vojčík a écrit : David Bruant wrote: ES6 provides WeakMaps and Proxies. Why not see what people do with those before introducing private slots? I wouldn't be opposed to that, but that's just my opinion. Still, private symbols allow property-like syntax. I haven't

Re: Private Slots

2013-01-15 Thread Brendan Eich
Very fair response -- thanks. I want to add praise for Kevin, he asks the right questions, especially the one to which I replied hold that thought: Maybe it's worth it, I don't know. That's the whole point: I don't know. And when in doubt... We certainly did leave out something in

Re: Private Slots

2013-01-15 Thread Mark S. Miller
On Tue, Jan 15, 2013 at 12:10 PM, Tom Van Cutsem tomvc...@gmail.com wrote: In defense of Kevin, I too would argue that private symbols add complexity to the object model. That doesn't mean I'm arguing in favor of removing private symbols, just noting that we do pay a complexity price. We

Re: Private Slots

2013-01-15 Thread Brendan Eich
David Bruant wrote: In theory, private symbols should have the same GC issues than WeakMap. Consider: var o = {}, o2 = {}; for(var i=0, i1000, i++){ let s = new Symbol(true /*private*/); o[s] = o2[s] = i; } Here, private symbols are created, properties are added.

Re: Private Slots

2013-01-15 Thread Brendan Eich
The GC cost is one problem, but the property access cost is another, and the second allocation (wm for every obj) yet another. And as Dean just reminded, prototypal inheritance favors symbols. It's not just one cost that motivates symbols over weakmaps if the goal is OO privacy. /be

Re: Private Slots

2013-01-15 Thread Mark S. Miller
On Tue, Jan 15, 2013 at 1:56 PM, Brendan Eich bren...@mozilla.com wrote: David Bruant wrote: In theory, private symbols should have the same GC issues than WeakMap. Consider: var o = {}, o2 = {}; for(var i=0, i1000, i++){ let s = new Symbol(true /*private*/); o[s]

Re: Private Slots

2013-01-15 Thread Brendan Eich
Mark S. Miller wrote: On Tue, Jan 15, 2013 at 1:56 PM, Brendan Eichbren...@mozilla.com wrote: David Bruant wrote: In theory, private symbols should have the same GC issues than WeakMap. Consider: var o = {}, o2 = {}; for(var i=0, i1000, i++){ let s = new Symbol(true

Re: Private Slots

2013-01-15 Thread Mark S. Miller
On Tue, Jan 15, 2013 at 2:27 PM, Brendan Eich bren...@mozilla.com wrote: Mark S. Miller wrote: On Tue, Jan 15, 2013 at 1:56 PM, Brendan Eichbren...@mozilla.com wrote: David Bruant wrote: In theory, private symbols should have the same GC issues than WeakMap. Consider: var o = {},

Re: Private Slots

2013-01-15 Thread Allen Wirfs-Brock
On Jan 15, 2013, at 1:58 PM, Brendan Eich wrote: The GC cost is one problem, but the property access cost is another, and the second allocation (wm for every obj) yet another. And as Dean just reminded, prototypal inheritance favors symbols. It's not just one cost that motivates symbols

Re: Private Slots

2013-01-15 Thread Mark S. Miller
On Tue, Jan 15, 2013 at 3:03 PM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Jan 15, 2013, at 1:58 PM, Brendan Eich wrote: The GC cost is one problem, but the property access cost is another, and the second allocation (wm for every obj) yet another. And as Dean just reminded,

Re: Private Slots

2013-01-15 Thread Mark S. Miller
I think you now understand my proposal. By simple, I meant for users, not implementors. I have no other disagreement with your conclusion. On Tue, Jan 15, 2013 at 5:00 PM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Jan 15, 2013, at 3:46 PM, Mark S. Miller wrote: On Tue, Jan 15, 2013 at

Re: Private Slots

2013-01-14 Thread Sam Tobin-Hochstadt
On Mon, Jan 14, 2013 at 10:57 AM, Kevin Smith khs4...@gmail.com wrote: When a property is added to an object using a private symbol, it creates a new kind of slot: a private slot. It is clear from the design of the Proxy API that this represents a fundamentally new extension to the ES object

Re: Private Slots

2013-01-14 Thread Allen Wirfs-Brock
On Jan 14, 2013, at 8:04 AM, Sam Tobin-Hochstadt wrote: On Mon, Jan 14, 2013 at 10:57 AM, Kevin Smith khs4...@gmail.com wrote: When a property is added to an object using a private symbol, it creates a new kind of slot: a private slot. It is clear from the design of the Proxy API that this

Re: Private Slots

2013-01-14 Thread Kevin Smith
I (as one of the people who has advocated for symbols) disagree entirely. The JS object model extension required for symbols is small -- JS objects now map from either strings or symbols to values (plus prototype inheritance, getters, setters, configurability, writeability, and the other

Re: Private Slots

2013-01-14 Thread Sam Tobin-Hochstadt
On Mon, Jan 14, 2013 at 11:28 AM, Kevin Smith khs4...@gmail.com wrote: I (as one of the people who has advocated for symbols) disagree entirely. The JS object model extension required for symbols is small -- JS objects now map from either strings or symbols to values (plus prototype

Re: Private Slots

2013-01-14 Thread Kevin Smith
As further evidence, the word private does not even occur in sections 8.1.6 and 8.1.6.1 of the current ES6 draft. These are the sections that define the ES6 object model. Small changes and additions had to be made to allow for property keys to be either strings or symbols but those changes

Re: Private Slots

2013-01-14 Thread David Bruant
Le 14/01/2013 16:57, Kevin Smith a écrit : When a property is added to an object using a private symbol, it creates a new kind of slot: a private slot. It is clear from the design of the Proxy API that this represents a fundamentally new extension to the ES object model. On the very first

Re: Private Slots

2013-01-14 Thread Kevin Smith
There is no new kind of slot. Symbols, private and otherwise, go in exactly the same kind of slot as any other object property. Slots keyed with private symbols have different, novel behavior. Behavior that did not exist before. At the very least, these slots are: 1) Strongly

Re: Private Slots

2013-01-14 Thread Brandon Benvie
Unless I missed a beat, they are not unfreezable. They are exactly like normal properties except they are not enumerated by any existing method including gOPN. On Monday, January 14, 2013, Kevin Smith wrote: There is no new kind of slot. Symbols, private and otherwise, go in exactly the same

Re: Private Slots

2013-01-14 Thread Kevin Smith
No boilerplate, no additional runtime costs than what's necessary. Arguably, all of those examples could be addressed by unique symbols. Where is the need for strong runtime enforcement of encapsulation? I would personally like to see answers to the following questions: - Do private

Re: Private Slots

2013-01-14 Thread Allen Wirfs-Brock
On Jan 14, 2013, at 8:38 AM, Kevin Smith wrote: There is no new kind of slot. Symbols, private and otherwise, go in exactly the same kind of slot as any other object property. Slots keyed with private symbols have different, novel behavior. Behavior that did not exist before. At the

Re: Private Slots

2013-01-14 Thread Sam Tobin-Hochstadt
On Mon, Jan 14, 2013 at 11:50 AM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: On Jan 14, 2013, at 8:38 AM, Kevin Smith wrote: There is no new kind of slot. Symbols, private and otherwise, go in exactly the same kind of slot as any other object property. Slots keyed with private

Re: Private Slots

2013-01-14 Thread Kevin Smith
And again, `Object.freeze` can be thought of as simply enumerating the accessible properties and freezes them, which works unchanged with private symbols, since they are not reflectively accessible via getOwnPropertyNames. I think of this fact as rather supporting my view, because freezing

Re: Private Slots

2013-01-14 Thread Sam Tobin-Hochstadt
On Mon, Jan 14, 2013 at 12:47 PM, Kevin Smith khs4...@gmail.com wrote: And again, `Object.freeze` can be thought of as simply enumerating the accessible properties and freezes them, which works unchanged with private symbols, since they are not reflectively accessible via getOwnPropertyNames.

Re: Private Slots

2013-01-14 Thread Claus Reinke
From the teachability perspective, I'm tired of explaining the closure hack to explain private properties. Even to some who are experienced webdevs, I have to explain that they can't access the private property through this.. The language needs to evolve to the point where people can write

Re: Private Slots

2013-01-14 Thread Kevin Smith
The concept of freezing the whole object is the problem. If you call `freeze` on a DOM object, does the page stop changing? Of course not -- objects can have hidden state that you, the client of that object, have no access to and thus no way to freeze. This isn't something new being added

Re: Private Slots

2013-01-14 Thread Claude Pache
Le 14 janv. 2013 à 19:29, Kevin Smith khs4...@gmail.com a écrit : The concept of freezing the whole object is the problem. If you call `freeze` on a DOM object, does the page stop changing? Of course not -- objects can have hidden state that you, the client of that object, have no

Re: Private Slots

2013-01-14 Thread Claude Pache
—Claude Le 14 janv. 2013 à 20:46, Claude Pache claude.pa...@gmail.com a écrit : Le 14 janv. 2013 à 19:29, Kevin Smith khs4...@gmail.com a écrit : The concept of freezing the whole object is the problem. If you call `freeze` on a DOM object, does the page stop changing? Of course

RE: Private Slots

2013-01-14 Thread Nathan Wall
Consider again the mixin scenario. A user wants to create a class with  private methods: let privateMethod = new Symbol(true); class C { constructor() {} [privateMethod]() { } publicMethod() { this[privateMethod](); } } And then use that class as a mixin: class D {

Re: Private Slots

2013-01-14 Thread Kevin Smith
This is one thing that came to my mind a couple months ago, but there are a number of ways to resolve this problem, such as: function mixin(a, b) { for (let name of Object.getOwnPropertyNames(b)) { let desc = Object.getOwnPropertyDescriptor(b, name); if

RE: Private Slots

2013-01-14 Thread Nathan Wall
In order to satisfy security guarantees, properties which are keys on  private symbols are not returned by getOwnPropertyNames. That's why the methods are bound to the original object. I realize, however, that non-method properties don't work correctly this way (so I probably just should

Re: Private Slots

2013-01-14 Thread Kevin Smith
In order to satisfy security guarantees, properties which are keys on private symbols are not returned by getOwnPropertyNames. That's why the methods are bound to the original object. Regardless of the this binding, the privately keyed method will not be copied over from the source object

RE: Private Slots

2013-01-14 Thread Nathan Wall
Regardless of the this binding, the privately keyed method will not be copied over from the source object and hence will be undefined when called. I think you're not understanding. Here's a simpler example that runs in modern ES engines:     var A = {         foo: function() {