May the defineProperty method of a proxy handler throw a TypeError?
Tom Van Cutsem
tomvc.be at gmail.com
Mon Jun 20 01:13:07 PDT 2011
2011/6/19 Mark S. Miller <erights at google.com>
> On Sun, Jun 19, 2011 at 8:22 AM, Tom Van Cutsem <tomvc.be at gmail.com>wrote:
>> 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 (18.104.22.168 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.
You're right, the problem is not with Object.defineProperty but rather with
[[Put]] / the set trap (since it defaults to [[DefineOwnProperty]] / the
defineProperty trap, and it is dependent on the strictness of the caller).
But my question remains: how important is it for a Proxy to be able to
faithfully emulate the reject behavior of assignment in non-strict code? If
it is important then we should probably have the defineProperty trap return
a success value, just like delete or set.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss