May the defineProperty method of a proxy handler throw a TypeError?

Mark S. Miller erights at
Sun Jun 19 09:21:57 PDT 2011

On Sun, Jun 19, 2011 at 8:22 AM, Tom Van Cutsem < at> wrote:

> 2011/6/18 David Bruant <david.bruant at>
>> Le 18/06/2011 00:47, David Flanagan a écrit :
>> > Given that the fixed properties proposal is adding a return value to
>> > defineProperty, perhaps returning false would be a suitable way to
>> > reject a property definition.
> Yes, I think such an API could work.
>>  I would see this as a weird semantic collision. If I return undefined,
>> should it be considered as a falsy value or an inappropriate property
>> descriptor? If I return {} or [], is it a truthy value or an invalid
>> property descriptor?
> - |undefined| is falsy, so interpret as a reject.
> - {} is a valid, empty property descriptor.
> - For [], or any other non-falsy, non-object value either one could 1)
> ignore such values, 2) interpret them as 'rejects', or 3) interpret them as
> illegal property descriptors, which should trigger a TypeError. I would opt
> for 3), as if the internal Proxy code does:
> let res = handler.defineProperty(...);
> if (res) {
>   desc = ToPropertyDescriptor(res); // throws TypeError if res is a
> non-Object value
>   ...
> } else {
>   reject();
> }
> But before continuing this discussion, I'd like to take measure of how
> important it actually is for the Proxy API to be able to faithfully emulate
> ES5.1 reject behavior in non-strict mode. Say some non-strict ES5.1 code is
> executing Object.defineProperty(...) on a proxy and it throws a TypeError
> rather than failing silently. Is that a big deal or just a minor annoyance?

There might be a misunderstanding here. If ES5.1 strict or non-strict code
explicitly calls Object.defineProperty(...) then ( step 4) the
[[DefineOwnProperty]] method is called with a Throw  argument of true. So a
failed explicit call to Object.defineProperty(...) always throws, regardless
of the strictness of its caller.

To do otherwise would be to make the dynamic scoping mistake,
since Object.defineProperty is first class, not a special form.

> As Mark recently mentioned, to ES5.1 code, proxies are like host objects,
> which may already trigger such behavior anyway. OTOH, it might preclude the
> use of Proxies to transparently wrap existing ES5.1 objects.
> Cheers,
> Tom

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list