| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4mapobject.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 | #include "qv4setobject_p.h" // ### temporary | - | ||||||||||||
| 41 | #include "qv4mapobject_p.h" | - | ||||||||||||
| 42 | #include "qv4mapiterator_p.h" | - | ||||||||||||
| 43 | #include "qv4estable_p.h" | - | ||||||||||||
| 44 | #include "qv4symbol_p.h" | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | using namespace QV4; | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | DEFINE_OBJECT_VTABLE(MapCtor); | - | ||||||||||||
| 49 | DEFINE_OBJECT_VTABLE(MapObject); | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | void Heap::MapCtor::init(QV4::ExecutionContext *scope) | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | Heap::FunctionObject::init(scope, QStringLiteral("Map")); executed 98564 times by 153 tests: return qstring_literal_temp;Executed by:
| 98564 | ||||||||||||
| 54 | } executed 98827 times by 153 tests: end of blockExecuted by:
| 98827 | ||||||||||||
| 55 | - | |||||||||||||
| 56 | ReturnedValue MapCtor::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *) | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | Scope scope(f); | - | ||||||||||||
| 59 | Scoped<MapObject> a(scope, scope.engine->memoryManager->allocate<MapObject>()); | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | if (argc > 0) {
| 146-346 | ||||||||||||
| 62 | ScopedValue iterable(scope, argv[0]); | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | // ### beware, hack alert! | - | ||||||||||||
| 65 | // Object iteration seems broken right now. if we allow any object to | - | ||||||||||||
| 66 | // iterate, it endlessly loops in the Map/prototype tests in test262... | - | ||||||||||||
| 67 | // disable these for now until Object iteration is fixed, just so we can | - | ||||||||||||
| 68 | // test this. | - | ||||||||||||
| 69 | Scoped<MapObject> mapObjectCheck(scope, argv[0]); | - | ||||||||||||
| 70 | Scoped<SetObject> setObjectCheck(scope, argv[0]); | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | if (!iterable->isUndefined() && !iterable->isNull() && (mapObjectCheck || setObjectCheck)) {
| 4-142 | ||||||||||||
| 73 | ScopedFunctionObject adder(scope, a->get(ScopedString(scope, scope.engine->newString(QString::fromLatin1("set"))))); | - | ||||||||||||
| 74 | if (!adder)
| 0 | ||||||||||||
| 75 | return scope.engine->throwTypeError(); never executed: return scope.engine->throwTypeError(); | 0 | ||||||||||||
| 76 | ScopedObject iter(scope, Runtime::method_getIterator(scope.engine, iterable, true)); | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | CHECK_EXCEPTION(); never executed: return QV4::Encode::undefined();
| 0 | ||||||||||||
| 79 | if (!iter)
| 0 | ||||||||||||
| 80 | return a.asReturnedValue(); never executed: return a.asReturnedValue(); | 0 | ||||||||||||
| 81 | - | |||||||||||||
| 82 | Value *nextValue = scope.alloc(1); | - | ||||||||||||
| 83 | ScopedValue done(scope); | - | ||||||||||||
| 84 | forever { | - | ||||||||||||
| 85 | done = Runtime::method_iteratorNext(scope.engine, iter, nextValue); | - | ||||||||||||
| 86 | CHECK_EXCEPTION(); never executed: return QV4::Encode::undefined();
| 0 | ||||||||||||
| 87 | if (done->toBoolean())
| 0 | ||||||||||||
| 88 | return a.asReturnedValue(); never executed: return a.asReturnedValue(); | 0 | ||||||||||||
| 89 | - | |||||||||||||
| 90 | adder->call(a, nextValue, 1); | - | ||||||||||||
| 91 | if (scope.engine->hasException) {
| 0 | ||||||||||||
| 92 | ScopedValue falsey(scope, Encode(false)); | - | ||||||||||||
| 93 | return Runtime::method_iteratorClose(scope.engine, iter, falsey); never executed: return Runtime::method_iteratorClose(scope.engine, iter, falsey); | 0 | ||||||||||||
| 94 | } | - | ||||||||||||
| 95 | } never executed: end of block | 0 | ||||||||||||
| 96 | } never executed: end of block | 0 | ||||||||||||
| 97 | } executed 146 times by 1 test: end of blockExecuted by:
| 146 | ||||||||||||
| 98 | return a.asReturnedValue(); executed 492 times by 1 test: return a.asReturnedValue();Executed by:
| 492 | ||||||||||||
| 99 | } | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | ReturnedValue MapCtor::virtualCall(const FunctionObject *f, const Value *, const Value *, int) | - | ||||||||||||
| 102 | { | - | ||||||||||||
| 103 | Scope scope(f); | - | ||||||||||||
| 104 | return scope.engine->throwTypeError(QString::fromLatin1("Map requires new")); executed 8 times by 1 test: return scope.engine->throwTypeError(QString::fromLatin1("Map requires new"));Executed by:
| 8 | ||||||||||||
| 105 | } | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | void MapPrototype::init(ExecutionEngine *engine, Object *ctor) | - | ||||||||||||
| 108 | { | - | ||||||||||||
| 109 | Scope scope(engine); | - | ||||||||||||
| 110 | ScopedObject o(scope); | - | ||||||||||||
| 111 | ctor->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(0)); | - | ||||||||||||
| 112 | ctor->defineReadonlyProperty(engine->id_prototype(), (o = this)); | - | ||||||||||||
| 113 | ctor->addSymbolSpecies(); | - | ||||||||||||
| 114 | defineDefaultProperty(engine->id_constructor(), (o = ctor)); | - | ||||||||||||
| 115 | - | |||||||||||||
| 116 | defineDefaultProperty(QStringLiteral("clear"), method_clear, 0); executed 98918 times by 153 tests: return qstring_literal_temp;Executed by:
| 98918 | ||||||||||||
| 117 | defineDefaultProperty(QStringLiteral("delete"), method_delete, 1); executed 99001 times by 153 tests: return qstring_literal_temp;Executed by:
| 99001 | ||||||||||||
| 118 | defineDefaultProperty(QStringLiteral("forEach"), method_forEach, 1); executed 99100 times by 153 tests: return qstring_literal_temp;Executed by:
| 99100 | ||||||||||||
| 119 | defineDefaultProperty(QStringLiteral("get"), method_get, 1); executed 98591 times by 153 tests: return qstring_literal_temp;Executed by:
| 98591 | ||||||||||||
| 120 | defineDefaultProperty(QStringLiteral("has"), method_has, 1); executed 98947 times by 153 tests: return qstring_literal_temp;Executed by:
| 98947 | ||||||||||||
| 121 | defineDefaultProperty(QStringLiteral("keys"), method_keys, 0); executed 98979 times by 153 tests: return qstring_literal_temp;Executed by:
| 98979 | ||||||||||||
| 122 | defineDefaultProperty(QStringLiteral("set"), method_set, 0); executed 98922 times by 153 tests: return qstring_literal_temp;Executed by:
| 98922 | ||||||||||||
| 123 | defineAccessorProperty(QStringLiteral("size"), method_get_size, nullptr); executed 98956 times by 153 tests: return qstring_literal_temp;Executed by:
| 98956 | ||||||||||||
| 124 | defineDefaultProperty(QStringLiteral("values"), method_values, 0); executed 98569 times by 153 tests: return qstring_literal_temp;Executed by:
| 98569 | ||||||||||||
| 125 | - | |||||||||||||
| 126 | // Per the spec, the value for entries/@@iterator is the same | - | ||||||||||||
| 127 | ScopedString valString(scope, scope.engine->newIdentifier(QStringLiteral("entries"))); executed 98859 times by 153 tests: return qstring_literal_temp;Executed by:
| 98859 | ||||||||||||
| 128 | ScopedFunctionObject entriesFn(scope, FunctionObject::createBuiltinFunction(engine, valString, MapPrototype::method_entries, 0)); | - | ||||||||||||
| 129 | defineDefaultProperty(QStringLiteral("entries"), entriesFn); executed 98760 times by 153 tests: return qstring_literal_temp;Executed by:
| 98760 | ||||||||||||
| 130 | defineDefaultProperty(engine->symbol_iterator(), entriesFn); | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | ScopedString val(scope, engine->newString(QLatin1String("Map"))); | - | ||||||||||||
| 133 | defineReadonlyConfigurableProperty(engine->symbol_toStringTag(), val); | - | ||||||||||||
| 134 | } executed 99047 times by 153 tests: end of blockExecuted by:
| 99047 | ||||||||||||
| 135 | - | |||||||||||||
| 136 | void Heap::MapObject::init() | - | ||||||||||||
| 137 | { | - | ||||||||||||
| 138 | Object::init(); | - | ||||||||||||
| 139 | esTable = new ESTable(); | - | ||||||||||||
| 140 | } executed 492 times by 1 test: end of blockExecuted by:
| 492 | ||||||||||||
| 141 | - | |||||||||||||
| 142 | void Heap::MapObject::destroy() | - | ||||||||||||
| 143 | { | - | ||||||||||||
| 144 | delete esTable; | - | ||||||||||||
| 145 | esTable = 0; | - | ||||||||||||
| 146 | } executed 494 times by 1 test: end of blockExecuted by:
| 494 | ||||||||||||
| 147 | - | |||||||||||||
| 148 | void Heap::MapObject::markObjects(Heap::Base *that, MarkStack *markStack) | - | ||||||||||||
| 149 | { | - | ||||||||||||
| 150 | MapObject *m = static_cast<MapObject *>(that); | - | ||||||||||||
| 151 | m->esTable->markObjects(markStack); | - | ||||||||||||
| 152 | Object::markObjects(that, markStack); | - | ||||||||||||
| 153 | } never executed: end of block | 0 | ||||||||||||
| 154 | - | |||||||||||||
| 155 | ReturnedValue MapPrototype::method_clear(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 156 | { | - | ||||||||||||
| 157 | Scope scope(b); | - | ||||||||||||
| 158 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 159 | if (!that)
| 36 | ||||||||||||
| 160 | return scope.engine->throwTypeError(); executed 36 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 36 | ||||||||||||
| 161 | - | |||||||||||||
| 162 | that->d()->esTable->clear(); | - | ||||||||||||
| 163 | return Encode::undefined(); executed 36 times by 1 test: return Encode::undefined();Executed by:
| 36 | ||||||||||||
| 164 | } | - | ||||||||||||
| 165 | - | |||||||||||||
| 166 | ReturnedValue MapPrototype::method_delete(const FunctionObject *b, const Value *thisObject, const Value *argv, int) | - | ||||||||||||
| 167 | { | - | ||||||||||||
| 168 | Scope scope(b); | - | ||||||||||||
| 169 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 170 | if (!that)
| 36-60 | ||||||||||||
| 171 | return scope.engine->throwTypeError(); executed 36 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 36 | ||||||||||||
| 172 | - | |||||||||||||
| 173 | return Encode(that->d()->esTable->remove(argv[0])); executed 60 times by 1 test: return Encode(that->d()->esTable->remove(argv[0]));Executed by:
| 60 | ||||||||||||
| 174 | } | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | ReturnedValue MapPrototype::method_entries(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 177 | { | - | ||||||||||||
| 178 | Scope scope(b); | - | ||||||||||||
| 179 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 180 | if (!that)
| 52-92 | ||||||||||||
| 181 | return scope.engine->throwTypeError(); executed 52 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 52 | ||||||||||||
| 182 | - | |||||||||||||
| 183 | Scoped<MapIteratorObject> ao(scope, scope.engine->newMapIteratorObject(that)); | - | ||||||||||||
| 184 | ao->d()->iterationKind = IteratorKind::KeyValueIteratorKind; | - | ||||||||||||
| 185 | return ao->asReturnedValue(); executed 92 times by 1 test: return ao->asReturnedValue();Executed by:
| 92 | ||||||||||||
| 186 | } | - | ||||||||||||
| 187 | - | |||||||||||||
| 188 | ReturnedValue MapPrototype::method_forEach(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||
| 189 | { | - | ||||||||||||
| 190 | Scope scope(b); | - | ||||||||||||
| 191 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 192 | if (!that)
| 52-66 | ||||||||||||
| 193 | return scope.engine->throwTypeError(); executed 52 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 52 | ||||||||||||
| 194 | - | |||||||||||||
| 195 | ScopedFunctionObject callbackfn(scope, argv[0]); | - | ||||||||||||
| 196 | if (!callbackfn)
| 28-38 | ||||||||||||
| 197 | return scope.engine->throwTypeError(); executed 28 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 28 | ||||||||||||
| 198 | - | |||||||||||||
| 199 | ScopedValue thisArg(scope, Primitive::undefinedValue()); | - | ||||||||||||
| 200 | if (argc > 1)
| 4-34 | ||||||||||||
| 201 | thisArg = ScopedValue(scope, argv[1]); executed 4 times by 1 test: thisArg = ScopedValue(scope, argv[1]);Executed by:
| 4 | ||||||||||||
| 202 | - | |||||||||||||
| 203 | Value *arguments = scope.alloc(3); | - | ||||||||||||
| 204 | for (uint i = 0; i < that->d()->esTable->size(); ++i) {
| 38-68 | ||||||||||||
| 205 | that->d()->esTable->iterate(i, &arguments[0], &arguments[1]); // fill in key (0), value (1) | - | ||||||||||||
| 206 | - | |||||||||||||
| 207 | arguments[2] = that; | - | ||||||||||||
| 208 | callbackfn->call(thisArg, arguments, 3); | - | ||||||||||||
| 209 | CHECK_EXCEPTION(); never executed: return QV4::Encode::undefined();
| 0-68 | ||||||||||||
| 210 | } executed 68 times by 1 test: end of blockExecuted by:
| 68 | ||||||||||||
| 211 | return Encode::undefined(); executed 38 times by 1 test: return Encode::undefined();Executed by:
| 38 | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | ReturnedValue MapPrototype::method_get(const FunctionObject *b, const Value *thisObject, const Value *argv, int) | - | ||||||||||||
| 215 | { | - | ||||||||||||
| 216 | Scope scope(b); | - | ||||||||||||
| 217 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 218 | if (!that)
| 52-76 | ||||||||||||
| 219 | return scope.engine->throwTypeError(); executed 52 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 52 | ||||||||||||
| 220 | - | |||||||||||||
| 221 | return that->d()->esTable->get(argv[0]); executed 76 times by 1 test: return that->d()->esTable->get(argv[0]);Executed by:
| 76 | ||||||||||||
| 222 | } | - | ||||||||||||
| 223 | - | |||||||||||||
| 224 | ReturnedValue MapPrototype::method_has(const FunctionObject *b, const Value *thisObject, const Value *argv, int) | - | ||||||||||||
| 225 | { | - | ||||||||||||
| 226 | Scope scope(b); | - | ||||||||||||
| 227 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 228 | if (!that)
| 52-108 | ||||||||||||
| 229 | return scope.engine->throwTypeError(); executed 52 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 52 | ||||||||||||
| 230 | - | |||||||||||||
| 231 | return Encode(that->d()->esTable->has(argv[0])); executed 108 times by 1 test: return Encode(that->d()->esTable->has(argv[0]));Executed by:
| 108 | ||||||||||||
| 232 | } | - | ||||||||||||
| 233 | - | |||||||||||||
| 234 | ReturnedValue MapPrototype::method_keys(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 235 | { | - | ||||||||||||
| 236 | Scope scope(b); | - | ||||||||||||
| 237 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 238 | if (!that)
| 20-52 | ||||||||||||
| 239 | return scope.engine->throwTypeError(); executed 52 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 52 | ||||||||||||
| 240 | - | |||||||||||||
| 241 | Scoped<MapIteratorObject> ao(scope, scope.engine->newMapIteratorObject(that)); | - | ||||||||||||
| 242 | ao->d()->iterationKind = IteratorKind::KeyIteratorKind; | - | ||||||||||||
| 243 | return ao->asReturnedValue(); executed 20 times by 1 test: return ao->asReturnedValue();Executed by:
| 20 | ||||||||||||
| 244 | } | - | ||||||||||||
| 245 | - | |||||||||||||
| 246 | ReturnedValue MapPrototype::method_set(const FunctionObject *b, const Value *thisObject, const Value *argv, int) | - | ||||||||||||
| 247 | { | - | ||||||||||||
| 248 | Scope scope(b); | - | ||||||||||||
| 249 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 250 | if (!that)
| 52-419 | ||||||||||||
| 251 | return scope.engine->throwTypeError(); executed 52 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 52 | ||||||||||||
| 252 | - | |||||||||||||
| 253 | that->d()->esTable->set(argv[0], argv[1]); | - | ||||||||||||
| 254 | return that.asReturnedValue(); executed 419 times by 1 test: return that.asReturnedValue();Executed by:
| 419 | ||||||||||||
| 255 | } | - | ||||||||||||
| 256 | - | |||||||||||||
| 257 | ReturnedValue MapPrototype::method_get_size(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 258 | { | - | ||||||||||||
| 259 | Scope scope(b); | - | ||||||||||||
| 260 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 261 | if (!that)
| 36-99 | ||||||||||||
| 262 | return scope.engine->throwTypeError(); executed 36 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 36 | ||||||||||||
| 263 | - | |||||||||||||
| 264 | return Encode(that->d()->esTable->size()); executed 99 times by 1 test: return Encode(that->d()->esTable->size());Executed by:
| 99 | ||||||||||||
| 265 | } | - | ||||||||||||
| 266 | - | |||||||||||||
| 267 | ReturnedValue MapPrototype::method_values(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
| 268 | { | - | ||||||||||||
| 269 | Scope scope(b); | - | ||||||||||||
| 270 | Scoped<MapObject> that(scope, thisObject); | - | ||||||||||||
| 271 | if (!that)
| 28-52 | ||||||||||||
| 272 | return scope.engine->throwTypeError(); executed 52 times by 1 test: return scope.engine->throwTypeError();Executed by:
| 52 | ||||||||||||
| 273 | - | |||||||||||||
| 274 | Scoped<MapIteratorObject> ao(scope, scope.engine->newMapIteratorObject(that)); | - | ||||||||||||
| 275 | ao->d()->iterationKind = IteratorKind::ValueIteratorKind; | - | ||||||||||||
| 276 | return ao->asReturnedValue(); executed 28 times by 1 test: return ao->asReturnedValue();Executed by:
| 28 | ||||||||||||
| 277 | } | - | ||||||||||||
| 278 | - | |||||||||||||
| 279 | - | |||||||||||||
| Source code | Switch to Preprocessed file |