Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4symbol.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2018 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 <qv4symbol_p.h> | - | ||||||||||||
41 | #include <qv4functionobject_p.h> | - | ||||||||||||
42 | #include <qv4identifiertable_p.h> | - | ||||||||||||
43 | - | |||||||||||||
44 | using namespace QV4; | - | ||||||||||||
45 | - | |||||||||||||
46 | DEFINE_OBJECT_VTABLE(SymbolCtor); | - | ||||||||||||
47 | DEFINE_MANAGED_VTABLE(Symbol); | - | ||||||||||||
48 | DEFINE_OBJECT_VTABLE(SymbolObject); | - | ||||||||||||
49 | - | |||||||||||||
50 | void Heap::Symbol::init(const QString &s) | - | ||||||||||||
51 | { | - | ||||||||||||
52 | Q_ASSERT(s.at(0) == QLatin1Char('@')); | - | ||||||||||||
53 | identifier = PropertyKey::fromStringOrSymbol(this); | - | ||||||||||||
54 | QString desc(s); | - | ||||||||||||
55 | text = desc.data_ptr(); | - | ||||||||||||
56 | text->ref.ref(); | - | ||||||||||||
57 | } executed 1190330 times by 153 tests: end of block Executed by:
| 1190330 | ||||||||||||
58 | - | |||||||||||||
59 | void Heap::SymbolCtor::init(QV4::ExecutionContext *scope) | - | ||||||||||||
60 | { | - | ||||||||||||
61 | Heap::FunctionObject::init(scope, QStringLiteral("Symbol")); executed 98785 times by 153 tests: return qstring_literal_temp; Executed by:
| 98785 | ||||||||||||
62 | } executed 99166 times by 153 tests: end of block Executed by:
| 99166 | ||||||||||||
63 | - | |||||||||||||
64 | void Heap::SymbolObject::init(const QV4::Symbol *s) | - | ||||||||||||
65 | { | - | ||||||||||||
66 | Object::init(); | - | ||||||||||||
67 | symbol.set(internalClass->engine, s->d()); | - | ||||||||||||
68 | } executed 106 times by 1 test: end of block Executed by:
| 106 | ||||||||||||
69 | - | |||||||||||||
70 | ReturnedValue QV4::SymbolCtor::virtualCall(const QV4::FunctionObject *f, const QV4::Value *, const QV4::Value *argv, int argc) | - | ||||||||||||
71 | { | - | ||||||||||||
72 | Scope scope(f); | - | ||||||||||||
73 | QString desc = QChar::fromLatin1('@'); | - | ||||||||||||
74 | if (argc && !argv[0].isUndefined()) {
| 8-1824 | ||||||||||||
75 | ScopedString s(scope, argv[0].toString(scope.engine)); | - | ||||||||||||
76 | if (scope.hasException())
| 12-1805 | ||||||||||||
77 | return Encode::undefined(); executed 12 times by 1 test: return Encode::undefined(); Executed by:
| 12 | ||||||||||||
78 | desc += s->toQString(); | - | ||||||||||||
79 | } executed 1805 times by 1 test: end of block Executed by:
| 1805 | ||||||||||||
80 | return Symbol::create(scope.engine, desc)->asReturnedValue(); executed 2483 times by 1 test: return Symbol::create(scope.engine, desc)->asReturnedValue(); Executed by:
| 2483 | ||||||||||||
81 | } | - | ||||||||||||
82 | - | |||||||||||||
83 | ReturnedValue SymbolCtor::method_for(const FunctionObject *f, const Value *, const Value *argv, int argc) | - | ||||||||||||
84 | { | - | ||||||||||||
85 | Scope scope(f); | - | ||||||||||||
86 | ScopedValue k(scope, argc ? argv[0]: Primitive::undefinedValue()); | - | ||||||||||||
87 | ScopedString key(scope, k->toString(scope.engine)); | - | ||||||||||||
88 | if (scope.hasException())
| 8-20 | ||||||||||||
89 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||
90 | QString desc = QLatin1Char('@') + key->toQString(); | - | ||||||||||||
91 | return scope.engine->identifierTable->insertSymbol(desc)->asReturnedValue(); executed 20 times by 1 test: return scope.engine->identifierTable->insertSymbol(desc)->asReturnedValue(); Executed by:
| 20 | ||||||||||||
92 | } | - | ||||||||||||
93 | - | |||||||||||||
94 | ReturnedValue SymbolCtor::method_keyFor(const FunctionObject *f, const Value *, const Value *argv, int argc) | - | ||||||||||||
95 | { | - | ||||||||||||
96 | ExecutionEngine *e = f->engine(); | - | ||||||||||||
97 | if (!argc || !argv[0].isSymbol())
| 0-44 | ||||||||||||
98 | return e->throwTypeError(QLatin1String("Symbol.keyFor: Argument is not a symbol.")); executed 32 times by 1 test: return e->throwTypeError(QLatin1String("Symbol.keyFor: Argument is not a symbol.")); Executed by:
| 32 | ||||||||||||
99 | const Symbol &arg = static_cast<const Symbol &>(argv[0]); | - | ||||||||||||
100 | Heap::Symbol *s = e->identifierTable->symbolForId(arg.propertyKey()); | - | ||||||||||||
101 | Q_ASSERT(!s || s == arg.d()); | - | ||||||||||||
102 | if (s)
| 4-8 | ||||||||||||
103 | return e->newString(arg.toQString().mid((1)))->asReturnedValue(); executed 4 times by 1 test: return e->newString(arg.toQString().mid((1)))->asReturnedValue(); Executed by:
| 4 | ||||||||||||
104 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||
105 | } | - | ||||||||||||
106 | - | |||||||||||||
107 | void SymbolPrototype::init(ExecutionEngine *engine, Object *ctor) | - | ||||||||||||
108 | { | - | ||||||||||||
109 | Scope scope(engine); | - | ||||||||||||
110 | ScopedValue v(scope); | - | ||||||||||||
111 | ctor->defineReadonlyProperty(engine->id_prototype(), (v = this)); | - | ||||||||||||
112 | ctor->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(0)); | - | ||||||||||||
113 | - | |||||||||||||
114 | ctor->defineDefaultProperty(QStringLiteral("for"), SymbolCtor::method_for, 1); executed 98286 times by 153 tests: return qstring_literal_temp; Executed by:
| 98286 | ||||||||||||
115 | ctor->defineDefaultProperty(QStringLiteral("keyFor"), SymbolCtor::method_keyFor, 1); executed 98890 times by 153 tests: return qstring_literal_temp; Executed by:
| 98890 | ||||||||||||
116 | ctor->defineReadonlyProperty(QStringLiteral("hasInstance"), *engine->symbol_hasInstance()); executed 98756 times by 153 tests: return qstring_literal_temp; Executed by:
| 98756 | ||||||||||||
117 | ctor->defineReadonlyProperty(QStringLiteral("isConcatSpreadable"), *engine->symbol_isConcatSpreadable()); executed 98364 times by 153 tests: return qstring_literal_temp; Executed by:
| 98364 | ||||||||||||
118 | ctor->defineReadonlyProperty(QStringLiteral("iterator"), *engine->symbol_iterator()); executed 98839 times by 153 tests: return qstring_literal_temp; Executed by:
| 98839 | ||||||||||||
119 | ctor->defineReadonlyProperty(QStringLiteral("match"), *engine->symbol_match()); executed 98855 times by 153 tests: return qstring_literal_temp; Executed by:
| 98855 | ||||||||||||
120 | ctor->defineReadonlyProperty(QStringLiteral("replace"), *engine->symbol_replace()); executed 98917 times by 153 tests: return qstring_literal_temp; Executed by:
| 98917 | ||||||||||||
121 | ctor->defineReadonlyProperty(QStringLiteral("search"), *engine->symbol_search()); executed 98705 times by 153 tests: return qstring_literal_temp; Executed by:
| 98705 | ||||||||||||
122 | ctor->defineReadonlyProperty(QStringLiteral("species"), *engine->symbol_species()); executed 98751 times by 153 tests: return qstring_literal_temp; Executed by:
| 98751 | ||||||||||||
123 | ctor->defineReadonlyProperty(QStringLiteral("split"), *engine->symbol_split()); executed 98772 times by 153 tests: return qstring_literal_temp; Executed by:
| 98772 | ||||||||||||
124 | ctor->defineReadonlyProperty(QStringLiteral("toPrimitive"), *engine->symbol_toPrimitive()); executed 98875 times by 153 tests: return qstring_literal_temp; Executed by:
| 98875 | ||||||||||||
125 | ctor->defineReadonlyProperty(QStringLiteral("toStringTag"), *engine->symbol_toStringTag()); executed 98340 times by 153 tests: return qstring_literal_temp; Executed by:
| 98340 | ||||||||||||
126 | ctor->defineReadonlyProperty(QStringLiteral("unscopables"), *engine->symbol_unscopables()); executed 98708 times by 153 tests: return qstring_literal_temp; Executed by:
| 98708 | ||||||||||||
127 | - | |||||||||||||
128 | defineDefaultProperty(QStringLiteral("constructor"), (v = ctor)); executed 98397 times by 153 tests: return qstring_literal_temp; Executed by:
| 98397 | ||||||||||||
129 | defineDefaultProperty(QStringLiteral("toString"), method_toString); executed 98908 times by 153 tests: return qstring_literal_temp; Executed by:
| 98908 | ||||||||||||
130 | defineDefaultProperty(QStringLiteral("valueOf"), method_valueOf); executed 98992 times by 153 tests: return qstring_literal_temp; Executed by:
| 98992 | ||||||||||||
131 | defineDefaultProperty(engine->symbol_toPrimitive(), method_symbolToPrimitive, 1, Attr_ReadOnly_ButConfigurable); | - | ||||||||||||
132 | - | |||||||||||||
133 | v = engine->newString(QStringLiteral("Symbol")); executed 98962 times by 153 tests: return qstring_literal_temp; Executed by:
| 98962 | ||||||||||||
134 | defineReadonlyConfigurableProperty(engine->symbol_toStringTag(), v); | - | ||||||||||||
135 | - | |||||||||||||
136 | } executed 98893 times by 153 tests: end of block Executed by:
| 98893 | ||||||||||||
137 | - | |||||||||||||
138 | ReturnedValue SymbolPrototype::method_toString(const FunctionObject *f, const Value *thisObject, const Value *, int) | - | ||||||||||||
139 | { | - | ||||||||||||
140 | Scope scope(f); | - | ||||||||||||
141 | Scoped<Symbol> s(scope, thisObject->as<Symbol>()); | - | ||||||||||||
142 | if (!s) {
| 4-18 | ||||||||||||
143 | if (const SymbolObject *o = thisObject->as<SymbolObject>())
| 0-4 | ||||||||||||
144 | s = o->d()->symbol; executed 4 times by 1 test: s = o->d()->symbol; Executed by:
| 4 | ||||||||||||
145 | else | - | ||||||||||||
146 | return scope.engine->throwTypeError(); never executed: return scope.engine->throwTypeError(); | 0 | ||||||||||||
147 | } | - | ||||||||||||
148 | return scope.engine->newString(s->descriptiveString())->asReturnedValue(); executed 22 times by 1 test: return scope.engine->newString(s->descriptiveString())->asReturnedValue(); Executed by:
| 22 | ||||||||||||
149 | } | - | ||||||||||||
150 | - | |||||||||||||
151 | ReturnedValue SymbolPrototype::method_valueOf(const FunctionObject *f, const Value *thisObject, const Value *, int) | - | ||||||||||||
152 | { | - | ||||||||||||
153 | Scope scope(f); | - | ||||||||||||
154 | Scoped<Symbol> s(scope, thisObject->as<Symbol>()); | - | ||||||||||||
155 | if (!s) {
| 32-38 | ||||||||||||
156 | if (const SymbolObject *o = thisObject->as<SymbolObject>())
| 4-28 | ||||||||||||
157 | s = o->d()->symbol; executed 4 times by 1 test: s = o->d()->symbol; Executed by:
| 4 | ||||||||||||
158 | else | - | ||||||||||||
159 | return scope.engine->throwTypeError(); executed 28 times by 1 test: return scope.engine->throwTypeError(); Executed by:
| 28 | ||||||||||||
160 | } | - | ||||||||||||
161 | return s->asReturnedValue(); executed 42 times by 1 test: return s->asReturnedValue(); Executed by:
| 42 | ||||||||||||
162 | } | - | ||||||||||||
163 | - | |||||||||||||
164 | ReturnedValue SymbolPrototype::method_symbolToPrimitive(const FunctionObject *f, const Value *thisObject, const Value *, int) | - | ||||||||||||
165 | { | - | ||||||||||||
166 | if (thisObject->isSymbol())
| 0-40 | ||||||||||||
167 | return thisObject->asReturnedValue(); never executed: return thisObject->asReturnedValue(); | 0 | ||||||||||||
168 | if (const SymbolObject *o = thisObject->as<SymbolObject>())
| 16-24 | ||||||||||||
169 | return o->d()->symbol->asReturnedValue(); executed 16 times by 1 test: return o->d()->symbol->asReturnedValue(); Executed by:
| 16 | ||||||||||||
170 | return f->engine()->throwTypeError(); executed 24 times by 1 test: return f->engine()->throwTypeError(); Executed by:
| 24 | ||||||||||||
171 | } | - | ||||||||||||
172 | - | |||||||||||||
173 | Heap::Symbol *Symbol::create(ExecutionEngine *e, const QString &s) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | Q_ASSERT(s.at(0) == QLatin1Char('@')); | - | ||||||||||||
176 | return e->memoryManager->alloc<Symbol>(s); executed 1190061 times by 153 tests: return e->memoryManager->alloc<Symbol>(s); Executed by:
| 1190061 | ||||||||||||
177 | } | - | ||||||||||||
178 | - | |||||||||||||
179 | QString Symbol::descriptiveString() const | - | ||||||||||||
180 | { | - | ||||||||||||
181 | return QLatin1String("Symbol(") + toQString().midRef(1) + QLatin1String(")"); executed 526 times by 1 test: return QLatin1String("Symbol(") + toQString().midRef(1) + QLatin1String(")"); Executed by:
| 526 | ||||||||||||
182 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |