From cf93acbee66db96a6f7fab8607432b70ec5c0437 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 24 Jun 2014 12:05:35 +0200 Subject: Exclude private methods and QObject::deleteLater from enumerable properties This is a regression from Qt 5.1/5.0 introduced with 5.2. Private slots/methods such as QObject::_q_reRegisterTimers() as well as QObject::deleteLater() are not suitable for calls from JavaScript. deleteLater() in particular is covered by the destroy() replacement slot. Task-number: QTBUG-39744 Change-Id: I9b25f3c0d4095ba8e2e8e5ee47e37903b5def1f9 Reviewed-by: Michael Brasser --- src/qml/jsruntime/qv4qobjectwrapper.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index a02424a3dc..37956825f8 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -710,6 +710,11 @@ PropertyAttributes QObjectWrapper::query(const Managed *m, StringRef name) void QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, StringRef name, uint *index, Property *p, PropertyAttributes *attributes) { + // Used to block access to QObject::destroyed() and QObject::deleteLater() from QML + static const int destroyedIdx1 = QObject::staticMetaObject.indexOfSignal("destroyed(QObject*)"); + static const int destroyedIdx2 = QObject::staticMetaObject.indexOfSignal("destroyed()"); + static const int deleteLaterIdx = QObject::staticMetaObject.indexOfSlot("deleteLater()"); + name = (String *)0; *index = UINT_MAX; @@ -726,9 +731,13 @@ void QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, StringRef n return; } const int methodCount = mo->methodCount(); - if (it->arrayIndex < static_cast(propertyCount + methodCount)) { - name = that->engine()->newString(QString::fromUtf8(mo->method(it->arrayIndex - propertyCount).name())); + while (it->arrayIndex < static_cast(propertyCount + methodCount)) { + const int index = it->arrayIndex - propertyCount; + const QMetaMethod method = mo->method(index); ++it->arrayIndex; + if (method.access() == QMetaMethod::Private || index == deleteLaterIdx || index == destroyedIdx1 || index == destroyedIdx2) + continue; + name = that->engine()->newString(QString::fromUtf8(method.name())); *attributes = QV4::Attr_Data; p->value = that->get(name); return; -- cgit v1.2.3