Security Demands Simplicity (was: Private Slots)

Mark S. Miller erights at google.com
Thu Jan 17 09:19:58 PST 2013


Still not right. I screwed up the scoping of the "balance" variable.
Another correction coming soon.

On Thu, Jan 17, 2013 at 9:17 AM, Mark S. Miller <erights at google.com> wrote:
> On Thu, Jan 17, 2013 at 9:13 AM, Andreas Rossberg <rossberg at google.com> wrote:
>> Hm, I'm afraid I don't fully understand that example. There seems to
>> be a missing closing brace for the constructor, and I don't know what
>> the free occurrences of 'balance' are referring to. Also, the second
>> line of the deposit function seems to be missing in the expansion.
>
> You're right. I also forgot a "new". Corrected I think:
>
>
> class Purse {
>     constructor(private balance) {}
>     getBalance() { return balance; }
>     makePurse() { return new Purse(0); }
>     deposit(amount, srcPurse) {
>         private(srcPurse).balance -= amount;
>         balance += amount;
>     }
> }
>
> expansion
>
> let Purse = (function() {
>     let amp = WeakMap();
>     function Purse(balance) {
>         amp.set(this, Object.seal({
>             get balance() { return balance; },
>             set balance(newBalance) { balance = newBalance; }
>         }));
>     }
>     Purse.prototype = {
>         getBalance: function() { return balance; },
>         makePurse: function() { return new Purse(0); },
>         deposit: function(amount, srcPurse) {
>             amp.get(srcPurse).balance -= amount;
>             balance += amount;
>         }
>     }
>     return Purse;
> })();
>
>
> Please let me know if anything else remains mysterious or looks wrong.
>
> --
>     Cheers,
>     --MarkM



-- 
    Cheers,
    --MarkM


More information about the es-discuss mailing list