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/JSObject.cpp

    r47267 r47780  
    3131#include "NativeErrorConstructor.h"
    3232#include "ObjectPrototype.h"
     33#include "PropertyDescriptor.h"
    3334#include "PropertyNameArray.h"
    3435#include "Lookup.h"
     
    505506}
    506507
     508bool JSObject::getOwnPropertyDescriptor(ExecState*, const Identifier& propertyName, PropertyDescriptor& descriptor)
     509{
     510    unsigned attributes = 0;
     511    JSCell* cell = 0;
     512    size_t offset = m_structure->get(propertyName, attributes, cell);
     513    if (offset == WTF::notFound)
     514        return false;
     515    descriptor.setDescriptor(getDirectOffset(offset), attributes);
     516    return true;
     517}
     518
     519bool JSObject::getPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
     520{
     521    JSObject* object = this;
     522    while (true) {
     523        if (object->getOwnPropertyDescriptor(exec, propertyName, descriptor))
     524            return true;
     525        JSValue prototype = object->prototype();
     526        if (!prototype.isObject())
     527            return false;
     528        object = asObject(prototype);
     529    }
     530}
    507531} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.