Security Demands Simplicity (was: Private Slots)

Russell Leggett russell.leggett at gmail.com
Thu Jan 17 21:47:31 PST 2013


On Thu, Jan 17, 2013 at 9:40 PM, Kevin Smith <khs4473 at gmail.com> wrote:

> It seems as if this approach to private class members also allows us to
> describe private methods in a convenient way.  Private methods can be
> attached to the _prototype_ of the private field object, thus avoiding
> per-instance allocation.  Of course, the correct "this" value has to be
> used in the expansion when calling the private method, but this approach
> appears to be compatible with mixins (whereas private symbols are not).
>
> https://gist.github.com/4561871
>
> Thoughts?
>

I've been on the fence with the debate, but I'll admit that this proposal
is really winning me over. I don't know if it's too late to get this syntax
in, but it would be a major win for me. I like this a lot more than private
symbols. It actually feels a lot like deconstructing an abstract data type
or pattern matching a case class in scala. There is something nice about
keeping all that extra stuff off the actual object. I'm not sure if I'd
still like it as much without the syntax, but maybe I would now.

I have do have a few questions on this, though:

1. How does this interact with proxies? I'm guessing that a proxy will not
map correctly and therefore make it inaccessible. Personally, I'm ok with
that.

2. Can I use private as a normal variable? Can it be bound to a new
variable, passed as an argument, or returned from a function?
    constructor(balance = 0) {
        let p = private;
        p.checkNum(amount);
        p.balance = balance;
    }
I would understand not going this route, but it definitely restricts access
very tightly where private member or manually using a weakmap would allow
it. Perhaps that edge case can just be handled by falling back to manually
using a weakmap. I admit its a pretty narrow case, and perhaps is best to
not be easy to do. If it *were* to be allowed to be passed around, the
shorthand accessor syntax wouldn't work unless you captured the "this" as
part of the assignment. Definitely possible, though.

3. Can private() be used to add arbitrary object to the map even if they
don't belong to the class?
    let obj = {};
    private(obj).balance = 10;
I'm guessing not, as it translates to a get right now, but curious if this
was a consideration.

- Russ



>
> { Kevin }
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130118/1881d4ba/attachment-0001.html>


More information about the es-discuss mailing list