| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4setobject.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2018 Crimson AS <info@crimson.no> | - | ||||||||||||
| 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 | #include "qv4setobject_p.h" | - | ||||||||||||
| 42 | #include "qv4setiterator_p.h" | - | ||||||||||||
| 43 | #include "qv4estable_p.h" | - | ||||||||||||
| 44 | #include "qv4symbol_p.h" | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | using namespace QV4; | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | DEFINE_OBJECT_VTABLE(SetCtor); | - | ||||||||||||
| 49 | DEFINE_OBJECT_VTABLE(SetObject); | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | void Heap::SetCtor::init(QV4::ExecutionContext *scope) | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | Heap::FunctionObject::init(scope, QStringLiteral("Set")); executed 98162 times by 153 tests: return qstring_literal_temp;Executed by:
| 98162 | ||||||||||||
| 54 | } executed 98439 times by 153 tests: end of blockExecuted by:
| 98439 | ||||||||||||
| 55 | - | |||||||||||||
| 56 | ReturnedValue SetCtor::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *) | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | Scope scope(f); | - | ||||||||||||
| 59 | Scoped<SetObject> a(scope, scope.engine->memoryManager->allocate<SetObject>()); | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | if (argc > 0) {
| 160-535 | ||||||||||||
| 62 | ScopedValue iterable(scope, argv[0]); | - | ||||||||||||
| 63 | if (!iterable->isUndefined() && !iterable->isNull()) {
| 4-155 | ||||||||||||
| 64 | ScopedFunctionObject adder(scope, a->get(ScopedString(scope, scope.engine->newString(QString::fromLatin1("add"))))); | - | ||||||||||||
| 65 | if (!adder)
| 8-145 | ||||||||||||
| 66 | return scope.engine->throwTypeError(); executed 8 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 8 | ||||||||||||
| 67 | ScopedObject iter(scope, Runtime::method_getIterator(scope.engine, iterable, true)); | - | ||||||||||||
| 68 | CHECK_EXCEPTION(); never executed: return QV4::Encode::undefined();
| 0-148 | ||||||||||||
| 69 | if (!iter)
| 0-146 | ||||||||||||
| 70 | return a.asReturnedValue(); never executed: return a.asReturnedValue(); | 0 | ||||||||||||
| 71 | - | |||||||||||||
| 72 | Value *nextValue = scope.alloc(1); | - | ||||||||||||
| 73 | ScopedValue done(scope); | - | ||||||||||||
| 74 | forever { | - | ||||||||||||
| 75 | done = Runtime::method_iteratorNext(scope.engine, iter, nextValue); | - | ||||||||||||
| 76 | CHECK_EXCEPTION(); executed 8 times by 1 test: return QV4::Encode::undefined();Executed by:
| 8-374 | ||||||||||||
| 77 | if (done->toBoolean())
| 136-238 | ||||||||||||
| 78 | return a.asReturnedValue(); executed 136 times by 1 test: return a.asReturnedValue();Executed by:
| 136 | ||||||||||||
| 79 | - | |||||||||||||
| 80 | adder->call(a, nextValue, 1); | - | ||||||||||||
| 81 | if (scope.engine->hasException) {
| 4-234 | ||||||||||||
| 82 | ScopedValue falsey(scope, Encode(false)); | - | ||||||||||||
| 83 | return Runtime::method_iteratorClose(scope.engine, iter, falsey); executed 4 times by 1 test: return Runtime::method_iteratorClose(scope.engine, iter, falsey);Executed by:
| 4 | ||||||||||||
| 84 | } | - | ||||||||||||
| 85 | } executed 234 times by 1 test: end of blockExecuted by:
| 234 | ||||||||||||
| 86 | } never executed: end of block | 0 | ||||||||||||
| 87 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 88 | - | |||||||||||||
| 89 | return a.asReturnedValue(); executed 543 times by 1 test: return a.asReturnedValue();Executed by:
| 543 | ||||||||||||
| 90 | } | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | ReturnedValue SetCtor::virtualCall(const FunctionObject *f, const Value *, const Value *, int) | - | ||||||||||||
| 93 | { | - | ||||||||||||
| 94 | Scope scope(f); | - | ||||||||||||
| 95 | return scope.engine->throwTypeError(QString::fromLatin1("Set requires new")); executed 8 times by 1 test: return scope.engine->throwTypeError(QString::fromLatin1("Set requires new"));Executed by:
| 8 | ||||||||||||
| 96 | } | - | ||||||||||||
| 97 | - | |||||||||||||
| 98 | void SetPrototype::init(ExecutionEngine *engine, Object *ctor) | - | ||||||||||||
| 99 | { | - | ||||||||||||
| 100 | Scope scope(engine); | - | ||||||||||||
| 101 | ScopedObject o(scope); | - | ||||||||||||
| 102 | ctor->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(0)); | - | ||||||||||||
| 103 | ctor->defineReadonlyProperty(engine->id_prototype(), (o = this)); | - | ||||||||||||
| 104 | ctor->addSymbolSpecies(); | - | ||||||||||||
| 105 | defineDefaultProperty(engine->id_constructor(), (o = ctor)); | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | defineDefaultProperty(QStringLiteral("add"), method_add, 1); executed 98653 times by 153 tests: return qstring_literal_temp;Executed by:
| 98653 | ||||||||||||
| 108 | defineDefaultProperty(QStringLiteral("clear"), method_clear, 0); executed 98928 times by 153 tests: return qstring_literal_temp;Executed by:
| 98928 | ||||||||||||
| 109 | defineDefaultProperty(QStringLiteral("delete"), method_delete, 1); executed 98951 times by 153 tests: return qstring_literal_temp;Executed by:
| 98951 | ||||||||||||
| 110 | defineDefaultProperty(QStringLiteral("entries"), method_entries, 0); executed 98572 times by 153 tests: return qstring_literal_temp;Executed by:
| 98572 | ||||||||||||
| 111 | defineDefaultProperty(QStringLiteral("forEach"), method_forEach, 1); executed 98823 times by 153 tests: return qstring_literal_temp;Executed by:
| 98823 | ||||||||||||
| 112 | defineDefaultProperty(QStringLiteral("has"), method_has, 1); executed 98988 times by 153 tests: return qstring_literal_temp;Executed by:
| 98988 | ||||||||||||
| 113 | defineAccessorProperty(QStringLiteral("size"), method_get_size, nullptr); executed 98953 times by 153 tests: return qstring_literal_temp;Executed by:
| 98953 | ||||||||||||
| 114 | - | |||||||||||||
| 115 | // Per the spec, the value for 'keys' is the same as 'values'. | - | ||||||||||||
| 116 | ScopedString valString(scope, scope.engine->newIdentifier(QStringLiteral("values"))); executed 98848 times by 153 tests: return qstring_literal_temp;Executed by:
| 98848 | ||||||||||||
| 117 | ScopedFunctionObject valuesFn(scope, FunctionObject::createBuiltinFunction(engine, valString, SetPrototype::method_values, 0)); | - | ||||||||||||
| 118 | defineDefaultProperty(QStringLiteral("keys"), valuesFn); executed 98738 times by 153 tests: return qstring_literal_temp;Executed by:
| 98738 | ||||||||||||
| 119 | defineDefaultProperty(QStringLiteral("values"), valuesFn); executed 98582 times by 153 tests: return qstring_literal_temp;Executed by:
| 98582 | ||||||||||||
| 120 | - | |||||||||||||
| 121 | defineDefaultProperty(engine->symbol_iterator(), valuesFn); | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | ScopedString val(scope, engine->newString(QLatin1String("Set"))); | - | ||||||||||||
| 124 | defineReadonlyConfigurableProperty(engine->symbol_toStringTag(), val); | - | ||||||||||||
| 125 | } executed 99003 times by 153 tests: end of blockExecuted by:
| 99003 | ||||||||||||
| 126 | - | |||||||||||||
| 127 | void Heap::SetObject::init() | - | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | Object::init(); | - | ||||||||||||
| 130 | esTable = new ESTable(); | - | ||||||||||||
| 131 | } executed 695 times by 1 test: end of blockExecuted by:
| 695 | ||||||||||||
| 132 | - | |||||||||||||
| 133 | void Heap::SetObject::destroy() | - | ||||||||||||
| 134 | { | - | ||||||||||||
| 135 | delete esTable; | - | ||||||||||||
| 136 | esTable = 0; | - | ||||||||||||
| 137 | } executed 704 times by 1 test: end of blockExecuted by:
| 704 | ||||||||||||
| 138 | - | |||||||||||||
| 139 | void Heap::SetObject::markObjects(Heap::Base *that, MarkStack *markStack) | - | ||||||||||||
| 140 | { | - | ||||||||||||
| 141 | SetObject *s = static_cast<SetObject *>(that); | - | ||||||||||||
| 142 | s->esTable->markObjects(markStack); | - | ||||||||||||
| 143 | Object::markObjects(that, markStack); | - | ||||||||||||
| 144 | } never executed: end of block | 0 | ||||||||||||
| 145 | - | |||||||||||||
| 146 | ReturnedValue SetPrototype::method_add(const FunctionObject *b, const Value *thisObject, const Value *argv, int) | - | ||||||||||||
| 147 | { | - | ||||||||||||
| 148 | Scope scope(b); | - | ||||||||||||
| 149 | Scoped<SetObject> that(scope, thisObject); | - | ||||||||||||
| 150 | if (!that)
| 80-527 | ||||||||||||
| 151 | return scope.engine->throwTypeError(); executed 80 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 80 | ||||||||||||
| 152 | - | |||||||||||||
| 153 | that->d()->esTable->set(argv[0], Primitive::undefinedValue()); | - | ||||||||||||
| 154 | return that.asReturnedValue(); executed 529 times by 1 test: return that.asReturnedValue();Executed by:
| 529 | ||||||||||||
| 155 | } | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | ReturnedValue SetPrototype::method_clear(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 158 | { | - | ||||||||||||
| 159 | Scope scope(b); | - | ||||||||||||
| 160 | Scoped<SetObject> that(scope, thisObject); | - | ||||||||||||
| 161 | if (!that)
| 16-79 | ||||||||||||
| 162 | return scope.engine->throwTypeError(); executed 79 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 79 | ||||||||||||
| 163 | - | |||||||||||||
| 164 | that->d()->esTable->clear(); | - | ||||||||||||
| 165 | return Encode::undefined(); executed 16 times by 1 test: return Encode::undefined();Executed by:
| 16 | ||||||||||||
| 166 | } | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | ReturnedValue SetPrototype::method_delete(const FunctionObject *b, const Value *thisObject, const Value *argv, int) | - | ||||||||||||
| 169 | { | - | ||||||||||||
| 170 | Scope scope(b); | - | ||||||||||||
| 171 | Scoped<SetObject> that(scope, thisObject); | - | ||||||||||||
| 172 | if (!that)
| 55-80 | ||||||||||||
| 173 | return scope.engine->throwTypeError(); executed 80 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 80 | ||||||||||||
| 174 | - | |||||||||||||
| 175 | return Encode(that->d()->esTable->remove(argv[0])); executed 55 times by 1 test: return Encode(that->d()->esTable->remove(argv[0]));Executed by:
| 55 | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | ReturnedValue SetPrototype::method_entries(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 179 | { | - | ||||||||||||
| 180 | Scope scope(b); | - | ||||||||||||
| 181 | Scoped<SetObject> that(scope, thisObject); | - | ||||||||||||
| 182 | if (!that)
| 20-80 | ||||||||||||
| 183 | return scope.engine->throwTypeError(); executed 80 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 80 | ||||||||||||
| 184 | - | |||||||||||||
| 185 | Scoped<SetIteratorObject> ao(scope, scope.engine->newSetIteratorObject(that)); | - | ||||||||||||
| 186 | ao->d()->iterationKind = IteratorKind::KeyValueIteratorKind; | - | ||||||||||||
| 187 | return ao->asReturnedValue(); executed 20 times by 1 test: return ao->asReturnedValue();Executed by:
| 20 | ||||||||||||
| 188 | } | - | ||||||||||||
| 189 | - | |||||||||||||
| 190 | ReturnedValue SetPrototype::method_forEach(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||
| 191 | { | - | ||||||||||||
| 192 | Scope scope(b); | - | ||||||||||||
| 193 | Scoped<SetObject> that(scope, thisObject); | - | ||||||||||||
| 194 | if (!that)
| 72-80 | ||||||||||||
| 195 | return scope.engine->throwTypeError(); executed 80 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 80 | ||||||||||||
| 196 | - | |||||||||||||
| 197 | ScopedFunctionObject callbackfn(scope, argv[0]); | - | ||||||||||||
| 198 | if (!callbackfn)
| 24-48 | ||||||||||||
| 199 | return scope.engine->throwTypeError(); executed 24 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 24 | ||||||||||||
| 200 | - | |||||||||||||
| 201 | ScopedValue thisArg(scope, Primitive::undefinedValue()); | - | ||||||||||||
| 202 | if (argc > 1)
| 8-40 | ||||||||||||
| 203 | thisArg = ScopedValue(scope, argv[1]); executed 8 times by 1 test: thisArg = ScopedValue(scope, argv[1]);Executed by:
| 8 | ||||||||||||
| 204 | - | |||||||||||||
| 205 | Value *arguments = scope.alloc(3); | - | ||||||||||||
| 206 | for (uint i = 0; i < that->d()->esTable->size(); ++i) {
| 40-96 | ||||||||||||
| 207 | that->d()->esTable->iterate(i, &arguments[0], &arguments[1]); // fill in key (0), value (1) | - | ||||||||||||
| 208 | arguments[1] = arguments[0]; // but for set, we want to return the key twice; value is always undefined. | - | ||||||||||||
| 209 | - | |||||||||||||
| 210 | arguments[2] = that; | - | ||||||||||||
| 211 | callbackfn->call(thisArg, arguments, 3); | - | ||||||||||||
| 212 | CHECK_EXCEPTION(); executed 8 times by 1 test: return QV4::Encode::undefined();Executed by:
| 8-88 | ||||||||||||
| 213 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||
| 214 | return Encode::undefined(); executed 40 times by 1 test: return Encode::undefined();Executed by:
| 40 | ||||||||||||
| 215 | } | - | ||||||||||||
| 216 | - | |||||||||||||
| 217 | ReturnedValue SetPrototype::method_has(const FunctionObject *b, const Value *thisObject, const Value *argv, int) | - | ||||||||||||
| 218 | { | - | ||||||||||||
| 219 | Scope scope(b); | - | ||||||||||||
| 220 | Scoped<SetObject> that(scope, thisObject); | - | ||||||||||||
| 221 | if (!that)
| 77-91 | ||||||||||||
| 222 | return scope.engine->throwTypeError(); executed 77 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 77 | ||||||||||||
| 223 | - | |||||||||||||
| 224 | return Encode(that->d()->esTable->has(argv[0])); executed 91 times by 1 test: return Encode(that->d()->esTable->has(argv[0]));Executed by:
| 91 | ||||||||||||
| 225 | } | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | ReturnedValue SetPrototype::method_get_size(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 228 | { | - | ||||||||||||
| 229 | Scope scope(b); | - | ||||||||||||
| 230 | Scoped<SetObject> that(scope, thisObject); | - | ||||||||||||
| 231 | if (!that)
| 0-131 | ||||||||||||
| 232 | return scope.engine->throwTypeError(); never executed: return scope.engine->throwTypeError(); | 0 | ||||||||||||
| 233 | - | |||||||||||||
| 234 | return Encode(that->d()->esTable->size()); executed 131 times by 1 test: return Encode(that->d()->esTable->size());Executed by:
| 131 | ||||||||||||
| 235 | } | - | ||||||||||||
| 236 | - | |||||||||||||
| 237 | ReturnedValue SetPrototype::method_values(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 238 | { | - | ||||||||||||
| 239 | Scope scope(b); | - | ||||||||||||
| 240 | Scoped<SetObject> that(scope, thisObject); | - | ||||||||||||
| 241 | if (!that)
| 80-106 | ||||||||||||
| 242 | return scope.engine->throwTypeError(); executed 80 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 80 | ||||||||||||
| 243 | - | |||||||||||||
| 244 | Scoped<SetIteratorObject> ao(scope, scope.engine->newSetIteratorObject(that)); | - | ||||||||||||
| 245 | ao->d()->iterationKind = IteratorKind::ValueIteratorKind; | - | ||||||||||||
| 246 | return ao->asReturnedValue(); executed 107 times by 1 test: return ao->asReturnedValue();Executed by:
| 107 | ||||||||||||
| 247 | } | - | ||||||||||||
| 248 | - | |||||||||||||
| Source code | Switch to Preprocessed file |