[[Extensible]]and Proxies (Was: Proxy.isProxy )

Mark S. Miller erights at google.com
Thu Jul 14 09:57:12 PDT 2011


On Thu, Jul 14, 2011 at 6:01 AM, David Bruant <david.bruant at labri.fr> wrote:

>  Le 13/07/2011 20:52, Mark S. Miller a écrit :
>
> On Wed, Jul 13, 2011 at 8:38 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:
>
>> Hate to start another cycle of this,  but if (trapping) proxies can't be
>> set to [[Extensible]]: false, then they can't be used to fully emulate
>> built-ins such as Array.  Why is there this restriction?
>>
>>
>  On Wed, Jul 13, 2011 at 10:30 AM, Allen Wirfs-Brock <
> allen at wirfs-brock.com> wrote:
>
>> Yes, but the restriction prohibits otherwise legal behavior that doesn't
>> violate the invariant.  Isn't that as "bad" as not enforcing the invariant?
>>
>
> What behavior of non-extensible arrays cannot be emulated by a normal
> non-proxy object?
>
> I'm not sure I understand your question since "normal non-proxy object"
> cannot really emuate anything. Did you mean to ask what behavior of
> non-extensible arrays cannot be emulated by proxies?
>

I did mean non-proxy object. In particular, a non-extensible, non-proxy
object whose length is an accessor property, so that decreasing it can cause
deletion, as in your third bullet below.



> If that's the question:
> -----
> var a = Array(1,2,3,4); // a.length===4
> Object.preventExtensions(a);
> console.log(a[3]); // 4, of course
> a.length = 3; // should delete a[3] under the hood.
> console.log(a[3]);
> -----
> Logs "undefined" with a conformant ECMAScript Array.
> This cannot be emulated with current proxies. Current choices are:
> * Throw a TypeError on Object.preventExtensions
> * Accept to be transformed into a normal object fully respecting ES5.1 8.12
> algorithms and log "4"
> * Turn the "length" property into a getter/setter pair which violates ES5.1
> 15.4.5.2 which ask the length property to be a non-configurable data
> property.
>

So having the length be an accessor means that such an object is not a
perfectly transparent emulation of an array. What is a use case this
non-transparency actually matters. In all the cases I can think of, where we
want precisely the behavior of an array, why not just use an array?



>
> David
>



-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110714/57ee1b13/attachment.html>


More information about the es-discuss mailing list