Possible Loophole (was: Proposal: Property fixing)

Tom Van Cutsem tomvc.be at gmail.com
Mon Jun 20 01:03:39 PDT 2011


2011/6/19 David Bruant <david.bruant at labri.fr>

> **
> With the current fixed properties proposal, here is what happens in the
> engine at an Object.defineProperty(o, name, pd) call:
> ----
> if("name" has already been observed as non-configurable){
>   [[DefineOwnProperty]] (name, pd) on the fixed properties record // ES5.1
> - 8.12.9
>   // This call includes invariant checking code
> }
> else{
>   resPd = ToPropertydescriptor(call o's defineProperty trap with [o, name,
> pd]);
>   if(!resPd.configurable){
>     add "name" to fixed properties record with resPd as property descriptor
>   }
> }
> ----
>
> What about doing the following:
> ----
> // (Calling the trap in all cases)
> resPd = ToPropertyDescriptor(call o's defineProperty trap with [o, name,
> pd]);
>
> if("name" has already been observed as non-configurable){
>   [[DefineOwnProperty]] (name, resPd) on the non-configurable properties
> record // ES5.1 - 8.12.9
>   // This call includes the exact same invariant checking code
>
> }
> else{
>   if(!resPd.configurable){
>     add "name" to non-configurable properties record with resPd as property
> descriptor
>   }
> }
> ----
>
> The same amount of engine code is called and we have the genericity of
> calling the defineProperty trap every single time.
>

The updated strawman is already more akin to your proposed second
implementation. The way I currently think about a Proxy's
[[DefineOwnProperty]] method with support for fixed properties is as
follows:

[[DefineOwnProperty]] (P, Desc, Throw)
1. Let handler be the value of the [[Handler]] internal property of O.
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 Desc as the second argument.
6. If ToBoolean(trapResult) is false, reject.
7. Let desc be ToPropertyDescriptor(trapResult)
8. If [[GetOwnProperty]](P) is not undefined, or desc.[[Configurable]] is
false
  a. return [[DefineOwnProperty]](P, desc, Throw) (as per ES5 8.12.9)
9. return true
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110620/d34bc382/attachment.html>


More information about the es-discuss mailing list