Did you read the linked post? The problem is completely different from the one 
you describe. It is about interoperability with membranes.
________________________________
From: Gary Guo<mailto:nbdd0...@hotmail.com>
Sent: ‎2014-‎12-‎20 21:41
To: es-discuss@mozilla.org<mailto:es-discuss@mozilla.org>
Subject: RE: Proposal About Private Symbol

Oops, seems Outlook.com ruins my email. One more time

I don't think it's a problem though. As long as the private Symbol doesn't 
leak, there is no way to access private properties. Private Symbol as I 
supposed only eliminate itself from getOwnPropertySymbols, and that's it, there 
should not be no more constraints on private Symbol.

```js
var constructor=function(){
    var privateField=Symbol('private', true);
    var pubField=Symbol('public');
    var leakedField=Symbol('leak', true);
    return function something(arg){
        this[privateField]=arg;
        this[pubField]=arg;
        this[leakedField]=arg;
        this["leak"]=leakedField;
    }
}
var arg="A";
var instance=new constructor(arg); // there is no way to access private fields
arg===instance[Object.getOwnPropertySymbols()[0]] // True, since 
Object.getOwnPropertySymbols expose the symbol
arg===instance[instance.leak]; // True, since instance.leak expose the symbol
```

Under careful use of the symbols, and without Object.getOwnPropertySymbols 
leaking every symbol, we can use symbols as private field.
V8 already has implemented private Symbol (just one more boolean field when 
defining the struct symbol) though it is not exposed to Script-side.

----------------------------------------
> From: d...@domenic.me
> To: waldron.r...@gmail.com; nbdd0...@hotmail.com; es-discuss@mozilla.org
> Subject: RE: Proposal About Private Symbol
> Date: Sat, 20 Dec 2014 20:11:04 +0000
>
> For more reasons on why a simple "private symbol" approach does not quite 
> work, see 
> https://github.com/zenparsing/es-abstract-refs/issues/11&issuecomment-65723350
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to