Hi,

I am wondering if getPropertyDescriptor and getPropertyNames fundamental
traps shouldn't rather be derived traps since they could have a pretty
straightforward default implementation.
One implementation of getPropertyNames could be :
--------------------------
Object.getPropertyNames = function(o){
    var objectToInspect;
    var result = [];

    for(objectToInspect = o;
        objectToInspect !== null;
        objectToInspect = Object.getPrototypeOf(objectToInspect))
    {
            result =
result.concat(Object.getOwnPropertyNames(objectToInspect));
    }

    return result.removeDuplicates(); // the removeDuplicates method is
made up, but you get the point
}
--------------------------
This seem to fit the proposal
(http://wiki.ecmascript.org/doku.php?id=harmony:extended_object_api&s=getpropertydescriptor)
expectations). This could be also the default getPropertyNames trap
implementation.

I haven't really seen a strong definition of what fundamental traps are
in the proposal. On Mark Miller's e-mail
(https://mail.mozilla.org/pipermail/es-discuss/2011-January/012601.html)
is written:
[a trap is fundamental if] there is no coherent default behavior to fall
back to that would be defined in terms of the remaining traps. (please
tell me if I misinterpret what you meant)
If we're going with this definition, then getPropertyDescriptor and
getPropertyNames should probably be derived traps since they can clearly
be defined thanks to other traps (respectively
getOwnPropertyDescriptorand getOwnPropertyNamesas I showed above) which
seems to be coherent fallback behavior.
Instead of a formal definition, this could be a rational for deciding
what is a fundamental trap and what isn't.

In the 5 remaining traps (getOwnPropertyDescriptor, getOwnPropertyNames,
defineProperty, delete, fix), I don't see any that could be defined
thanks to the others. They seem to be also the fundamental actions that
one can perform on a single object:
Property-wise:
- create/configure a property (defineProperty)
- delete a property (delete)
- retrieve a property (getOwnPropertyDescriptor. Can be used to separate
the create and configure cases of defineProperty)
Property-set-wise:
- retrieve the property set (getOwnPropertyNames. More can be found
later on each property with getOwnPropertyDescriptor)
- prevent further extension (and optional reconfigurations for seal and
freeze)(fix)
The prototype can be retrieved thanks to Object.getPrototypeOf (which
cannot be trapped for consistency purposes) and all actions can be
performed by climbing the prototype chain.

Any thoughts on the fundamental trap definition?
Or on the idea of turning getPropertyDescriptor and getPropertyNames
into derived traps with the suggested definition?

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

Reply via email to