Changeset 53930 in webkit


Ignore:
Timestamp:
Jan 27, 2010 6:25:11 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-27 Kent Hansen <kent.hansen@nokia.com>

Reviewed by Simon Hausmann.

[Qt] Meta-methods can't be introspected using ES5 API
https://bugs.webkit.org/show_bug.cgi?id=34087

Add getOwnPropertyDescriptor() and getOwnPropertyNames() reimplementations.

Tests are in WebKit/qt/tests/qwebframe

  • bridge/qt/qt_runtime.cpp: (JSC::Bindings::QtRuntimeMetaMethod::getOwnPropertyDescriptor): (JSC::Bindings::QtRuntimeMetaMethod::getOwnPropertyNames): (JSC::Bindings::QtRuntimeConnectionMethod::getOwnPropertyDescriptor): (JSC::Bindings::QtRuntimeConnectionMethod::getOwnPropertyNames):
  • bridge/qt/qt_runtime.h:

2010-01-27 Kent Hansen <kent.hansen@nokia.com>

Reviewed by Simon Hausmann.

[Qt] Meta-methods can't be introspected using ES5 API
https://bugs.webkit.org/show_bug.cgi?id=34087

Test that Object.getOwnPropertyDescriptor and
Object.getOwnPropertyNames work with meta-methods.

  • tests/qwebframe/tst_qwebframe.cpp:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r53927 r53930  
     12010-01-27  Kent Hansen  <kent.hansen@nokia.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] Meta-methods can't be introspected using ES5 API
     6        https://bugs.webkit.org/show_bug.cgi?id=34087
     7
     8        Add getOwnPropertyDescriptor() and getOwnPropertyNames() reimplementations.
     9
     10        Tests are in WebKit/qt/tests/qwebframe
     11
     12        * bridge/qt/qt_runtime.cpp:
     13        (JSC::Bindings::QtRuntimeMetaMethod::getOwnPropertyDescriptor):
     14        (JSC::Bindings::QtRuntimeMetaMethod::getOwnPropertyNames):
     15        (JSC::Bindings::QtRuntimeConnectionMethod::getOwnPropertyDescriptor):
     16        (JSC::Bindings::QtRuntimeConnectionMethod::getOwnPropertyNames):
     17        * bridge/qt/qt_runtime.h:
     18
    1192010-01-27  Tony Chang  <tony@chromium.org>
    220
  • trunk/WebCore/bridge/qt/qt_runtime.cpp

    r53611 r53930  
    14011401}
    14021402
     1403bool QtRuntimeMetaMethod::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
     1404{
     1405    if (propertyName == "connect") {
     1406        PropertySlot slot;
     1407        slot.setCustom(this, connectGetter);
     1408        descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly | DontEnum);
     1409        return true;
     1410    }
     1411
     1412    if (propertyName == "disconnect") {
     1413        PropertySlot slot;
     1414        slot.setCustom(this, disconnectGetter);
     1415        descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly | DontEnum);
     1416        return true;
     1417    }
     1418
     1419    if (propertyName == exec->propertyNames().length) {
     1420        PropertySlot slot;
     1421        slot.setCustom(this, lengthGetter);
     1422        descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly | DontEnum);
     1423        return true;
     1424    }
     1425
     1426    return QtRuntimeMethod::getOwnPropertyDescriptor(exec, propertyName, descriptor);
     1427}
     1428
     1429void QtRuntimeMetaMethod::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
     1430{
     1431    if (mode == IncludeDontEnumProperties) {
     1432        propertyNames.add(Identifier(exec, "connect"));
     1433        propertyNames.add(Identifier(exec, "disconnect"));
     1434        propertyNames.add(exec->propertyNames().length);
     1435    }
     1436
     1437    QtRuntimeMethod::getOwnPropertyNames(exec, propertyNames, mode);
     1438}
     1439
    14031440JSValue QtRuntimeMetaMethod::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot&)
    14041441{
     
    15851622
    15861623    return QtRuntimeMethod::getOwnPropertySlot(exec, propertyName, slot);
     1624}
     1625
     1626bool QtRuntimeConnectionMethod::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
     1627{
     1628    if (propertyName == exec->propertyNames().length) {
     1629        PropertySlot slot;
     1630        slot.setCustom(this, lengthGetter);
     1631        descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly | DontEnum);
     1632        return true;
     1633    }
     1634
     1635    return QtRuntimeMethod::getOwnPropertyDescriptor(exec, propertyName, descriptor);
     1636}
     1637
     1638void QtRuntimeConnectionMethod::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
     1639{
     1640    if (mode == IncludeDontEnumProperties)
     1641        propertyNames.add(exec->propertyNames().length);
     1642
     1643    QtRuntimeMethod::getOwnPropertyNames(exec, propertyNames, mode);
    15871644}
    15881645
  • trunk/WebCore/bridge/qt/qt_runtime.h

    r53464 r53930  
    156156
    157157protected:
    158     static const unsigned StructureFlags = OverridesGetOwnPropertySlot | InternalFunction::StructureFlags | OverridesMarkChildren;
     158    static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | InternalFunction::StructureFlags | OverridesMarkChildren;
    159159
    160160    QtRuntimeMethodData *d_func() const {return d_ptr;}
     
    169169
    170170    virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
     171    virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
     172    virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
    171173
    172174    virtual void markChildren(MarkStack& markStack);
     
    190192
    191193    virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
     194    virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
     195    virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
    192196
    193197protected:
  • trunk/WebKit/qt/ChangeLog

    r53851 r53930  
     12010-01-27  Kent Hansen  <kent.hansen@nokia.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] Meta-methods can't be introspected using ES5 API
     6        https://bugs.webkit.org/show_bug.cgi?id=34087
     7
     8        Test that Object.getOwnPropertyDescriptor and
     9        Object.getOwnPropertyNames work with meta-methods.
     10
     11        * tests/qwebframe/tst_qwebframe.cpp:
     12
    1132010-01-26  Simon Hausmann  <simon.hausmann@nokia.com>
    214
  • trunk/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r52444 r53930  
    574574    void qObjectWrapperWithSameIdentity();
    575575    void scrollRecursively();
     576    void introspectQtMethods_data();
     577    void introspectQtMethods();
    576578
    577579private:
     
    28622864}
    28632865
     2866void tst_QWebFrame::introspectQtMethods_data()
     2867{
     2868    QTest::addColumn<QString>("objectExpression");
     2869    QTest::addColumn<QString>("methodName");
     2870    QTest::addColumn<QStringList>("expectedPropertyNames");
     2871
     2872    QTest::newRow("myObject.mySignal")
     2873        << "myObject" << "mySignal" << (QStringList() << "connect" << "disconnect" << "length" << "name");
     2874    QTest::newRow("myObject.mySlot")
     2875        << "myObject" << "mySlot" << (QStringList() << "connect" << "disconnect" << "length" << "name");
     2876    QTest::newRow("myObject.myInvokable")
     2877        << "myObject" << "myInvokable" << (QStringList() << "connect" << "disconnect" << "length" << "name");
     2878    QTest::newRow("myObject.mySignal.connect")
     2879        << "myObject.mySignal" << "connect" << (QStringList() << "length" << "name");
     2880    QTest::newRow("myObject.mySignal.disconnect")
     2881        << "myObject.mySignal" << "disconnect" << (QStringList() << "length" << "name");
     2882}
     2883
     2884void tst_QWebFrame::introspectQtMethods()
     2885{
     2886    QFETCH(QString, objectExpression);
     2887    QFETCH(QString, methodName);
     2888    QFETCH(QStringList, expectedPropertyNames);
     2889
     2890    QString methodLookup = QString::fromLatin1("%0['%1']").arg(objectExpression).arg(methodName);
     2891    QCOMPARE(evalJSV(QString::fromLatin1("Object.getOwnPropertyNames(%0).sort()").arg(methodLookup)).toStringList(), expectedPropertyNames);
     2892
     2893    for (int i = 0; i < expectedPropertyNames.size(); ++i) {
     2894        QString name = expectedPropertyNames.at(i);
     2895        QCOMPARE(evalJS(QString::fromLatin1("%0.hasOwnProperty('%1')").arg(methodLookup).arg(name)), sTrue);
     2896        evalJS(QString::fromLatin1("var descriptor = Object.getOwnPropertyDescriptor(%0, '%1')").arg(methodLookup).arg(name));
     2897        QCOMPARE(evalJS("typeof descriptor"), QString::fromLatin1("object"));
     2898        QCOMPARE(evalJS("descriptor.get"), sUndefined);
     2899        QCOMPARE(evalJS("descriptor.set"), sUndefined);
     2900        QCOMPARE(evalJS(QString::fromLatin1("descriptor.value === %0['%1']").arg(methodLookup).arg(name)), sTrue);
     2901        QCOMPARE(evalJS(QString::fromLatin1("descriptor.enumerable")), sFalse);
     2902        QCOMPARE(evalJS(QString::fromLatin1("descriptor.configurable")), sFalse);
     2903    }
     2904
     2905    QVERIFY(evalJSV("var props=[]; for (var p in myObject.deleteLater) {props.push(p);}; props.sort()").toStringList().isEmpty());
     2906}
     2907
    28642908QTEST_MAIN(tst_QWebFrame)
    28652909#include "tst_qwebframe.moc"
Note: See TracChangeset for help on using the changeset viewer.