Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsapi/qjsvalue_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 | // | - | ||||||
41 | // W A R N I N G | - | ||||||
42 | // ------------- | - | ||||||
43 | // | - | ||||||
44 | // This file is not part of the Qt API. It exists purely as an | - | ||||||
45 | // implementation detail. This header file may change from version to | - | ||||||
46 | // version without notice, or even be removed. | - | ||||||
47 | // | - | ||||||
48 | // We mean it. | - | ||||||
49 | // | - | ||||||
50 | - | |||||||
51 | #ifndef QJSVALUE_P_H | - | ||||||
52 | #define QJSVALUE_P_H | - | ||||||
53 | - | |||||||
54 | #include <qjsvalue.h> | - | ||||||
55 | #include <private/qtqmlglobal_p.h> | - | ||||||
56 | #include <private/qv4value_p.h> | - | ||||||
57 | #include <private/qv4string_p.h> | - | ||||||
58 | #include <private/qv4engine_p.h> | - | ||||||
59 | #include <private/qflagpointer_p.h> | - | ||||||
60 | #include <private/qv4mm_p.h> | - | ||||||
61 | #include <private/qv4persistent_p.h> | - | ||||||
62 | - | |||||||
63 | QT_BEGIN_NAMESPACE | - | ||||||
64 | - | |||||||
65 | class QJSValuePrivate | - | ||||||
66 | { | - | ||||||
67 | public: | - | ||||||
68 | static inline QV4::Value *getValue(const QJSValue *jsval) | - | ||||||
69 | { | - | ||||||
70 | if (jsval->d & 3)
| 296-2436 | ||||||
71 | return nullptr; executed 296 times by 4 tests: return nullptr; Executed by:
| 296 | ||||||
72 | return reinterpret_cast<QV4::Value *>(jsval->d); executed 2436 times by 18 tests: return reinterpret_cast<QV4::Value *>(jsval->d); Executed by:
| 2436 | ||||||
73 | } | - | ||||||
74 | - | |||||||
75 | static inline QVariant *getVariant(const QJSValue *jsval) | - | ||||||
76 | { | - | ||||||
77 | if (jsval->d & 1)
| 16-194 | ||||||
78 | return reinterpret_cast<QVariant *>(jsval->d & ~3); executed 194 times by 3 tests: return reinterpret_cast<QVariant *>(jsval->d & ~3); Executed by:
| 194 | ||||||
79 | return nullptr; executed 16 times by 1 test: return nullptr; Executed by:
| 16 | ||||||
80 | } | - | ||||||
81 | - | |||||||
82 | static inline void setVariant(QJSValue *jsval, const QVariant &v) { | - | ||||||
83 | QVariant *val = new QVariant(v); | - | ||||||
84 | jsval->d = reinterpret_cast<quintptr>(val) | 1; | - | ||||||
85 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||
86 | - | |||||||
87 | static inline void setValue(QJSValue *jsval, QV4::ExecutionEngine *engine, const QV4::Value &v) { | - | ||||||
88 | QV4::Value *value = engine->memoryManager->m_persistentValues->allocate(); | - | ||||||
89 | *value = v; | - | ||||||
90 | jsval->d = reinterpret_cast<quintptr>(value); | - | ||||||
91 | } never executed: end of block | 0 | ||||||
92 | - | |||||||
93 | static inline void setValue(QJSValue *jsval, QV4::ExecutionEngine *engine, QV4::ReturnedValue v) { | - | ||||||
94 | QV4::Value *value = engine->memoryManager->m_persistentValues->allocate(); | - | ||||||
95 | *value = v; | - | ||||||
96 | jsval->d = reinterpret_cast<quintptr>(value); | - | ||||||
97 | } never executed: end of block | 0 | ||||||
98 | - | |||||||
99 | static QV4::ReturnedValue convertedToValue(QV4::ExecutionEngine *e, const QJSValue &jsval) | - | ||||||
100 | { | - | ||||||
101 | QV4::Value *v = getValue(&jsval); | - | ||||||
102 | if (!v) {
| 14-700 | ||||||
103 | QVariant *variant = getVariant(&jsval); | - | ||||||
104 | v = e->memoryManager->m_persistentValues->allocate(); | - | ||||||
105 | *v = variant ? e->fromVariant(*variant) : QV4::Encode::undefined();
| 0-14 | ||||||
106 | jsval.d = reinterpret_cast<quintptr>(v); | - | ||||||
107 | delete variant; | - | ||||||
108 | } executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||
109 | - | |||||||
110 | if (QV4::PersistentValueStorage::getEngine(v) != e) {
| 14-700 | ||||||
111 | qWarning("JSValue can't be reassigned to another engine."); | - | ||||||
112 | return QV4::Encode::undefined(); executed 14 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 14 | ||||||
113 | } | - | ||||||
114 | - | |||||||
115 | return v->asReturnedValue(); executed 700 times by 15 tests: return v->asReturnedValue(); Executed by:
| 700 | ||||||
116 | } | - | ||||||
117 | - | |||||||
118 | static QV4::Value *valueForData(const QJSValue *jsval, QV4::Value *scratch) | - | ||||||
119 | { | - | ||||||
120 | QV4::Value *v = getValue(jsval); | - | ||||||
121 | if (v)
| 152-330 | ||||||
122 | return v; executed 330 times by 4 tests: return v; Executed by:
| 330 | ||||||
123 | v = scratch; | - | ||||||
124 | QVariant *variant = getVariant(jsval); | - | ||||||
125 | if (!variant) {
| 16-136 | ||||||
126 | *v = QV4::Encode::undefined(); | - | ||||||
127 | return v; executed 16 times by 1 test: return v; Executed by:
| 16 | ||||||
128 | } | - | ||||||
129 | - | |||||||
130 | switch (variant->userType()) { | - | ||||||
131 | case QMetaType::UnknownType: never executed: case QMetaType::UnknownType: | 0 | ||||||
132 | case QMetaType::Void: never executed: case QMetaType::Void: | 0 | ||||||
133 | *v = QV4::Encode::undefined(); | - | ||||||
134 | break; never executed: break; | 0 | ||||||
135 | case QMetaType::Nullptr: executed 2 times by 1 test: case QMetaType::Nullptr: Executed by:
| 2 | ||||||
136 | case QMetaType::VoidStar: never executed: case QMetaType::VoidStar: | 0 | ||||||
137 | *v = QV4::Encode::null(); | - | ||||||
138 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||
139 | case QMetaType::Bool: executed 22 times by 1 test: case QMetaType::Bool: Executed by:
| 22 | ||||||
140 | *v = QV4::Encode(variant->toBool()); | - | ||||||
141 | break; executed 22 times by 1 test: break; Executed by:
| 22 | ||||||
142 | case QMetaType::Double: executed 46 times by 1 test: case QMetaType::Double: Executed by:
| 46 | ||||||
143 | *v = QV4::Encode(variant->toDouble()); | - | ||||||
144 | break; executed 46 times by 1 test: break; Executed by:
| 46 | ||||||
145 | case QMetaType::Int: executed 22 times by 2 tests: case QMetaType::Int: Executed by:
| 22 | ||||||
146 | case QMetaType::Short: never executed: case QMetaType::Short: | 0 | ||||||
147 | case QMetaType::UShort: never executed: case QMetaType::UShort: | 0 | ||||||
148 | case QMetaType::Char: never executed: case QMetaType::Char: | 0 | ||||||
149 | case QMetaType::UChar: never executed: case QMetaType::UChar: | 0 | ||||||
150 | *v = QV4::Encode(variant->toInt()); | - | ||||||
151 | break; executed 22 times by 2 tests: break; Executed by:
| 22 | ||||||
152 | case QMetaType::UInt: never executed: case QMetaType::UInt: | 0 | ||||||
153 | *v = QV4::Encode(variant->toUInt()); | - | ||||||
154 | break; never executed: break; | 0 | ||||||
155 | default: executed 44 times by 1 test: default: Executed by:
| 44 | ||||||
156 | return nullptr; executed 44 times by 1 test: return nullptr; Executed by:
| 44 | ||||||
157 | } | - | ||||||
158 | return v; executed 92 times by 2 tests: return v; Executed by:
| 92 | ||||||
159 | } | - | ||||||
160 | - | |||||||
161 | static QV4::ExecutionEngine *engine(const QJSValue *jsval) { | - | ||||||
162 | QV4::Value *v = getValue(jsval); | - | ||||||
163 | return v ? QV4::PersistentValueStorage::getEngine(v) : nullptr; executed 678 times by 5 tests: return v ? QV4::PersistentValueStorage::getEngine(v) : nullptr; Executed by:
| 678 | ||||||
164 | } | - | ||||||
165 | - | |||||||
166 | static inline bool checkEngine(QV4::ExecutionEngine *e, const QJSValue &jsval) { | - | ||||||
167 | QV4::ExecutionEngine *v4 = engine(&jsval); | - | ||||||
168 | return !v4 || v4 == e; never executed: return !v4 || v4 == e; | 0 | ||||||
169 | } | - | ||||||
170 | - | |||||||
171 | static inline void free(QJSValue *jsval) { | - | ||||||
172 | if (QV4::Value *v = QJSValuePrivate::getValue(jsval))
| 0 | ||||||
173 | QV4::PersistentValueStorage::free(v); never executed: QV4::PersistentValueStorage::free(v); | 0 | ||||||
174 | else if (QVariant *v = QJSValuePrivate::getVariant(jsval))
| 0 | ||||||
175 | delete v; never executed: delete v; | 0 | ||||||
176 | } never executed: end of block | 0 | ||||||
177 | }; | - | ||||||
178 | - | |||||||
179 | QT_END_NAMESPACE | - | ||||||
180 | - | |||||||
181 | #endif | - | ||||||
Source code | Switch to Preprocessed file |