Skip to content

Commit

Permalink
2010-03-01 Oliver Hunt <oliver@apple.com>
Browse files Browse the repository at this point in the history
        Reviewed by Gavin Barraclough.

        PropertySlot::getValue(ExecState, unsigned) unnecessarily converts index to an Identifier
        https://bugs.webkit.org/show_bug.cgi?id=35561

        Fix this by defining a separate property getter function for index getters.  This allows
        us to pass an unsigned number without the conversion to an Identifier.  We then update
        setCustomIndex to take this new getter type.

        * runtime/PropertySlot.h:
        (JSC::PropertySlot::getValue):
        (JSC::PropertySlot::setCustom):
        (JSC::PropertySlot::setCustomIndex):
2010-03-01  Oliver Hunt  <oliver@apple.com>

        Reviewed by Gavin Barraclough.

        PropertySlot::getValue(ExecState, unsigned) unnecessarily converts index to an Identifier
        https://bugs.webkit.org/show_bug.cgi?id=35561

        Update bindings generation and the few manual indexing getters we have to use
        the new PropertySlot API.

        * bindings/js/JSDOMWindowCustom.cpp:
        (WebCore::indexGetter):
        * bindings/scripts/CodeGeneratorJS.pm:
        * bridge/runtime_array.cpp:
        (JSC::RuntimeArray::indexGetter):
        * bridge/runtime_array.h:

Canonical link: https://commits.webkit.org/46698@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@55397 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ojhunt committed Mar 2, 2010
1 parent 7d75812 commit 33fbd4f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
16 changes: 16 additions & 0 deletions JavaScriptCore/ChangeLog
@@ -1,3 +1,19 @@
2010-03-01 Oliver Hunt <oliver@apple.com>

Reviewed by Gavin Barraclough.

PropertySlot::getValue(ExecState, unsigned) unnecessarily converts index to an Identifier
https://bugs.webkit.org/show_bug.cgi?id=35561

Fix this by defining a separate property getter function for index getters. This allows
us to pass an unsigned number without the conversion to an Identifier. We then update
setCustomIndex to take this new getter type.

* runtime/PropertySlot.h:
(JSC::PropertySlot::getValue):
(JSC::PropertySlot::setCustom):
(JSC::PropertySlot::setCustomIndex):

2010-03-01 Gavin Barraclough <barraclough@apple.com>

Reviewed by Oliver Hunt.
Expand Down
15 changes: 12 additions & 3 deletions JavaScriptCore/runtime/PropertySlot.h
Expand Up @@ -34,6 +34,7 @@ namespace JSC {

#define JSC_VALUE_SLOT_MARKER 0
#define JSC_REGISTER_SLOT_MARKER reinterpret_cast<GetValueFunc>(1)
#define INDEX_GETTER_MARKER reinterpret_cast<GetValueFunc>(2)

class PropertySlot {
public:
Expand All @@ -52,13 +53,16 @@ namespace JSC {
}

typedef JSValue (*GetValueFunc)(ExecState*, const Identifier&, const PropertySlot&);
typedef JSValue (*GetIndexValueFunc)(ExecState*, JSValue slotBase, unsigned);

JSValue getValue(ExecState* exec, const Identifier& propertyName) const
{
if (m_getValue == JSC_VALUE_SLOT_MARKER)
return *m_data.valueSlot;
if (m_getValue == JSC_REGISTER_SLOT_MARKER)
return (*m_data.registerSlot).jsValue();
if (m_getValue == INDEX_GETTER_MARKER)
return m_getIndexValue(exec, slotBase(), index());
return m_getValue(exec, propertyName, *this);
}

Expand All @@ -68,6 +72,8 @@ namespace JSC {
return *m_data.valueSlot;
if (m_getValue == JSC_REGISTER_SLOT_MARKER)
return (*m_data.registerSlot).jsValue();
if (m_getValue == INDEX_GETTER_MARKER)
return m_getIndexValue(exec, m_slotBase, m_data.index);
return m_getValue(exec, Identifier::from(exec, propertyName), *this);
}

Expand Down Expand Up @@ -132,14 +138,16 @@ namespace JSC {
ASSERT(slotBase);
ASSERT(getValue);
m_getValue = getValue;
m_getIndexValue = 0;
m_slotBase = slotBase;
}

void setCustomIndex(JSValue slotBase, unsigned index, GetValueFunc getValue)
void setCustomIndex(JSValue slotBase, unsigned index, GetIndexValueFunc getIndexValue)
{
ASSERT(slotBase);
ASSERT(getValue);
m_getValue = getValue;
ASSERT(getIndexValue);
m_getValue = INDEX_GETTER_MARKER;
m_getIndexValue = getIndexValue;
m_slotBase = slotBase;
m_data.index = index;
}
Expand Down Expand Up @@ -212,6 +220,7 @@ namespace JSC {
static JSValue functionGetter(ExecState*, const Identifier&, const PropertySlot&);

GetValueFunc m_getValue;
GetIndexValueFunc m_getIndexValue;

JSValue m_slotBase;
union {
Expand Down
17 changes: 17 additions & 0 deletions WebCore/ChangeLog
@@ -1,3 +1,20 @@
2010-03-01 Oliver Hunt <oliver@apple.com>

Reviewed by Gavin Barraclough.

PropertySlot::getValue(ExecState, unsigned) unnecessarily converts index to an Identifier
https://bugs.webkit.org/show_bug.cgi?id=35561

Update bindings generation and the few manual indexing getters we have to use
the new PropertySlot API.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::indexGetter):
* bindings/scripts/CodeGeneratorJS.pm:
* bridge/runtime_array.cpp:
(JSC::RuntimeArray::indexGetter):
* bridge/runtime_array.h:

2010-03-01 Chris Fleizach <cfleizach@apple.com>

Reviewed by Darin Adler.
Expand Down
4 changes: 2 additions & 2 deletions WebCore/bindings/js/JSDOMWindowCustom.cpp
Expand Up @@ -134,9 +134,9 @@ static JSValue childFrameGetter(ExecState* exec, const Identifier& propertyName,
return toJS(exec, static_cast<JSDOMWindow*>(asObject(slot.slotBase()))->impl()->frame()->tree()->child(AtomicString(propertyName))->domWindow());
}

static JSValue indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
static JSValue indexGetter(ExecState* exec, JSValue slotBase, unsigned index)
{
return toJS(exec, static_cast<JSDOMWindow*>(asObject(slot.slotBase()))->impl()->frame()->tree()->child(slot.index())->domWindow());
return toJS(exec, static_cast<JSDOMWindow*>(asObject(slotBase))->impl()->frame()->tree()->child(index)->domWindow());
}

static JSValue namedItemGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
Expand Down
10 changes: 5 additions & 5 deletions WebCore/bindings/scripts/CodeGeneratorJS.pm
Expand Up @@ -746,7 +746,7 @@ sub GenerateHeader

# Index getter
if ($dataNode->extendedAttributes->{"HasIndexGetter"}) {
push(@headerContent, " static JSC::JSValue indexGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);\n");
push(@headerContent, " static JSC::JSValue indexGetter(JSC::ExecState*, JSC::JSValue, unsigned);\n");
}
if ($dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
push(@headerContent, " JSC::JSValue getByIndex(JSC::ExecState*, unsigned index);\n");
Expand Down Expand Up @@ -1712,14 +1712,14 @@ sub GenerateImplementation
}

if ($dataNode->extendedAttributes->{"HasIndexGetter"}) {
push(@implContent, "\nJSValue ${className}::indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)\n");
push(@implContent, "\nJSValue ${className}::indexGetter(ExecState* exec, JSValue slotBase, unsigned index)\n");
push(@implContent, "{\n");
push(@implContent, " ${className}* thisObj = static_cast<$className*>(asObject(slot.slotBase()));\n");
push(@implContent, " ${className}* thisObj = static_cast<$className*>(asObject(slotBase));\n");
if (IndexGetterReturnsStrings($implClassName)) {
$implIncludes{"KURL.h"} = 1;
push(@implContent, " return jsStringOrNull(exec, thisObj->impl()->item(slot.index()));\n");
push(@implContent, " return jsStringOrNull(exec, thisObj->impl()->item(index));\n");
} else {
push(@implContent, " return toJS(exec, thisObj->globalObject(), static_cast<$implClassName*>(thisObj->impl())->item(slot.index()));\n");
push(@implContent, " return toJS(exec, thisObj->globalObject(), static_cast<$implClassName*>(thisObj->impl())->item(index));\n");
}
push(@implContent, "}\n");
if ($interfaceName eq "HTMLCollection" or $interfaceName eq "HTMLAllCollection") {
Expand Down
6 changes: 3 additions & 3 deletions WebCore/bridge/runtime_array.cpp
Expand Up @@ -56,10 +56,10 @@ JSValue RuntimeArray::lengthGetter(ExecState* exec, const Identifier&, const Pro
return jsNumber(exec, thisObj->getLength());
}

JSValue RuntimeArray::indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
JSValue RuntimeArray::indexGetter(ExecState* exec, JSValue slotBase, unsigned index)
{
RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slot.slotBase()));
return thisObj->getConcreteArray()->valueAt(exec, slot.index());
RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slotBase));
return thisObj->getConcreteArray()->valueAt(exec, index);
}

void RuntimeArray::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
Expand Down
2 changes: 1 addition & 1 deletion WebCore/bridge/runtime_array.h
Expand Up @@ -62,7 +62,7 @@ class RuntimeArray : public JSArray {
private:
static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | JSObject::StructureFlags;
static JSValue lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
static JSValue indexGetter(ExecState*, const Identifier&, const PropertySlot&);
static JSValue indexGetter(ExecState*, JSValue, unsigned);
};

} // namespace JSC
Expand Down

0 comments on commit 33fbd4f

Please sign in to comment.