| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4qobjectwrapper_p.h |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 24 | ** | - | ||||||
| 25 | ** GNU General Public License Usage | - | ||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 35 | ** | - | ||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||
| 37 | ** | - | ||||||
| 38 | ****************************************************************************/ | - | ||||||
| 39 | - | |||||||
| 40 | #ifndef QV4QOBJECTWRAPPER_P_H | - | ||||||
| 41 | #define QV4QOBJECTWRAPPER_P_H | - | ||||||
| 42 | - | |||||||
| 43 | // | - | ||||||
| 44 | // W A R N I N G | - | ||||||
| 45 | // ------------- | - | ||||||
| 46 | // | - | ||||||
| 47 | // This file is not part of the Qt API. It exists purely as an | - | ||||||
| 48 | // implementation detail. This header file may change from version to | - | ||||||
| 49 | // version without notice, or even be removed. | - | ||||||
| 50 | // | - | ||||||
| 51 | // We mean it. | - | ||||||
| 52 | // | - | ||||||
| 53 | - | |||||||
| 54 | #include <QtCore/qglobal.h> | - | ||||||
| 55 | #include <QtCore/qmetatype.h> | - | ||||||
| 56 | #include <QtCore/qpair.h> | - | ||||||
| 57 | #include <QtCore/qhash.h> | - | ||||||
| 58 | #include <private/qhashedstring_p.h> | - | ||||||
| 59 | #include <private/qqmldata_p.h> | - | ||||||
| 60 | #include <private/qqmlpropertycache_p.h> | - | ||||||
| 61 | #include <private/qintrusivelist_p.h> | - | ||||||
| 62 | - | |||||||
| 63 | #include <private/qv4value_p.h> | - | ||||||
| 64 | #include <private/qv4functionobject_p.h> | - | ||||||
| 65 | - | |||||||
| 66 | QT_BEGIN_NAMESPACE | - | ||||||
| 67 | - | |||||||
| 68 | class QObject; | - | ||||||
| 69 | class QQmlData; | - | ||||||
| 70 | class QQmlPropertyCache; | - | ||||||
| 71 | class QQmlPropertyData; | - | ||||||
| 72 | - | |||||||
| 73 | namespace QV4 { | - | ||||||
| 74 | struct QObjectSlotDispatcher; | - | ||||||
| 75 | - | |||||||
| 76 | namespace Heap { | - | ||||||
| 77 | - | |||||||
| 78 | struct QQmlValueTypeWrapper; | - | ||||||
| 79 | - | |||||||
| 80 | struct Q_QML_EXPORT QObjectWrapper : Object { | - | ||||||
| 81 | void init(QObject *object) | - | ||||||
| 82 | { | - | ||||||
| 83 | Object::init(); | - | ||||||
| 84 | qObj.init(object); | - | ||||||
| 85 | } executed 536134 times by 141 tests: end of blockExecuted by:
| 536134 | ||||||
| 86 | - | |||||||
| 87 | void destroy() { | - | ||||||
| 88 | qObj.destroy(); | - | ||||||
| 89 | Object::destroy(); | - | ||||||
| 90 | } executed 535986 times by 141 tests: end of blockExecuted by:
| 535986 | ||||||
| 91 | - | |||||||
| 92 | QObject *object() const { return qObj.data(); } executed 13947464 times by 141 tests: return qObj.data();Executed by:
| 13947464 | ||||||
| 93 | static void markObjects(Heap::Base *that, MarkStack *markStack); | - | ||||||
| 94 | - | |||||||
| 95 | private: | - | ||||||
| 96 | QQmlQPointer<QObject> qObj; | - | ||||||
| 97 | }; | - | ||||||
| 98 | - | |||||||
| 99 | #define QObjectMethodMembers(class, Member) \ | - | ||||||
| 100 | Member(class, Pointer, QQmlValueTypeWrapper *, valueTypeWrapper) \ | - | ||||||
| 101 | Member(class, NoMark, QQmlQPointer<QObject>, qObj) \ | - | ||||||
| 102 | Member(class, NoMark, QQmlPropertyCache *, _propertyCache) \ | - | ||||||
| 103 | Member(class, NoMark, int, index) | - | ||||||
| 104 | - | |||||||
| 105 | DECLARE_HEAP_OBJECT(QObjectMethod, FunctionObject) { | - | ||||||
| 106 | DECLARE_MARKOBJECTS(QObjectMethod); executed 104 times by 5 tests: end of blockExecuted by:
never executed: o->valueTypeWrapper.heapObject()->mark(stack);
| 0-104 | ||||||
| 107 | - | |||||||
| 108 | void init(QV4::ExecutionContext *scope); | - | ||||||
| 109 | void destroy() | - | ||||||
| 110 | { | - | ||||||
| 111 | setPropertyCache(nullptr); | - | ||||||
| 112 | qObj.destroy(); | - | ||||||
| 113 | FunctionObject::destroy(); | - | ||||||
| 114 | } executed 68114 times by 62 tests: end of blockExecuted by:
| 68114 | ||||||
| 115 | - | |||||||
| 116 | QQmlPropertyCache *propertyCache() const { return _propertyCache; } executed 130504 times by 56 tests: return _propertyCache;Executed by:
| 130504 | ||||||
| 117 | void setPropertyCache(QQmlPropertyCache *c) { | - | ||||||
| 118 | if (c)
| 65298-70976 | ||||||
| 119 | c->addref(); executed 65298 times by 61 tests: c->addref();Executed by:
| 65298 | ||||||
| 120 | if (_propertyCache)
| 65252-71022 | ||||||
| 121 | _propertyCache->release(); executed 65252 times by 61 tests: _propertyCache->release();Executed by:
| 65252 | ||||||
| 122 | _propertyCache = c; | - | ||||||
| 123 | } executed 136274 times by 62 tests: end of blockExecuted by:
| 136274 | ||||||
| 124 | - | |||||||
| 125 | const QMetaObject *metaObject(); | - | ||||||
| 126 | QObject *object() const { return qObj.data(); } executed 132492 times by 62 tests: return qObj.data();Executed by:
| 132492 | ||||||
| 127 | void setObject(QObject *o) { qObj = o; } executed 67816 times by 62 tests: end of blockExecuted by:
| 67816 | ||||||
| 128 | - | |||||||
| 129 | }; | - | ||||||
| 130 | - | |||||||
| 131 | struct QMetaObjectWrapper : FunctionObject { | - | ||||||
| 132 | const QMetaObject* metaObject; | - | ||||||
| 133 | QQmlPropertyData *constructors; | - | ||||||
| 134 | int constructorCount; | - | ||||||
| 135 | - | |||||||
| 136 | void init(const QMetaObject* metaObject); | - | ||||||
| 137 | void destroy(); | - | ||||||
| 138 | void ensureConstructorsCache(); | - | ||||||
| 139 | }; | - | ||||||
| 140 | - | |||||||
| 141 | struct QmlSignalHandler : Object { | - | ||||||
| 142 | void init(QObject *object, int signalIndex); | - | ||||||
| 143 | void destroy() { | - | ||||||
| 144 | qObj.destroy(); | - | ||||||
| 145 | Object::destroy(); | - | ||||||
| 146 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||
| 147 | int signalIndex; | - | ||||||
| 148 | - | |||||||
| 149 | QObject *object() const { return qObj.data(); } executed 10 times by 1 test: return qObj.data();Executed by:
| 10 | ||||||
| 150 | void setObject(QObject *o) { qObj = o; } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||
| 151 | - | |||||||
| 152 | private: | - | ||||||
| 153 | QQmlQPointer<QObject> qObj; | - | ||||||
| 154 | }; | - | ||||||
| 155 | - | |||||||
| 156 | } | - | ||||||
| 157 | - | |||||||
| 158 | struct Q_QML_EXPORT QObjectWrapper : public Object | - | ||||||
| 159 | { | - | ||||||
| 160 | V4_OBJECT2(QObjectWrapper, Object) executed 12965255 times by 153 tests: end of blockExecuted by:
never executed: end of blockexecuted 19292649 times by 153 tests: return &static_vtbl;Executed by:
executed 13815737 times by 141 tests: return static_cast<QV4::Heap::QObjectWrapper *>(m());Executed by:
executed 13729819 times by 141 tests: return dptr;Executed by:
| 0-19292649 | ||||||
| 161 | V4_NEEDS_DESTROY executed 535326 times by 141 tests: end of blockExecuted by:
| 535326 | ||||||
| 162 | - | |||||||
| 163 | enum RevisionMode { IgnoreRevision, CheckRevision }; | - | ||||||
| 164 | - | |||||||
| 165 | static void initializeBindings(ExecutionEngine *engine); | - | ||||||
| 166 | - | |||||||
| 167 | QObject *object() const { return d()->object(); } executed 453323 times by 111 tests: return d()->object();Executed by:
| 453323 | ||||||
| 168 | - | |||||||
| 169 | ReturnedValue getQmlProperty(QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, bool *hasProperty = nullptr, bool includeImports = false) const; | - | ||||||
| 170 | static ReturnedValue getQmlProperty(ExecutionEngine *engine, QQmlContextData *qmlContext, QObject *object, String *name, RevisionMode revisionMode, bool *hasProperty = nullptr); | - | ||||||
| 171 | - | |||||||
| 172 | static bool setQmlProperty(ExecutionEngine *engine, QQmlContextData *qmlContext, QObject *object, String *name, RevisionMode revisionMode, const Value &value); | - | ||||||
| 173 | - | |||||||
| 174 | static ReturnedValue wrap(ExecutionEngine *engine, QObject *object); | - | ||||||
| 175 | static void markWrapper(QObject *object, MarkStack *markStack); | - | ||||||
| 176 | - | |||||||
| 177 | using Object::get; | - | ||||||
| 178 | - | |||||||
| 179 | static ReturnedValue getProperty(ExecutionEngine *engine, QObject *object, int propertyIndex, bool captureRequired); | - | ||||||
| 180 | static void setProperty(ExecutionEngine *engine, QObject *object, int propertyIndex, const Value &value); | - | ||||||
| 181 | void setProperty(ExecutionEngine *engine, int propertyIndex, const Value &value); | - | ||||||
| 182 | - | |||||||
| 183 | void destroyObject(bool lastCall); | - | ||||||
| 184 | - | |||||||
| 185 | protected: | - | ||||||
| 186 | static bool virtualIsEqualTo(Managed *that, Managed *o); | - | ||||||
| 187 | - | |||||||
| 188 | static ReturnedValue getProperty(ExecutionEngine *engine, QObject *object, QQmlPropertyData *property, bool captureRequired = true); | - | ||||||
| 189 | static void setProperty(ExecutionEngine *engine, QObject *object, QQmlPropertyData *property, const Value &value); | - | ||||||
| 190 | - | |||||||
| 191 | static ReturnedValue create(ExecutionEngine *engine, QObject *object); | - | ||||||
| 192 | - | |||||||
| 193 | static QQmlPropertyData *findProperty(ExecutionEngine *engine, QObject *o, QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, QQmlPropertyData *local); | - | ||||||
| 194 | QQmlPropertyData *findProperty(ExecutionEngine *engine, QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, QQmlPropertyData *local) const; | - | ||||||
| 195 | - | |||||||
| 196 | static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); | - | ||||||
| 197 | static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); | - | ||||||
| 198 | static PropertyAttributes virtualGetOwnProperty(Managed *m, PropertyKey id, Property *p); | - | ||||||
| 199 | static void virtualAdvanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); | - | ||||||
| 200 | - | |||||||
| 201 | static ReturnedValue method_connect(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); | - | ||||||
| 202 | static ReturnedValue method_disconnect(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); | - | ||||||
| 203 | - | |||||||
| 204 | private: | - | ||||||
| 205 | Q_NEVER_INLINE static ReturnedValue wrap_slowPath(ExecutionEngine *engine, QObject *object); | - | ||||||
| 206 | }; | - | ||||||
| 207 | - | |||||||
| 208 | inline ReturnedValue QObjectWrapper::wrap(ExecutionEngine *engine, QObject *object) | - | ||||||
| 209 | { | - | ||||||
| 210 | if (Q_UNLIKELY(QQmlData::wasDeleted(object)))
| 677-8143104 | ||||||
| 211 | return QV4::Encode::null(); executed 677 times by 30 tests: return QV4::Encode::null();Executed by:
| 677 | ||||||
| 212 | - | |||||||
| 213 | auto ddata = QQmlData::get(object); | - | ||||||
| 214 | if (Q_LIKELY(ddata && ddata->jsEngineId == engine->m_engineId && !ddata->jsWrapper.isUndefined())) {
| 535050-7608054 | ||||||
| 215 | // We own the JS object | - | ||||||
| 216 | return ddata->jsWrapper.value(); executed 7608054 times by 134 tests: return ddata->jsWrapper.value();Executed by:
| 7608054 | ||||||
| 217 | } | - | ||||||
| 218 | - | |||||||
| 219 | return wrap_slowPath(engine, object); executed 535050 times by 141 tests: return wrap_slowPath(engine, object);Executed by:
| 535050 | ||||||
| 220 | } | - | ||||||
| 221 | - | |||||||
| 222 | struct QQmlValueTypeWrapper; | - | ||||||
| 223 | - | |||||||
| 224 | struct Q_QML_EXPORT QObjectMethod : public QV4::FunctionObject | - | ||||||
| 225 | { | - | ||||||
| 226 | V4_OBJECT2(QObjectMethod, QV4::FunctionObject) executed 1006 times by 6 tests: end of blockExecuted by:
never executed: end of blockexecuted 205854 times by 62 tests: return &static_vtbl;Executed by:
executed 800254 times by 62 tests: return static_cast<QV4::Heap::QObjectMethod *>(m());Executed by:
executed 732094 times by 62 tests: return dptr;Executed by:
| 0-800254 | ||||||
| 227 | V4_NEEDS_DESTROY executed 68114 times by 62 tests: end of blockExecuted by:
| 68114 | ||||||
| 228 | - | |||||||
| 229 | enum { DestroyMethod = -1, ToStringMethod = -2 }; | - | ||||||
| 230 | - | |||||||
| 231 | static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index); | - | ||||||
| 232 | static ReturnedValue create(QV4::ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index); | - | ||||||
| 233 | - | |||||||
| 234 | int methodIndex() const { return d()->index; } executed 636 times by 6 tests: return d()->index;Executed by:
| 636 | ||||||
| 235 | QObject *object() const { return d()->object(); } executed 636 times by 6 tests: return d()->object();Executed by:
| 636 | ||||||
| 236 | - | |||||||
| 237 | QV4::ReturnedValue method_toString(QV4::ExecutionEngine *engine) const; | - | ||||||
| 238 | QV4::ReturnedValue method_destroy(QV4::ExecutionEngine *ctx, const Value *args, int argc) const; | - | ||||||
| 239 | - | |||||||
| 240 | static ReturnedValue virtualCall(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); | - | ||||||
| 241 | - | |||||||
| 242 | ReturnedValue callInternal(const Value *thisObject, const Value *argv, int argc) const; | - | ||||||
| 243 | - | |||||||
| 244 | static QPair<QObject *, int> extractQtMethod(const QV4::FunctionObject *function); | - | ||||||
| 245 | }; | - | ||||||
| 246 | - | |||||||
| 247 | - | |||||||
| 248 | struct Q_QML_EXPORT QMetaObjectWrapper : public QV4::FunctionObject | - | ||||||
| 249 | { | - | ||||||
| 250 | V4_OBJECT2(QMetaObjectWrapper, QV4::FunctionObject) executed 12 times by 1 test: end of blockExecuted by:
never executed: end of blockexecuted 30 times by 1 test: return &static_vtbl;Executed by:
executed 94 times by 1 test: return static_cast<QV4::Heap::QMetaObjectWrapper *>(m());Executed by:
executed 88 times by 1 test: return dptr;Executed by:
| 0-94 | ||||||
| 251 | V4_NEEDS_DESTROY executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||
| 252 | - | |||||||
| 253 | static ReturnedValue create(ExecutionEngine *engine, const QMetaObject* metaObject); | - | ||||||
| 254 | const QMetaObject *metaObject() const { return d()->metaObject; } | - | ||||||
| 255 | - | |||||||
| 256 | protected: | - | ||||||
| 257 | static ReturnedValue virtualCallAsConstructor(const FunctionObject *, const Value *argv, int argc, const Value *); | - | ||||||
| 258 | static bool virtualIsEqualTo(Managed *a, Managed *b); | - | ||||||
| 259 | - | |||||||
| 260 | private: | - | ||||||
| 261 | void init(ExecutionEngine *engine); | - | ||||||
| 262 | ReturnedValue constructInternal(const Value *argv, int argc) const; | - | ||||||
| 263 | ReturnedValue callConstructor(const QQmlPropertyData &data, QV4::ExecutionEngine *engine, QV4::CallData *callArgs) const; | - | ||||||
| 264 | ReturnedValue callOverloadedConstructor(QV4::ExecutionEngine *engine, QV4::CallData *callArgs) const; | - | ||||||
| 265 | - | |||||||
| 266 | }; | - | ||||||
| 267 | - | |||||||
| 268 | struct Q_QML_EXPORT QmlSignalHandler : public QV4::Object | - | ||||||
| 269 | { | - | ||||||
| 270 | V4_OBJECT2(QmlSignalHandler, QV4::Object) executed 10 times by 1 test: end of blockExecuted by:
never executed: end of blockexecuted 52 times by 1 test: return &static_vtbl;Executed by:
executed 48 times by 1 test: return static_cast<QV4::Heap::QmlSignalHandler *>(m());Executed by:
executed 34 times by 1 test: return dptr;Executed by:
| 0-52 | ||||||
| 271 | V4_PROTOTYPE(signalHandlerPrototype) executed 14 times by 1 test: return e->signalHandlerPrototype();Executed by:
| 14 | ||||||
| 272 | V4_NEEDS_DESTROY executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||
| 273 | - | |||||||
| 274 | int signalIndex() const { return d()->signalIndex; } executed 10 times by 1 test: return d()->signalIndex;Executed by:
| 10 | ||||||
| 275 | QObject *object() const { return d()->object(); } executed 10 times by 1 test: return d()->object();Executed by:
| 10 | ||||||
| 276 | - | |||||||
| 277 | static void initProto(ExecutionEngine *v4); | - | ||||||
| 278 | }; | - | ||||||
| 279 | - | |||||||
| 280 | class MultiplyWrappedQObjectMap : public QObject, | - | ||||||
| 281 | private QHash<QObject*, QV4::WeakValue> | - | ||||||
| 282 | { | - | ||||||
| 283 | Q_OBJECT | - | ||||||
| 284 | public: | - | ||||||
| 285 | typedef QHash<QObject*, QV4::WeakValue>::ConstIterator ConstIterator; | - | ||||||
| 286 | typedef QHash<QObject*, QV4::WeakValue>::Iterator Iterator; | - | ||||||
| 287 | - | |||||||
| 288 | ConstIterator begin() const { return QHash<QObject*, QV4::WeakValue>::constBegin(); } never executed: return QHash<QObject*, QV4::WeakValue>::constBegin(); | 0 | ||||||
| 289 | Iterator begin() { return QHash<QObject*, QV4::WeakValue>::begin(); } never executed: return QHash<QObject*, QV4::WeakValue>::begin(); | 0 | ||||||
| 290 | ConstIterator end() const { return QHash<QObject*, QV4::WeakValue>::constEnd(); } never executed: return QHash<QObject*, QV4::WeakValue>::constEnd(); | 0 | ||||||
| 291 | Iterator end() { return QHash<QObject*, QV4::WeakValue>::end(); } never executed: return QHash<QObject*, QV4::WeakValue>::end(); | 0 | ||||||
| 292 | - | |||||||
| 293 | void insert(QObject *key, Heap::Object *value); | - | ||||||
| 294 | ReturnedValue value(QObject *key) const { return QHash<QObject*, QV4::WeakValue>::value(key).value(); } never executed: return QHash<QObject*, QV4::WeakValue>::value(key).value(); | 0 | ||||||
| 295 | Iterator erase(Iterator it); | - | ||||||
| 296 | void remove(QObject *key); | - | ||||||
| 297 | void mark(QObject *key, MarkStack *markStack); | - | ||||||
| 298 | - | |||||||
| 299 | private Q_SLOTS: | - | ||||||
| 300 | void removeDestroyedObject(QObject*); | - | ||||||
| 301 | }; | - | ||||||
| 302 | - | |||||||
| 303 | } | - | ||||||
| 304 | - | |||||||
| 305 | QT_END_NAMESPACE | - | ||||||
| 306 | - | |||||||
| 307 | #endif // QV4QOBJECTWRAPPER_P_H | - | ||||||
| 308 | - | |||||||
| 309 | - | |||||||
| Source code | Switch to Preprocessed file |