Names strawman ready for discussion

Tom Van Cutsem tomvc.be at gmail.com
Thu Sep 9 07:08:42 PDT 2010


Both of these seem to be compelling advantages of soft fields over names.
However, I wonder if it would be possible to get the best of both worlds.

IIUC, the Names proposal converts:

private x;
this.x = "foo";
this.x

into:

let x = new Name;
this[x] = "foo";
this[x]

Would it be possible to instead rewrite it to:

let x = new ExplicitSoftField();
x.set(this, "foo");
x.get(this)

(using the same rules for determining the scope of 'x' as detailed in the
Names proposal)

You would get the 'private' scoping of Names, and the concise syntax,
without the limitations that MarkM raised. Am I missing something?

2010/9/8 Mark S. Miller <erights at google.com>

> On Tue, Sep 7, 2010 at 9:57 PM, Sam Tobin-Hochstadt <samth at ccs.neu.edu>wrote:
>
>> > Hi Sam, glad to see this coming together. A couple questions:
>> > 1) Given
>> >     const n = new Name();
>> >     const x = Object.freeze({...});
>> > what does
>> >     x[n] = 88;
>> > do?
>>
>> Produces an error, just as x["n"] would.
>>
>
> This means that Names cannot be used as virtual "expando" properties on
> frozen objects.
>
>
>  > 2) Given
>> >     const n = new Name();
>> >     const x = Proxy.create(..., ...);
>> > what does
>> >     x[n] = 88;
>> > do?
>>
>> Calls the 'set' trap of 'x' with x, n, and 88 as arguments.
>>
>
> I would then guess that using it as an rvalue, "x[n]", would invoke the
> 'get' trap of x's handler with x and n as arguments. So if x is an object of
> unknown provenance, n may be captured by that object and used to look up
> field values on other objects that should have been hidden from x.
>
> Syntax aside, these are both semantic differences with ExplicitSoftFields.
> In the corresponding examples:
>
> 1)
>     const f = ExplicitSoftField();
>     const x = Object.freeze({...});
>     f.set(x, 88);
> works, rather than throwing an error, because the state being mutated is in
> f rather than x. Unlike Names, this means that ExplicitSoftFields can be
> used as generic collision-free "expando" properties, even on frozen objects.
>
> 2)
>     const f = ExplicitSoftField();
>     const x = Proxy.create(..., ...);
>     f.set(x, 88);
> never invokes x's handler, never giving x a chance to steal f, since only
> x's identity is used by f to look up or store associations. Identity tests
> on a proxy, by design, do not trap to the handler.
>
> --
>     Cheers,
>     --MarkM
>
> _______________________________________________
> 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/20100909/067b2d03/attachment.html>


More information about the es-discuss mailing list