In the [[SetP]] implementation on this page:

http://wiki.ecmascript.org/doku.php?id=harmony:proto_climbing_refactoring

In step 2, the property lookup should stop when a data descriptor of any sort, 
writable or non-writable is uncovered.  A property closer to the start of a 
lookup shadows one further along the prototype chain, and these semantics don't 
preserve that.

Step 5c should return true after calling the setter.

Step 5d(i) to recheck for extensibility is redundant with 
[[DefineOwnProperty]]'s check of the same.

Technically, only step 2 needs to be changed in order to actually make the 
logic sane on the first point.  And the second point could be fixed with a 
one-line addition, and the third with a one-line removal.  But the algorithm's 
unwieldy enough with just adding more steps (particularly to step 2), I think 
you want a somewhat broader refactoring.  I make this proposal:

[[SetP]](Receiver, P, V)
When the [[SetP]] internal method of O is called with initial receiver 
Receiver, property name P, and value V, the following steps are taken:

1. Let ownDesc be the result of calling the [[GetOwnProperty]] internal method 
of O with argument P.
2. If ownDesc is not undefined, then
   a. If IsAccessorDescriptor(ownDesc) is true, then
      i.   Let setter be ownDesc.[[Set]].
      ii.  If setter is undefined, return false.
      iii. Call the [[Call]] internal method of setter providing Receiver as 
the this value and providing V as the sole argument.
      iv.  Return true.
   b. Otherwise IsDataDescriptor(ownDesc) must be true.
      i.   If ownDesc.[[Writable]] is false, return false.
      ii.  If Receiver === O, then
           1. Let updateDesc be the Property Descriptor { [[Value]]: V }.
           2. Return the result of calling the [[DefineOwnProperty]] internal 
method of Receiver passing P, updateDesc, and false as arguments.
      iii. Else
           1. Let newDesc be the Property Descriptor {[[Value]]: V, 
[[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}.
           2. Return the result of calling the [[DefineOwnProperty]] internal 
method of Receiver passing P, newDesc, and false as arguments.
3. Let proto be the value of the [[Prototype]] internal property of O.
4. If proto is null, then define the property on Receiver:
   a. Let newDesc be the Property Descriptor {[[Value]]: V, [[Writable]]: true, 
[[Enumerable]]: true, [[Configurable]]: true}.
   b. Return the result of calling the [[DefineOwnProperty]] internal method of 
Receiver passing P, newDesc, and false as arguments.
5. Return the result of calling the [[SetP]] internal method of proto with 
arguments Receiver, P, and V.

Aside from fixing the noted bugs, this makes one further notable change.  When 
the property lookup to determine whether there's a setting conflict bottoms out 
at the end of the prototype chain, without finding the property, this algorithm 
simple defines the property on the receiver as a fully mutable property.  It 
doesn't reget the property on the receiver to determine if anything's 
"changed", to set the property consistent with its attributes at that instant.  
First, this seems more efficient.  Under the current algorithm any property 
miss must make an effort to reget the original property, even "just in case".  
Second, I have difficulty imagining how changes would legitimately happen, in a 
way that we might consider good coding style.  But perhaps I'm missing some 
reason why this reget is a design requirement; please let me know if I've 
missed it.

Anyway, comments welcome on this -- I'm working on implementing it now, so 
feedback is particularly timely for me, and I'll be able to provide 
implementation feedback quickly.

Jeff
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to