Ignore:
Timestamp:
Aug 26, 2009, 9:52:15 AM (16 years ago)
Author:
[email protected]
Message:

[ES5] Implement getOwnPropertyDescriptor
https://bugs.webkit.org/show_bug.cgi?id=28724

Reviewed by Gavin Barraclough.

JavaScriptCore:
Implement the core runtime support for getOwnPropertyDescriptor.
This adds a virtual getOwnPropertyDescriptor method to every class
that implements getOwnPropertySlot that shadows the behaviour of
getOwnPropertySlot. The alternative would be to make getOwnPropertySlot
(or PropertySlots in general) provide property attribute information,
but quick testing showed this to be a regression.

WebCore:
Implement the WebCore side of getOwnPropertyDescriptor. This
requires a custom implementation of getOwnPropertyDescriptor
for every class with a custom implementation of getOwnPropertySlot.

The bindings generator has been updated to generate appropriate
versions of getOwnPropertyDescriptor for the general case where
a custom getOwnPropertyDescriptor is not needed. ES5 is vague
about how getOwnPropertyDescriptor should work in the context of
"host" functions with polymorphic GetOwnProperty, so it seems
okay that occasionally we "guess" what attributes -- eg. determining
whether a property is writable.

Test: fast/js/getOwnPropertyDescriptor.html

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSFunction.cpp

    r47686 r47780  
    178178}
    179179
     180    bool JSFunction::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
     181    {
     182        if (isHostFunction())
     183            return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
     184       
     185        if (propertyName == exec->propertyNames().prototype) {
     186            PropertySlot slot;
     187            getOwnPropertySlot(exec, propertyName, slot);
     188            return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
     189        }
     190       
     191        if (propertyName == exec->propertyNames().arguments) {
     192            descriptor.setDescriptor(exec->interpreter()->retrieveArguments(exec, this), ReadOnly | DontEnum | DontDelete);
     193            return true;
     194        }
     195       
     196        if (propertyName == exec->propertyNames().length) {
     197            descriptor.setDescriptor(jsNumber(exec, jsExecutable()->parameterCount()), ReadOnly | DontEnum | DontDelete);
     198            return true;
     199        }
     200       
     201        if (propertyName == exec->propertyNames().caller) {
     202            descriptor.setDescriptor(exec->interpreter()->retrieveCaller(exec, this), ReadOnly | DontEnum | DontDelete);
     203            return true;
     204        }
     205       
     206        return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
     207    }
     208   
    180209void JSFunction::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
    181210{
Note: See TracChangeset for help on using the changeset viewer.