Minor type confusion in proxies proposal?

Sean Eagan seaneagan1 at gmail.com
Tue Jul 5 07:45:39 PDT 2011


On Sun, Jul 3, 2011 at 12:00 PM, Mark S. Miller <erights at google.com> wrote:
>> Here is a possible revised semantics for [[DefineOwnProperty]] on trapping
>> proxies, and the Object.defineProperty built-in:
>> [[DefineOwnProperty]] (P, Desc, Throw)
>> When the [[DefineOwnProperty]] internal method of a trapping proxy O is
>> called with property name P, property descriptor Desc and Boolean flag
>> Throw, the following steps are taken:
>> 1. Let descObj be FromGenericPropertyDescriptor(Desc) // see
>> harmony:proxies_semantics page
>> 2. Return DefineProxyProperty(O, P, descObj, Throw)
>> DefineProxyProperty (Proxy, P, DescObj, Throw)
>> When the DefineProxyProperty auxiliary function is called with a trapping
>> proxy Proxy, a property name P, an Object DescObj and a Boolean flag Throw,
>> the following steps are taken:
>> 1. Let handler be the value of the [[Handler]] internal property of Proxy.
>> 2. Let defineProperty be the result of calling the [[Get]] internal method
>> of handler with argument “defineProperty”.
>> 3. If defineProperty is undefined, throw a TypeError exception.
>> 4. If IsCallable(defineProperty) is false, throw a TypeError exception.
>> 5. Let trapResult be the result of calling the [[Call]] internal method of
>> defineProperty providing handler as the this value, P as the first argument
>> and DescObj as the second argument.
>
> This pass-through without protective copying is too hazardous. It means each
> handler must individually protect itself, not only against accessor
> behavior, but against the caller changing the shared DescObj after the fact.

I think if an "Object.toPropertyDescriptor" function were introduced,
then this protection burden may be sufficiently small.  This would be
similar to the FixedHandler approach of providing *optional* builtin
invariant maintenance support.  The first argument to this function
would be the object to convert to a property descriptor,  and there
could potentially be a second argument which could be a boolean as to
whether to keep non-standard attributes.

>
>>
>> 6. Let success be ToBoolean(trapResult)
>> 7. If success is false, reject
>> 8. Return true
>> Object.defineProperty (O, P, Attributes)
>> 1. If Type(O) is not Object throw a TypeError exception.
>> 2. Let name be ToString(P).
>> 3. If O is a trapping proxy
>>   a. Call DefineProxyProperty(O, name, Attributes, true)
>>   b. Return O.
>> 4. Let desc be the result of ToPropertyDescriptor(Attributes)
>> 5. Call the [[DefineOwnProperty]] internal method of O with arguments
>> name, desc, and true.
>> 6. Return O.

Cheers,
Sean Eagan


More information about the es-discuss mailing list