| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4variantobject.cpp |
| 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 | #include "qv4variantobject_p.h" | - | ||||||||||||
| 41 | #include "qv4functionobject_p.h" | - | ||||||||||||
| 42 | #include "qv4objectproto_p.h" | - | ||||||||||||
| 43 | #include <private/qqmlvaluetypewrapper_p.h> | - | ||||||||||||
| 44 | #include <private/qv8engine_p.h> | - | ||||||||||||
| 45 | #include <private/qv4qobjectwrapper_p.h> | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | using namespace QV4; | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | DEFINE_OBJECT_VTABLE(VariantObject); | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | void Heap::VariantObject::init() | - | ||||||||||||
| 54 | { | - | ||||||||||||
| 55 | Object::init(); | - | ||||||||||||
| 56 | scarceData = new ExecutionEngine::ScarceResourceData; | - | ||||||||||||
| 57 | } executed 98779 times by 153 tests: end of blockExecuted by:
| 98779 | ||||||||||||
| 58 | - | |||||||||||||
| 59 | void Heap::VariantObject::init(const QVariant &value) | - | ||||||||||||
| 60 | { | - | ||||||||||||
| 61 | Object::init(); | - | ||||||||||||
| 62 | scarceData = new ExecutionEngine::ScarceResourceData(value); | - | ||||||||||||
| 63 | if (isScarce())
| 142-29661 | ||||||||||||
| 64 | removeVmePropertyReference(); executed 142 times by 1 test: removeVmePropertyReference();Executed by:
| 142 | ||||||||||||
| 65 | } executed 29803 times by 56 tests: end of blockExecuted by:
| 29803 | ||||||||||||
| 66 | - | |||||||||||||
| 67 | bool VariantObject::Data::isScarce() const | - | ||||||||||||
| 68 | { | - | ||||||||||||
| 69 | QVariant::Type t = data().type(); | - | ||||||||||||
| 70 | return t == QVariant::Pixmap || t == QVariant::Image; executed 184893 times by 153 tests: return t == QVariant::Pixmap || t == QVariant::Image;Executed by:
| 184893 | ||||||||||||
| 71 | } | - | ||||||||||||
| 72 | - | |||||||||||||
| 73 | bool VariantObject::virtualIsEqualTo(Managed *m, Managed *other) | - | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | Q_ASSERT(m->as<QV4::VariantObject>()); | - | ||||||||||||
| 76 | QV4::VariantObject *lv = static_cast<QV4::VariantObject *>(m); | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | if (QV4::VariantObject *rv = other->as<QV4::VariantObject>())
| 0-26 | ||||||||||||
| 79 | return lv->d()->data() == rv->d()->data(); executed 26 times by 2 tests: return lv->d()->data() == rv->d()->data();Executed by:
| 26 | ||||||||||||
| 80 | - | |||||||||||||
| 81 | if (QV4::QQmlValueTypeWrapper *v = other->as<QQmlValueTypeWrapper>())
| 0 | ||||||||||||
| 82 | return v->isEqual(lv->d()->data()); never executed: return v->isEqual(lv->d()->data()); | 0 | ||||||||||||
| 83 | - | |||||||||||||
| 84 | return false; never executed: return false; | 0 | ||||||||||||
| 85 | } | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | void VariantObject::addVmePropertyReference() const | - | ||||||||||||
| 88 | { | - | ||||||||||||
| 89 | if (d()->isScarce() && ++d()->vmePropertyReferenceCount == 1) {
| 6-21767 | ||||||||||||
| 90 | // remove from the ep->scarceResources list | - | ||||||||||||
| 91 | // since it is now no longer eligible to be | - | ||||||||||||
| 92 | // released automatically by the engine. | - | ||||||||||||
| 93 | d()->addVmePropertyReference(); | - | ||||||||||||
| 94 | } executed 64 times by 1 test: end of blockExecuted by:
| 64 | ||||||||||||
| 95 | } executed 21837 times by 22 tests: end of blockExecuted by:
| 21837 | ||||||||||||
| 96 | - | |||||||||||||
| 97 | void VariantObject::removeVmePropertyReference() const | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | if (d()->isScarce() && --d()->vmePropertyReferenceCount == 0) {
| 0-4213 | ||||||||||||
| 100 | // and add to the ep->scarceResources list | - | ||||||||||||
| 101 | // since it is now eligible to be released | - | ||||||||||||
| 102 | // automatically by the engine. | - | ||||||||||||
| 103 | d()->removeVmePropertyReference(); | - | ||||||||||||
| 104 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 105 | } executed 4219 times by 17 tests: end of blockExecuted by:
| 4219 | ||||||||||||
| 106 | - | |||||||||||||
| 107 | - | |||||||||||||
| 108 | void VariantPrototype::init() | - | ||||||||||||
| 109 | { | - | ||||||||||||
| 110 | defineDefaultProperty(QStringLiteral("preserve"), method_preserve, 0); executed 98079 times by 153 tests: return qstring_literal_temp;Executed by:
| 98079 | ||||||||||||
| 111 | defineDefaultProperty(QStringLiteral("destroy"), method_destroy, 0); executed 98663 times by 153 tests: return qstring_literal_temp;Executed by:
| 98663 | ||||||||||||
| 112 | defineDefaultProperty(engine()->id_valueOf(), method_valueOf, 0); | - | ||||||||||||
| 113 | defineDefaultProperty(engine()->id_toString(), method_toString, 0); | - | ||||||||||||
| 114 | } executed 98848 times by 153 tests: end of blockExecuted by:
| 98848 | ||||||||||||
| 115 | - | |||||||||||||
| 116 | ReturnedValue VariantPrototype::method_preserve(const FunctionObject *, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | const VariantObject *o = thisObject->as<QV4::VariantObject>(); | - | ||||||||||||
| 119 | if (o && o->d()->isScarce())
| 0-24 | ||||||||||||
| 120 | o->d()->addVmePropertyReference(); executed 24 times by 1 test: o->d()->addVmePropertyReference();Executed by:
| 24 | ||||||||||||
| 121 | RETURN_UNDEFINED(); executed 24 times by 1 test: return QV4::Encode::undefined();Executed by:
| 24 | ||||||||||||
| 122 | } | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | ReturnedValue VariantPrototype::method_destroy(const FunctionObject *, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 125 | { | - | ||||||||||||
| 126 | const VariantObject *o = thisObject->as<QV4::VariantObject>(); | - | ||||||||||||
| 127 | if (o) {
| 0-32 | ||||||||||||
| 128 | if (o->d()->isScarce())
| 0-32 | ||||||||||||
| 129 | o->d()->addVmePropertyReference(); executed 32 times by 1 test: o->d()->addVmePropertyReference();Executed by:
| 32 | ||||||||||||
| 130 | o->d()->data() = QVariant(); | - | ||||||||||||
| 131 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||
| 132 | RETURN_UNDEFINED(); executed 32 times by 1 test: return QV4::Encode::undefined();Executed by:
| 32 | ||||||||||||
| 133 | } | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | ReturnedValue VariantPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 136 | { | - | ||||||||||||
| 137 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||
| 138 | const VariantObject *o = thisObject->as<QV4::VariantObject>(); | - | ||||||||||||
| 139 | if (!o)
| 0-32 | ||||||||||||
| 140 | RETURN_UNDEFINED(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||
| 141 | QString result = o->d()->data().toString(); | - | ||||||||||||
| 142 | if (result.isEmpty() && !o->d()->data().canConvert(QVariant::String)) {
| 2-26 | ||||||||||||
| 143 | result = QLatin1String("QVariant(") | - | ||||||||||||
| 144 | + QLatin1String(o->d()->data().typeName()) | - | ||||||||||||
| 145 | + QLatin1Char(')'); | - | ||||||||||||
| 146 | } executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||
| 147 | return Encode(v4->newString(result)); executed 32 times by 5 tests: return Encode(v4->newString(result));Executed by:
| 32 | ||||||||||||
| 148 | } | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | ReturnedValue VariantPrototype::method_valueOf(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 151 | { | - | ||||||||||||
| 152 | const VariantObject *o = thisObject->as<QV4::VariantObject>(); | - | ||||||||||||
| 153 | if (o) {
| 0-30 | ||||||||||||
| 154 | QVariant v = o->d()->data(); | - | ||||||||||||
| 155 | switch (v.type()) { | - | ||||||||||||
| 156 | case QVariant::Invalid: never executed: case QVariant::Invalid: | 0 | ||||||||||||
| 157 | return Encode::undefined(); never executed: return Encode::undefined(); | 0 | ||||||||||||
| 158 | case QVariant::String: never executed: case QVariant::String: | 0 | ||||||||||||
| 159 | return Encode(b->engine()->newString(v.toString())); never executed: return Encode(b->engine()->newString(v.toString())); | 0 | ||||||||||||
| 160 | case QVariant::Int: never executed: case QVariant::Int: | 0 | ||||||||||||
| 161 | return Encode(v.toInt()); never executed: return Encode(v.toInt()); | 0 | ||||||||||||
| 162 | case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||
| 163 | case QVariant::UInt: never executed: case QVariant::UInt: | 0 | ||||||||||||
| 164 | return Encode(v.toDouble()); never executed: return Encode(v.toDouble()); | 0 | ||||||||||||
| 165 | case QVariant::Bool: never executed: case QVariant::Bool: | 0 | ||||||||||||
| 166 | return Encode(v.toBool()); never executed: return Encode(v.toBool()); | 0 | ||||||||||||
| 167 | default: executed 30 times by 3 tests: default:Executed by:
| 30 | ||||||||||||
| 168 | if (QMetaType::typeFlags(v.userType()) & QMetaType::IsEnumeration)
| 2-28 | ||||||||||||
| 169 | RETURN_RESULT(Encode(v.toInt())); executed 2 times by 1 test: return QV4::Encode(Encode(v.toInt()));Executed by:
| 2 | ||||||||||||
| 170 | break; executed 28 times by 3 tests: break;Executed by:
| 28 | ||||||||||||
| 171 | } | - | ||||||||||||
| 172 | } | - | ||||||||||||
| 173 | return thisObject->asReturnedValue(); executed 28 times by 3 tests: return thisObject->asReturnedValue();Executed by:
| 28 | ||||||||||||
| 174 | } | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |