| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsapi/qjsengine.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 QJSENGINE_H | - | ||||||
| 41 | #define QJSENGINE_H | - | ||||||
| 42 | - | |||||||
| 43 | #include <QtCore/qmetatype.h> | - | ||||||
| 44 | - | |||||||
| 45 | #include <QtCore/qvariant.h> | - | ||||||
| 46 | #include <QtCore/qsharedpointer.h> | - | ||||||
| 47 | #include <QtCore/qobject.h> | - | ||||||
| 48 | #include <QtQml/qjsvalue.h> | - | ||||||
| 49 | - | |||||||
| 50 | #include <QtQml/qqmldebug.h> | - | ||||||
| 51 | - | |||||||
| 52 | QT_BEGIN_NAMESPACE | - | ||||||
| 53 | - | |||||||
| 54 | - | |||||||
| 55 | template <typename T> | - | ||||||
| 56 | inline T qjsvalue_cast(const QJSValue &); | - | ||||||
| 57 | - | |||||||
| 58 | class QJSEnginePrivate; | - | ||||||
| 59 | class Q_QML_EXPORT QJSEngine | - | ||||||
| 60 | : public QObject | - | ||||||
| 61 | { | - | ||||||
| 62 | Q_OBJECT | - | ||||||
| 63 | public: | - | ||||||
| 64 | QJSEngine(); | - | ||||||
| 65 | explicit QJSEngine(QObject *parent); | - | ||||||
| 66 | ~QJSEngine() override; | - | ||||||
| 67 | - | |||||||
| 68 | QJSValue globalObject() const; | - | ||||||
| 69 | - | |||||||
| 70 | QJSValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1); | - | ||||||
| 71 | - | |||||||
| 72 | QJSValue newObject(); | - | ||||||
| 73 | QJSValue newArray(uint length = 0); | - | ||||||
| 74 | - | |||||||
| 75 | QJSValue newQObject(QObject *object); | - | ||||||
| 76 | - | |||||||
| 77 | QJSValue newQMetaObject(const QMetaObject* metaObject); | - | ||||||
| 78 | - | |||||||
| 79 | template <typename T> | - | ||||||
| 80 | QJSValue newQMetaObject() | - | ||||||
| 81 | { | - | ||||||
| 82 | return newQMetaObject(&T::staticMetaObject); executed 2 times by 1 test: return newQMetaObject(&T::staticMetaObject);Executed by:
| 2 | ||||||
| 83 | } | - | ||||||
| 84 | - | |||||||
| 85 | template <typename T> | - | ||||||
| 86 | inline QJSValue toScriptValue(const T &value) | - | ||||||
| 87 | { | - | ||||||
| 88 | return create(qMetaTypeId<T>(), &value); executed 48668 times by 5 tests: return create(qMetaTypeId<T>(), &value);Executed by:
| 48668 | ||||||
| 89 | } | - | ||||||
| 90 | template <typename T> | - | ||||||
| 91 | inline T fromScriptValue(const QJSValue &value) | - | ||||||
| 92 | { | - | ||||||
| 93 | return qjsvalue_cast<T>(value); executed 52 times by 2 tests: return qjsvalue_cast<T>(value);Executed by:
| 52 | ||||||
| 94 | } | - | ||||||
| 95 | - | |||||||
| 96 | void collectGarbage(); | - | ||||||
| 97 | - | |||||||
| 98 | #if QT_DEPRECATED_SINCE(5, 6) | - | ||||||
| 99 | QT_DEPRECATED void installTranslatorFunctions(const QJSValue &object = QJSValue()); | - | ||||||
| 100 | #endif | - | ||||||
| 101 | - | |||||||
| 102 | enum Extension { | - | ||||||
| 103 | TranslationExtension = 0x1, | - | ||||||
| 104 | ConsoleExtension = 0x2, | - | ||||||
| 105 | GarbageCollectionExtension = 0x4, | - | ||||||
| 106 | AllExtensions = 0xffffffff | - | ||||||
| 107 | }; | - | ||||||
| 108 | Q_DECLARE_FLAGS(Extensions, Extension) | - | ||||||
| 109 | - | |||||||
| 110 | void installExtensions(Extensions extensions, const QJSValue &object = QJSValue()); | - | ||||||
| 111 | - | |||||||
| 112 | QV4::ExecutionEngine *handle() const { return m_v4Engine; } executed 10437358 times by 144 tests: return m_v4Engine;Executed by:
| 10437358 | ||||||
| 113 | - | |||||||
| 114 | void throwError(const QString &message); | - | ||||||
| 115 | - | |||||||
| 116 | private: | - | ||||||
| 117 | QJSValue create(int type, const void *ptr); | - | ||||||
| 118 | - | |||||||
| 119 | static bool convertV2(const QJSValue &value, int type, void *ptr); | - | ||||||
| 120 | - | |||||||
| 121 | friend inline bool qjsvalue_cast_helper(const QJSValue &, int, void *); | - | ||||||
| 122 | - | |||||||
| 123 | protected: | - | ||||||
| 124 | QJSEngine(QJSEnginePrivate &dd, QObject *parent = nullptr); | - | ||||||
| 125 | - | |||||||
| 126 | private: | - | ||||||
| 127 | QV4::ExecutionEngine *m_v4Engine; | - | ||||||
| 128 | Q_DISABLE_COPY(QJSEngine) | - | ||||||
| 129 | Q_DECLARE_PRIVATE(QJSEngine) executed 473962 times by 60 tests: return reinterpret_cast<QJSEnginePrivate *>(qGetPtrHelper(d_ptr));Executed by:
never executed: return reinterpret_cast<const QJSEnginePrivate *>(qGetPtrHelper(d_ptr)); | 0-473962 | ||||||
| 130 | }; | - | ||||||
| 131 | - | |||||||
| 132 | Q_DECLARE_OPERATORS_FOR_FLAGS(QJSEngine::Extensions) | - | ||||||
| 133 | - | |||||||
| 134 | inline bool qjsvalue_cast_helper(const QJSValue &value, int type, void *ptr) | - | ||||||
| 135 | { | - | ||||||
| 136 | return QJSEngine::convertV2(value, type, ptr); executed 482 times by 4 tests: return QJSEngine::convertV2(value, type, ptr);Executed by:
| 482 | ||||||
| 137 | } | - | ||||||
| 138 | - | |||||||
| 139 | template<typename T> | - | ||||||
| 140 | T qjsvalue_cast(const QJSValue &value) | - | ||||||
| 141 | { | - | ||||||
| 142 | T t; | - | ||||||
| 143 | const int id = qMetaTypeId<T>(); | - | ||||||
| 144 | - | |||||||
| 145 | if (qjsvalue_cast_helper(value, id, &t))
| 54-428 | ||||||
| 146 | return t; executed 428 times by 4 tests: return t;Executed by:
| 428 | ||||||
| 147 | else if (value.isVariant())
| 4-50 | ||||||
| 148 | return qvariant_cast<T>(value.toVariant()); executed 4 times by 1 test: return qvariant_cast<T>(value.toVariant());Executed by:
| 4 | ||||||
| 149 | - | |||||||
| 150 | return T(); executed 50 times by 1 test: return T();Executed by:
| 50 | ||||||
| 151 | } | - | ||||||
| 152 | - | |||||||
| 153 | template <> | - | ||||||
| 154 | inline QVariant qjsvalue_cast<QVariant>(const QJSValue &value) | - | ||||||
| 155 | { | - | ||||||
| 156 | return value.toVariant(); executed 30 times by 2 tests: return value.toVariant();Executed by:
| 30 | ||||||
| 157 | } | - | ||||||
| 158 | - | |||||||
| 159 | Q_QML_EXPORT QJSEngine *qjsEngine(const QObject *); | - | ||||||
| 160 | - | |||||||
| 161 | QT_END_NAMESPACE | - | ||||||
| 162 | - | |||||||
| 163 | #endif // QJSENGINE_H | - | ||||||
| Source code | Switch to Preprocessed file |