Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4stringobject.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 | - | |||||||||||||||||||
41 | #include "qv4stringobject_p.h" | - | ||||||||||||||||||
42 | #include "qv4regexp_p.h" | - | ||||||||||||||||||
43 | #include "qv4regexpobject_p.h" | - | ||||||||||||||||||
44 | #include "qv4objectproto_p.h" | - | ||||||||||||||||||
45 | #include <private/qv4mm_p.h> | - | ||||||||||||||||||
46 | #include "qv4scopedvalue_p.h" | - | ||||||||||||||||||
47 | #include "qv4symbol_p.h" | - | ||||||||||||||||||
48 | #include "qv4alloca_p.h" | - | ||||||||||||||||||
49 | #include "qv4jscall_p.h" | - | ||||||||||||||||||
50 | #include "qv4stringiterator_p.h" | - | ||||||||||||||||||
51 | #include <QtCore/QDateTime> | - | ||||||||||||||||||
52 | #include <QtCore/QDebug> | - | ||||||||||||||||||
53 | #include <QtCore/QStringList> | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | #include <cassert> | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | #ifndef Q_OS_WIN | - | ||||||||||||||||||
58 | # include <time.h> | - | ||||||||||||||||||
59 | # ifndef Q_OS_VXWORKS | - | ||||||||||||||||||
60 | # include <sys/time.h> | - | ||||||||||||||||||
61 | # else | - | ||||||||||||||||||
62 | # include "qplatformdefs.h" | - | ||||||||||||||||||
63 | # endif | - | ||||||||||||||||||
64 | #else | - | ||||||||||||||||||
65 | # include <windows.h> | - | ||||||||||||||||||
66 | #endif | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | using namespace QV4; | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | DEFINE_OBJECT_VTABLE(StringObject); | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | void Heap::StringObject::init() | - | ||||||||||||||||||
73 | { | - | ||||||||||||||||||
74 | Object::init(); | - | ||||||||||||||||||
75 | Q_ASSERT(vtable() == QV4::StringObject::staticVTable()); | - | ||||||||||||||||||
76 | string.set(internalClass->engine, internalClass->engine->id_empty()->d()); | - | ||||||||||||||||||
77 | setProperty(internalClass->engine, LengthPropertyIndex, Primitive::fromInt32(0)); | - | ||||||||||||||||||
78 | } never executed: end of block | 0 | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | void Heap::StringObject::init(const QV4::String *str) | - | ||||||||||||||||||
81 | { | - | ||||||||||||||||||
82 | Object::init(); | - | ||||||||||||||||||
83 | string.set(internalClass->engine, str->d()); | - | ||||||||||||||||||
84 | setProperty(internalClass->engine, LengthPropertyIndex, Primitive::fromInt32(length())); | - | ||||||||||||||||||
85 | } executed 48304 times by 14 tests: end of block Executed by:
| 48304 | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | Heap::String *Heap::StringObject::getIndex(uint index) const | - | ||||||||||||||||||
88 | { | - | ||||||||||||||||||
89 | QString str = string->toQString(); | - | ||||||||||||||||||
90 | if (index >= (uint)str.length())
| 28-1076 | ||||||||||||||||||
91 | return nullptr; executed 28 times by 2 tests: return nullptr; Executed by:
| 28 | ||||||||||||||||||
92 | return internalClass->engine->newString(str.mid(index, 1)); executed 1076 times by 4 tests: return internalClass->engine->newString(str.mid(index, 1)); Executed by:
| 1076 | ||||||||||||||||||
93 | } | - | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | uint Heap::StringObject::length() const | - | ||||||||||||||||||
96 | { | - | ||||||||||||||||||
97 | return string->length(); executed 48934 times by 14 tests: return string->length(); Executed by:
| 48934 | ||||||||||||||||||
98 | } | - | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | bool StringObject::virtualDeleteProperty(Managed *m, PropertyKey id) | - | ||||||||||||||||||
101 | { | - | ||||||||||||||||||
102 | Q_ASSERT(m->as<StringObject>()); | - | ||||||||||||||||||
103 | if (id.isArrayIndex()) {
| 28-86 | ||||||||||||||||||
104 | StringObject *o = static_cast<StringObject *>(m); | - | ||||||||||||||||||
105 | uint index = id.asArrayIndex(); | - | ||||||||||||||||||
106 | if (index < static_cast<uint>(o->d()->string->toQString().length()))
| 2-26 | ||||||||||||||||||
107 | return false; executed 26 times by 2 tests: return false; Executed by:
| 26 | ||||||||||||||||||
108 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
109 | return Object::virtualDeleteProperty(m, id); executed 88 times by 2 tests: return Object::virtualDeleteProperty(m, id); Executed by:
| 88 | ||||||||||||||||||
110 | } | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | void StringObject::virtualAdvanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attrs) | - | ||||||||||||||||||
113 | { | - | ||||||||||||||||||
114 | name->setM(nullptr); | - | ||||||||||||||||||
115 | StringObject *s = static_cast<StringObject *>(m); | - | ||||||||||||||||||
116 | uint slen = s->d()->string->toQString().length(); | - | ||||||||||||||||||
117 | if (it->arrayIndex <= slen) {
| 28-577 | ||||||||||||||||||
118 | while (it->arrayIndex < slen) {
| 256-322 | ||||||||||||||||||
119 | *index = it->arrayIndex; | - | ||||||||||||||||||
120 | ++it->arrayIndex; | - | ||||||||||||||||||
121 | Property pd; | - | ||||||||||||||||||
122 | PropertyAttributes a = s->getOwnProperty(PropertyKey::fromArrayIndex(*index), &pd); | - | ||||||||||||||||||
123 | if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) {
| 0-174 | ||||||||||||||||||
124 | *attrs = a; | - | ||||||||||||||||||
125 | p->copy(&pd, a); | - | ||||||||||||||||||
126 | return; executed 322 times by 4 tests: return; Executed by:
| 322 | ||||||||||||||||||
127 | } | - | ||||||||||||||||||
128 | } never executed: end of block | 0 | ||||||||||||||||||
129 | if (s->arrayData()) {
| 12-244 | ||||||||||||||||||
130 | it->arrayNode = s->sparseBegin(); | - | ||||||||||||||||||
131 | // iterate until we're past the end of the string | - | ||||||||||||||||||
132 | while (it->arrayNode && it->arrayNode->key() < slen)
| 0-12 | ||||||||||||||||||
133 | it->arrayNode = it->arrayNode->nextNode(); never executed: it->arrayNode = it->arrayNode->nextNode(); | 0 | ||||||||||||||||||
134 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
135 | } executed 256 times by 4 tests: end of block Executed by:
| 256 | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | return Object::virtualAdvanceIterator(m, it, name, index, p, attrs); executed 284 times by 4 tests: return Object::virtualAdvanceIterator(m, it, name, index, p, attrs); Executed by:
| 284 | ||||||||||||||||||
138 | } | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | PropertyAttributes StringObject::virtualGetOwnProperty(Managed *m, PropertyKey id, Property *p) | - | ||||||||||||||||||
141 | { | - | ||||||||||||||||||
142 | PropertyAttributes attributes = Object::virtualGetOwnProperty(m, id, p); | - | ||||||||||||||||||
143 | if (attributes != Attr_Invalid)
| 510-1548 | ||||||||||||||||||
144 | return attributes; executed 510 times by 1 test: return attributes; Executed by:
| 510 | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | Object *o = static_cast<Object *>(m); | - | ||||||||||||||||||
147 | if (id.isArrayIndex()) {
| 542-1006 | ||||||||||||||||||
148 | uint index = id.asArrayIndex(); | - | ||||||||||||||||||
149 | if (o->isStringObject()) {
| 0-542 | ||||||||||||||||||
150 | if (index >= static_cast<const StringObject *>(m)->length())
| 12-530 | ||||||||||||||||||
151 | return Attr_Invalid; executed 12 times by 1 test: return Attr_Invalid; Executed by:
| 12 | ||||||||||||||||||
152 | if (p)
| 92-438 | ||||||||||||||||||
153 | p->value = static_cast<StringObject *>(o)->getIndex(index); executed 438 times by 4 tests: p->value = static_cast<StringObject *>(o)->getIndex(index); Executed by:
| 438 | ||||||||||||||||||
154 | return Attr_NotConfigurable|Attr_NotWritable; executed 530 times by 4 tests: return Attr_NotConfigurable|Attr_NotWritable; Executed by:
| 530 | ||||||||||||||||||
155 | } | - | ||||||||||||||||||
156 | } never executed: end of block | 0 | ||||||||||||||||||
157 | return Attr_Invalid; executed 1006 times by 2 tests: return Attr_Invalid; Executed by:
| 1006 | ||||||||||||||||||
158 | } | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | DEFINE_OBJECT_VTABLE(StringCtor); | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | void Heap::StringCtor::init(QV4::ExecutionContext *scope) | - | ||||||||||||||||||
163 | { | - | ||||||||||||||||||
164 | Heap::FunctionObject::init(scope, QStringLiteral("String")); executed 98740 times by 153 tests: return qstring_literal_temp; Executed by:
| 98740 | ||||||||||||||||||
165 | } executed 99086 times by 153 tests: end of block Executed by:
| 99086 | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | ReturnedValue StringCtor::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *) | - | ||||||||||||||||||
168 | { | - | ||||||||||||||||||
169 | ExecutionEngine *v4 = static_cast<const Object *>(f)->engine(); | - | ||||||||||||||||||
170 | Scope scope(v4); | - | ||||||||||||||||||
171 | ScopedString value(scope); | - | ||||||||||||||||||
172 | if (argc)
| 256-3214 | ||||||||||||||||||
173 | value = argv[0].toString(v4); executed 3215 times by 5 tests: value = argv[0].toString(v4); Executed by:
| 3215 | ||||||||||||||||||
174 | else | - | ||||||||||||||||||
175 | value = v4->newString(); executed 256 times by 1 test: value = v4->newString(); Executed by:
| 256 | ||||||||||||||||||
176 | CHECK_EXCEPTION(); executed 11 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 11-3468 | ||||||||||||||||||
177 | return Encode(v4->newStringObject(value)); executed 3467 times by 5 tests: return Encode(v4->newStringObject(value)); Executed by:
| 3467 | ||||||||||||||||||
178 | } | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | ReturnedValue StringCtor::virtualCall(const FunctionObject *m, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||
181 | { | - | ||||||||||||||||||
182 | ExecutionEngine *v4 = m->engine(); | - | ||||||||||||||||||
183 | if (!argc)
| 4-616874 | ||||||||||||||||||
184 | return v4->newString()->asReturnedValue(); executed 4 times by 1 test: return v4->newString()->asReturnedValue(); Executed by:
| 4 | ||||||||||||||||||
185 | if (argv[0].isSymbol())
| 500-616418 | ||||||||||||||||||
186 | return v4->newString(argv[0].symbolValue()->descriptiveString())->asReturnedValue(); executed 500 times by 1 test: return v4->newString(argv[0].symbolValue()->descriptiveString())->asReturnedValue(); Executed by:
| 500 | ||||||||||||||||||
187 | return argv[0].toString(v4)->asReturnedValue(); executed 616377 times by 1 test: return argv[0].toString(v4)->asReturnedValue(); Executed by:
| 616377 | ||||||||||||||||||
188 | } | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | ReturnedValue StringCtor::method_fromCharCode(const FunctionObject *b, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||
191 | { | - | ||||||||||||||||||
192 | QString str(argc, Qt::Uninitialized); | - | ||||||||||||||||||
193 | QChar *ch = str.data(); | - | ||||||||||||||||||
194 | for (int i = 0, ei = argc; i < ei; ++i) {
| 17044476-28032727 | ||||||||||||||||||
195 | *ch = QChar(argv[i].toUInt16()); | - | ||||||||||||||||||
196 | ++ch; | - | ||||||||||||||||||
197 | } executed 28025947 times by 2 tests: end of block Executed by:
| 28025947 | ||||||||||||||||||
198 | *ch = 0; | - | ||||||||||||||||||
199 | return Encode(b->engine()->newString(str)); executed 17068719 times by 2 tests: return Encode(b->engine()->newString(str)); Executed by:
| 17068719 | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | - | |||||||||||||||||||
203 | - | |||||||||||||||||||
204 | ReturnedValue StringCtor::method_fromCodePoint(const FunctionObject *f, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||
205 | { | - | ||||||||||||||||||
206 | ExecutionEngine *e = f->engine(); | - | ||||||||||||||||||
207 | QString result(argc*2, Qt::Uninitialized); // assume worst case | - | ||||||||||||||||||
208 | QChar *ch = result.data(); | - | ||||||||||||||||||
209 | for (int i = 0; i < argc; ++i) {
| 59-140 | ||||||||||||||||||
210 | double num = argv[i].toNumber(); | - | ||||||||||||||||||
211 | if (e->hasException)
| 16-124 | ||||||||||||||||||
212 | return Encode::undefined(); executed 16 times by 1 test: return Encode::undefined(); Executed by:
| 16 | ||||||||||||||||||
213 | int cp = static_cast<int>(num); | - | ||||||||||||||||||
214 | if (cp != num || cp < 0 || cp > 0x10ffff)
| 4-95 | ||||||||||||||||||
215 | return e->throwRangeError(QStringLiteral("String.fromCodePoint: argument out of range.")); executed 40 times by 1 test: return e->throwRangeError(([]() noexcept -> QString { enum { Size = sizeof(u"" "String.fromCodePoint: argument out of range.")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "String.fromCodePoint: argument out of range." }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); Executed by:
executed 40 times by 1 test: return qstring_literal_temp; Executed by:
| 40 | ||||||||||||||||||
216 | if (cp > 0xffff) {
| 20-63 | ||||||||||||||||||
217 | *ch = QChar::highSurrogate(cp); | - | ||||||||||||||||||
218 | ++ch; | - | ||||||||||||||||||
219 | *ch = QChar::lowSurrogate(cp); | - | ||||||||||||||||||
220 | } else { executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
221 | *ch = cp; | - | ||||||||||||||||||
222 | } executed 63 times by 1 test: end of block Executed by:
| 63 | ||||||||||||||||||
223 | ++ch; | - | ||||||||||||||||||
224 | } executed 83 times by 1 test: end of block Executed by:
| 83 | ||||||||||||||||||
225 | *ch = 0; | - | ||||||||||||||||||
226 | result.truncate(ch - result.constData()); | - | ||||||||||||||||||
227 | return e->newString(result)->asReturnedValue(); executed 60 times by 1 test: return e->newString(result)->asReturnedValue(); Executed by:
| 60 | ||||||||||||||||||
228 | } | - | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | void StringPrototype::init(ExecutionEngine *engine, Object *ctor) | - | ||||||||||||||||||
231 | { | - | ||||||||||||||||||
232 | Scope scope(engine); | - | ||||||||||||||||||
233 | ScopedObject o(scope); | - | ||||||||||||||||||
234 | - | |||||||||||||||||||
235 | // need to set this once again, as these were not fully defined when creating the string proto | - | ||||||||||||||||||
236 | Heap::InternalClass *ic = scope.engine->classes[ExecutionEngine::Class_StringObject]->changePrototype(scope.engine->objectPrototype()->d()); | - | ||||||||||||||||||
237 | d()->internalClass.set(scope.engine, ic); | - | ||||||||||||||||||
238 | d()->string.set(scope.engine, scope.engine->id_empty()->d()); | - | ||||||||||||||||||
239 | setProperty(scope.engine, Heap::StringObject::LengthPropertyIndex, Primitive::fromInt32(0)); | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | ctor->defineReadonlyProperty(engine->id_prototype(), (o = this)); | - | ||||||||||||||||||
242 | ctor->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(1)); | - | ||||||||||||||||||
243 | ctor->defineDefaultProperty(QStringLiteral("fromCharCode"), StringCtor::method_fromCharCode, 1); executed 98391 times by 153 tests: return qstring_literal_temp; Executed by:
| 98391 | ||||||||||||||||||
244 | ctor->defineDefaultProperty(QStringLiteral("fromCodePoint"), StringCtor::method_fromCodePoint, 1); executed 98846 times by 153 tests: return qstring_literal_temp; Executed by:
| 98846 | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); executed 98866 times by 153 tests: return qstring_literal_temp; Executed by:
| 98866 | ||||||||||||||||||
247 | defineDefaultProperty(engine->id_toString(), method_toString); | - | ||||||||||||||||||
248 | defineDefaultProperty(engine->id_valueOf(), method_toString); // valueOf and toString are identical | - | ||||||||||||||||||
249 | defineDefaultProperty(QStringLiteral("charAt"), method_charAt, 1); executed 99063 times by 153 tests: return qstring_literal_temp; Executed by:
| 99063 | ||||||||||||||||||
250 | defineDefaultProperty(QStringLiteral("charCodeAt"), method_charCodeAt, 1); executed 98363 times by 153 tests: return qstring_literal_temp; Executed by:
| 98363 | ||||||||||||||||||
251 | defineDefaultProperty(QStringLiteral("codePointAt"), method_codePointAt, 1); executed 99090 times by 153 tests: return qstring_literal_temp; Executed by:
| 99090 | ||||||||||||||||||
252 | defineDefaultProperty(QStringLiteral("concat"), method_concat, 1); executed 98876 times by 153 tests: return qstring_literal_temp; Executed by:
| 98876 | ||||||||||||||||||
253 | defineDefaultProperty(QStringLiteral("endsWith"), method_endsWith, 1); executed 99076 times by 153 tests: return qstring_literal_temp; Executed by:
| 99076 | ||||||||||||||||||
254 | defineDefaultProperty(QStringLiteral("indexOf"), method_indexOf, 1); executed 99056 times by 153 tests: return qstring_literal_temp; Executed by:
| 99056 | ||||||||||||||||||
255 | defineDefaultProperty(QStringLiteral("includes"), method_includes, 1); executed 99079 times by 153 tests: return qstring_literal_temp; Executed by:
| 99079 | ||||||||||||||||||
256 | defineDefaultProperty(QStringLiteral("lastIndexOf"), method_lastIndexOf, 1); executed 98838 times by 153 tests: return qstring_literal_temp; Executed by:
| 98838 | ||||||||||||||||||
257 | defineDefaultProperty(QStringLiteral("localeCompare"), method_localeCompare, 1); executed 99101 times by 153 tests: return qstring_literal_temp; Executed by:
| 99101 | ||||||||||||||||||
258 | defineDefaultProperty(QStringLiteral("match"), method_match, 1); executed 98810 times by 153 tests: return qstring_literal_temp; Executed by:
| 98810 | ||||||||||||||||||
259 | defineDefaultProperty(QStringLiteral("normalize"), method_normalize, 0); executed 99086 times by 153 tests: return qstring_literal_temp; Executed by:
| 99086 | ||||||||||||||||||
260 | defineDefaultProperty(QStringLiteral("padEnd"), method_padEnd, 1); executed 98854 times by 153 tests: return qstring_literal_temp; Executed by:
| 98854 | ||||||||||||||||||
261 | defineDefaultProperty(QStringLiteral("padStart"), method_padStart, 1); executed 98945 times by 153 tests: return qstring_literal_temp; Executed by:
| 98945 | ||||||||||||||||||
262 | defineDefaultProperty(QStringLiteral("repeat"), method_repeat, 1); executed 99080 times by 153 tests: return qstring_literal_temp; Executed by:
| 99080 | ||||||||||||||||||
263 | defineDefaultProperty(QStringLiteral("replace"), method_replace, 2); executed 99113 times by 153 tests: return qstring_literal_temp; Executed by:
| 99113 | ||||||||||||||||||
264 | defineDefaultProperty(QStringLiteral("search"), method_search, 1); executed 98910 times by 153 tests: return qstring_literal_temp; Executed by:
| 98910 | ||||||||||||||||||
265 | defineDefaultProperty(QStringLiteral("slice"), method_slice, 2); executed 99088 times by 153 tests: return qstring_literal_temp; Executed by:
| 99088 | ||||||||||||||||||
266 | defineDefaultProperty(QStringLiteral("split"), method_split, 2); executed 98825 times by 153 tests: return qstring_literal_temp; Executed by:
| 98825 | ||||||||||||||||||
267 | defineDefaultProperty(QStringLiteral("startsWith"), method_startsWith, 1); executed 98899 times by 153 tests: return qstring_literal_temp; Executed by:
| 98899 | ||||||||||||||||||
268 | defineDefaultProperty(QStringLiteral("substr"), method_substr, 2); executed 98912 times by 153 tests: return qstring_literal_temp; Executed by:
| 98912 | ||||||||||||||||||
269 | defineDefaultProperty(QStringLiteral("substring"), method_substring, 2); executed 99119 times by 153 tests: return qstring_literal_temp; Executed by:
| 99119 | ||||||||||||||||||
270 | defineDefaultProperty(QStringLiteral("toLowerCase"), method_toLowerCase); executed 99059 times by 153 tests: return qstring_literal_temp; Executed by:
| 99059 | ||||||||||||||||||
271 | defineDefaultProperty(QStringLiteral("toLocaleLowerCase"), method_toLocaleLowerCase); executed 99088 times by 153 tests: return qstring_literal_temp; Executed by:
| 99088 | ||||||||||||||||||
272 | defineDefaultProperty(QStringLiteral("toUpperCase"), method_toUpperCase); executed 98846 times by 153 tests: return qstring_literal_temp; Executed by:
| 98846 | ||||||||||||||||||
273 | defineDefaultProperty(QStringLiteral("toLocaleUpperCase"), method_toLocaleUpperCase); executed 99108 times by 153 tests: return qstring_literal_temp; Executed by:
| 99108 | ||||||||||||||||||
274 | defineDefaultProperty(QStringLiteral("trim"), method_trim); executed 98817 times by 153 tests: return qstring_literal_temp; Executed by:
| 98817 | ||||||||||||||||||
275 | defineDefaultProperty(engine->symbol_iterator(), method_iterator); | - | ||||||||||||||||||
276 | } executed 98662 times by 153 tests: end of block Executed by:
| 98662 | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | static Heap::String *thisAsString(ExecutionEngine *v4, const QV4::Value *thisObject) | - | ||||||||||||||||||
279 | { | - | ||||||||||||||||||
280 | if (String *s = thisObject->stringValue())
| 112-359 | ||||||||||||||||||
281 | return s->d(); executed 359 times by 1 test: return s->d(); Executed by:
| 359 | ||||||||||||||||||
282 | if (const StringObject *thisString = thisObject->as<StringObject>())
| 48-64 | ||||||||||||||||||
283 | return thisString->d()->string; executed 48 times by 1 test: return thisString->d()->string; Executed by:
| 48 | ||||||||||||||||||
284 | return thisObject->toString(v4); executed 64 times by 1 test: return thisObject->toString(v4); Executed by:
| 64 | ||||||||||||||||||
285 | } | - | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | static QString getThisString(ExecutionEngine *v4, const QV4::Value *thisObject) | - | ||||||||||||||||||
288 | { | - | ||||||||||||||||||
289 | if (String *s = thisObject->stringValue())
| 3682-570539 | ||||||||||||||||||
290 | return s->toQString(); executed 570589 times by 10 tests: return s->toQString(); Executed by:
| 570589 | ||||||||||||||||||
291 | if (const StringObject *thisString = thisObject->as<StringObject>())
| 837-2844 | ||||||||||||||||||
292 | return thisString->d()->string->toQString(); executed 2843 times by 1 test: return thisString->d()->string->toQString(); Executed by:
| 2843 | ||||||||||||||||||
293 | if (thisObject->isUndefined() || thisObject->isNull()) {
| 80-760 | ||||||||||||||||||
294 | v4->throwTypeError(); | - | ||||||||||||||||||
295 | return QString(); executed 159 times by 1 test: return QString(); Executed by:
| 159 | ||||||||||||||||||
296 | } | - | ||||||||||||||||||
297 | return thisObject->toQString(); executed 680 times by 1 test: return thisObject->toQString(); Executed by:
| 680 | ||||||||||||||||||
298 | } | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | ReturnedValue StringPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||||||||
301 | { | - | ||||||||||||||||||
302 | if (thisObject->isString())
| 66-2271 | ||||||||||||||||||
303 | return thisObject->asReturnedValue(); executed 66 times by 2 tests: return thisObject->asReturnedValue(); Executed by:
| 66 | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
306 | const StringObject *o = thisObject->as<StringObject>(); | - | ||||||||||||||||||
307 | if (!o)
| 16-2256 | ||||||||||||||||||
308 | return v4->throwTypeError(); executed 16 times by 1 test: return v4->throwTypeError(); Executed by:
| 16 | ||||||||||||||||||
309 | return o->d()->string->asReturnedValue(); executed 2255 times by 2 tests: return o->d()->string->asReturnedValue(); Executed by:
| 2255 | ||||||||||||||||||
310 | } | - | ||||||||||||||||||
311 | - | |||||||||||||||||||
312 | ReturnedValue StringPrototype::method_charAt(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
313 | { | - | ||||||||||||||||||
314 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
315 | const QString str = getThisString(v4, thisObject); | - | ||||||||||||||||||
316 | if (v4->hasException)
| 12-316 | ||||||||||||||||||
317 | return QV4::Encode::undefined(); executed 12 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 12 | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | int pos = 0; | - | ||||||||||||||||||
320 | if (argc > 0)
| 4-312 | ||||||||||||||||||
321 | pos = (int) argv[0].toInteger(); executed 312 times by 1 test: pos = (int) argv[0].toInteger(); Executed by:
| 312 | ||||||||||||||||||
322 | - | |||||||||||||||||||
323 | QString result; | - | ||||||||||||||||||
324 | if (pos >= 0 && pos < str.length())
| 12-304 | ||||||||||||||||||
325 | result += str.at(pos); executed 288 times by 1 test: result += str.at(pos); Executed by:
| 288 | ||||||||||||||||||
326 | - | |||||||||||||||||||
327 | return Encode(v4->newString(result)); executed 316 times by 1 test: return Encode(v4->newString(result)); Executed by:
| 316 | ||||||||||||||||||
328 | } | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | ReturnedValue StringPrototype::method_charCodeAt(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
331 | { | - | ||||||||||||||||||
332 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
333 | const QString str = getThisString(v4, thisObject); | - | ||||||||||||||||||
334 | if (v4->hasException)
| 12-306 | ||||||||||||||||||
335 | return QV4::Encode::undefined(); executed 12 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 12 | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | int pos = 0; | - | ||||||||||||||||||
338 | if (argc > 0)
| 4-302 | ||||||||||||||||||
339 | pos = (int) argv[0].toInteger(); executed 301 times by 2 tests: pos = (int) argv[0].toInteger(); Executed by:
| 301 | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | - | |||||||||||||||||||
342 | if (pos >= 0 && pos < str.length())
| 4-302 | ||||||||||||||||||
343 | RETURN_RESULT(Encode(str.at(pos).unicode())); executed 294 times by 2 tests: return QV4::Encode(Encode(str.at(pos).unicode())); Executed by:
| 294 | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | return Encode(qt_qnan()); executed 12 times by 1 test: return Encode(qt_qnan()); Executed by:
| 12 | ||||||||||||||||||
346 | } | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | ReturnedValue StringPrototype::method_codePointAt(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
349 | { | - | ||||||||||||||||||
350 | ExecutionEngine *v4 = f->engine(); | - | ||||||||||||||||||
351 | QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
352 | if (v4->hasException)
| 16-192 | ||||||||||||||||||
353 | return QV4::Encode::undefined(); executed 16 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 16 | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | int index = argc ? argv[0].toInteger() : 0;
| 0-192 | ||||||||||||||||||
356 | if (v4->hasException)
| 8-184 | ||||||||||||||||||
357 | return QV4::Encode::undefined(); executed 8 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
358 | - | |||||||||||||||||||
359 | if (index < 0 || index >= value.size())
| 8-172 | ||||||||||||||||||
360 | return Encode::undefined(); executed 20 times by 1 test: return Encode::undefined(); Executed by:
| 20 | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | uint first = value.at(index).unicode(); | - | ||||||||||||||||||
363 | if (QChar::isHighSurrogate(first) && index + 1 < value.size()) {
| 12-124 | ||||||||||||||||||
364 | uint second = value.at(index + 1).unicode(); | - | ||||||||||||||||||
365 | if (QChar::isLowSurrogate(second))
| 48-64 | ||||||||||||||||||
366 | return Encode(QChar::surrogateToUcs4(first, second)); executed 64 times by 1 test: return Encode(QChar::surrogateToUcs4(first, second)); Executed by:
| 64 | ||||||||||||||||||
367 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||
368 | return Encode(first); executed 100 times by 1 test: return Encode(first); Executed by:
| 100 | ||||||||||||||||||
369 | } | - | ||||||||||||||||||
370 | - | |||||||||||||||||||
371 | ReturnedValue StringPrototype::method_concat(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
372 | { | - | ||||||||||||||||||
373 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
374 | QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
375 | if (v4->hasException)
| 12-52 | ||||||||||||||||||
376 | return QV4::Encode::undefined(); executed 12 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 12 | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | Scope scope(v4); | - | ||||||||||||||||||
379 | ScopedString s(scope); | - | ||||||||||||||||||
380 | for (int i = 0; i < argc; ++i) {
| 52-584 | ||||||||||||||||||
381 | s = argv[i].toString(scope.engine); | - | ||||||||||||||||||
382 | if (v4->hasException)
| 0-584 | ||||||||||||||||||
383 | return QV4::Encode::undefined(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | Q_ASSERT(s->isString()); | - | ||||||||||||||||||
386 | value += s->toQString(); | - | ||||||||||||||||||
387 | } executed 584 times by 1 test: end of block Executed by:
| 584 | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | return Encode(v4->newString(value)); executed 52 times by 1 test: return Encode(v4->newString(value)); Executed by:
| 52 | ||||||||||||||||||
390 | } | - | ||||||||||||||||||
391 | - | |||||||||||||||||||
392 | ReturnedValue StringPrototype::method_endsWith(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
393 | { | - | ||||||||||||||||||
394 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
395 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
396 | if (v4->hasException)
| 16-160 | ||||||||||||||||||
397 | return QV4::Encode::undefined(); executed 16 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 16 | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | if (argc && argv[0].as<RegExpObject>())
| 0-154 | ||||||||||||||||||
400 | return v4->throwTypeError(); executed 8 times by 1 test: return v4->throwTypeError(); Executed by:
| 8 | ||||||||||||||||||
401 | QString searchString = (argc ? argv[0] : Primitive::undefinedValue()).toQString();
| 0-144 | ||||||||||||||||||
402 | if (v4->hasException)
| 8-142 | ||||||||||||||||||
403 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | int pos = value.length(); | - | ||||||||||||||||||
406 | if (argc > 1)
| 43-99 | ||||||||||||||||||
407 | pos = (int) argv[1].toInteger(); executed 99 times by 1 test: pos = (int) argv[1].toInteger(); Executed by:
| 99 | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | if (pos == value.length())
| 64-80 | ||||||||||||||||||
410 | RETURN_RESULT(Encode(value.endsWith(searchString))); executed 63 times by 1 test: return QV4::Encode(Encode(value.endsWith(searchString))); Executed by:
| 63 | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | QStringRef stringToSearch = value.leftRef(pos); | - | ||||||||||||||||||
413 | return Encode(stringToSearch.endsWith(searchString)); executed 80 times by 1 test: return Encode(stringToSearch.endsWith(searchString)); Executed by:
| 80 | ||||||||||||||||||
414 | } | - | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | ReturnedValue StringPrototype::method_indexOf(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
417 | { | - | ||||||||||||||||||
418 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
419 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
420 | if (v4->hasException)
| 8-15013 | ||||||||||||||||||
421 | return QV4::Encode::undefined(); executed 8 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | QString searchString = (argc ? argv[0] : Primitive::undefinedValue()).toQString();
| 4-15008 | ||||||||||||||||||
424 | if (v4->hasException)
| 28-14985 | ||||||||||||||||||
425 | return Encode::undefined(); executed 28 times by 1 test: return Encode::undefined(); Executed by:
| 28 | ||||||||||||||||||
426 | - | |||||||||||||||||||
427 | int pos = 0; | - | ||||||||||||||||||
428 | if (argc > 1)
| 2472-12511 | ||||||||||||||||||
429 | pos = (int) argv[1].toInteger(); executed 2472 times by 1 test: pos = (int) argv[1].toInteger(); Executed by:
| 2472 | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | int index = -1; | - | ||||||||||||||||||
432 | if (! value.isEmpty())
| 32-14953 | ||||||||||||||||||
433 | index = value.indexOf(searchString, qMin(qMax(pos, 0), value.length())); executed 14944 times by 7 tests: index = value.indexOf(searchString, qMin(qMax(pos, 0), value.length())); Executed by:
| 14944 | ||||||||||||||||||
434 | - | |||||||||||||||||||
435 | return Encode(index); executed 14977 times by 7 tests: return Encode(index); Executed by:
| 14977 | ||||||||||||||||||
436 | } | - | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | ReturnedValue StringPrototype::method_includes(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
439 | { | - | ||||||||||||||||||
440 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
441 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
442 | if (v4->hasException)
| 15-160 | ||||||||||||||||||
443 | return QV4::Encode::undefined(); executed 15 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 15 | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | if (argc && argv[0].as<RegExpObject>())
| 0-159 | ||||||||||||||||||
446 | return v4->throwTypeError(); executed 8 times by 1 test: return v4->throwTypeError(); Executed by:
| 8 | ||||||||||||||||||
447 | QString searchString = (argc ? argv[0] : Primitive::undefinedValue()).toQString();
| 0-151 | ||||||||||||||||||
448 | if (v4->hasException)
| 8-144 | ||||||||||||||||||
449 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
450 | - | |||||||||||||||||||
451 | int pos = 0; | - | ||||||||||||||||||
452 | if (argc > 1) {
| 32-112 | ||||||||||||||||||
453 | const Value &posArg = argv[1]; | - | ||||||||||||||||||
454 | pos = (int) posArg.toInteger(); | - | ||||||||||||||||||
455 | if (!posArg.isInteger() && posArg.isNumber() && qIsInf(posArg.toNumber()))
| 8-56 | ||||||||||||||||||
456 | pos = value.length(); executed 8 times by 1 test: pos = value.length(); Executed by:
| 8 | ||||||||||||||||||
457 | } executed 112 times by 1 test: end of block Executed by:
| 112 | ||||||||||||||||||
458 | - | |||||||||||||||||||
459 | if (pos == 0)
| 64-80 | ||||||||||||||||||
460 | RETURN_RESULT(Encode(value.contains(searchString))); executed 80 times by 1 test: return QV4::Encode(Encode(value.contains(searchString))); Executed by:
| 80 | ||||||||||||||||||
461 | - | |||||||||||||||||||
462 | QStringRef stringToSearch = value.midRef(pos); | - | ||||||||||||||||||
463 | return Encode(stringToSearch.contains(searchString)); executed 64 times by 1 test: return Encode(stringToSearch.contains(searchString)); Executed by:
| 64 | ||||||||||||||||||
464 | } | - | ||||||||||||||||||
465 | - | |||||||||||||||||||
466 | ReturnedValue StringPrototype::method_lastIndexOf(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
467 | { | - | ||||||||||||||||||
468 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
469 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
470 | if (v4->hasException)
| 8-238 | ||||||||||||||||||
471 | return QV4::Encode::undefined(); executed 8 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | QString searchString = (argc ? argv[0] : Primitive::undefinedValue()).toQString();
| 4-234 | ||||||||||||||||||
474 | if (v4->hasException)
| 8-230 | ||||||||||||||||||
475 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | double position = argc > 1 ? RuntimeHelpers::toNumber(argv[1]) : +qInf();
| 24-206 | ||||||||||||||||||
478 | if (std::isnan(position))
| 8-222 | ||||||||||||||||||
479 | position = +qInf(); executed 8 times by 1 test: position = +qInf(); Executed by:
| 8 | ||||||||||||||||||
480 | else | - | ||||||||||||||||||
481 | position = trunc(position); executed 222 times by 4 tests: position = trunc(position); Executed by:
| 222 | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | int pos = trunc(qMin(qMax(position, 0.0), double(value.length()))); | - | ||||||||||||||||||
484 | if (!searchString.isEmpty() && pos == value.length())
| 0-230 | ||||||||||||||||||
485 | --pos; executed 214 times by 4 tests: --pos; Executed by:
| 214 | ||||||||||||||||||
486 | if (searchString.isNull() && pos == 0)
| 0-230 | ||||||||||||||||||
487 | RETURN_RESULT(Encode(-1)); never executed: return QV4::Encode(Encode(-1)); | 0 | ||||||||||||||||||
488 | int index = value.lastIndexOf(searchString, pos); | - | ||||||||||||||||||
489 | return Encode(index); executed 229 times by 4 tests: return Encode(index); Executed by:
| 229 | ||||||||||||||||||
490 | } | - | ||||||||||||||||||
491 | - | |||||||||||||||||||
492 | ReturnedValue StringPrototype::method_localeCompare(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
493 | { | - | ||||||||||||||||||
494 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
495 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
496 | if (v4->hasException)
| 8-252 | ||||||||||||||||||
497 | return QV4::Encode::undefined(); executed 8 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
498 | - | |||||||||||||||||||
499 | const QString that = (argc ? argv[0] : Primitive::undefinedValue()).toQString();
| 32-220 | ||||||||||||||||||
500 | return Encode(QString::localeAwareCompare(value, that)); executed 252 times by 1 test: return Encode(QString::localeAwareCompare(value, that)); Executed by:
| 252 | ||||||||||||||||||
501 | } | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | ReturnedValue StringPrototype::method_match(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
504 | { | - | ||||||||||||||||||
505 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
506 | if (thisObject->isNullOrUndefined())
| 8-415 | ||||||||||||||||||
507 | return v4->throwTypeError(); executed 8 times by 1 test: return v4->throwTypeError(); Executed by:
| 8 | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | Scope scope(v4); | - | ||||||||||||||||||
510 | ScopedString s(scope, thisObject->toString(v4)); | - | ||||||||||||||||||
511 | if (v4->hasException)
| 0-414 | ||||||||||||||||||
512 | return Encode::undefined(); never executed: return Encode::undefined(); | 0 | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | Scoped<RegExpObject> that(scope, argc ? argv[0] : Primitive::undefinedValue()); | - | ||||||||||||||||||
515 | if (!that) {
| 84-330 | ||||||||||||||||||
516 | // convert args[0] to a regexp | - | ||||||||||||||||||
517 | that = RegExpCtor::virtualCallAsConstructor(b, argv, argc, b); | - | ||||||||||||||||||
518 | if (v4->hasException)
| 8-76 | ||||||||||||||||||
519 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
520 | } executed 76 times by 1 test: end of block Executed by:
| 76 | ||||||||||||||||||
521 | Q_ASSERT(!!that); | - | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | bool global = that->global(); | - | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | if (!global)
| 142-264 | ||||||||||||||||||
526 | return RegExpPrototype::method_exec(b, that, s, 1); executed 264 times by 2 tests: return RegExpPrototype::method_exec(b, that, s, 1); Executed by:
| 264 | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | // rx is now in thisObject | - | ||||||||||||||||||
529 | that->setLastIndex(0); | - | ||||||||||||||||||
530 | ScopedArrayObject a(scope, scope.engine->newArrayObject()); | - | ||||||||||||||||||
531 | - | |||||||||||||||||||
532 | int previousLastIndex = 0; | - | ||||||||||||||||||
533 | uint n = 0; | - | ||||||||||||||||||
534 | while (1) { | - | ||||||||||||||||||
535 | Value result = Primitive::fromReturnedValue(RegExpPrototype::execFirstMatch(b, that, s, 1)); | - | ||||||||||||||||||
536 | if (result.isNull())
| 144-680 | ||||||||||||||||||
537 | break; executed 144 times by 1 test: break; Executed by:
| 144 | ||||||||||||||||||
538 | int index = that->lastIndex(); | - | ||||||||||||||||||
539 | if (previousLastIndex == index) {
| 0-678 | ||||||||||||||||||
540 | previousLastIndex = index + 1; | - | ||||||||||||||||||
541 | that->setLastIndex(previousLastIndex); | - | ||||||||||||||||||
542 | } else { never executed: end of block | 0 | ||||||||||||||||||
543 | previousLastIndex = index; | - | ||||||||||||||||||
544 | } executed 678 times by 1 test: end of block Executed by:
| 678 | ||||||||||||||||||
545 | a->arraySet(n, result); | - | ||||||||||||||||||
546 | ++n; | - | ||||||||||||||||||
547 | } executed 678 times by 1 test: end of block Executed by:
| 678 | ||||||||||||||||||
548 | if (!n)
| 0-144 | ||||||||||||||||||
549 | return Encode::null(); never executed: return Encode::null(); | 0 | ||||||||||||||||||
550 | else | - | ||||||||||||||||||
551 | return a.asReturnedValue(); executed 144 times by 1 test: return a.asReturnedValue(); Executed by:
| 144 | ||||||||||||||||||
552 | } | - | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | ReturnedValue StringPrototype::method_normalize(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
555 | { | - | ||||||||||||||||||
556 | ExecutionEngine *v4 = f->engine(); | - | ||||||||||||||||||
557 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
558 | if (v4->hasException)
| 16-76 | ||||||||||||||||||
559 | return Encode::undefined(); executed 16 times by 1 test: return Encode::undefined(); Executed by:
| 16 | ||||||||||||||||||
560 | - | |||||||||||||||||||
561 | QString::NormalizationForm form = QString::NormalizationForm_C; | - | ||||||||||||||||||
562 | if (argc >= 1 && !argv[0].isUndefined()) {
| 4-72 | ||||||||||||||||||
563 | QString f = argv[0].toQString(); | - | ||||||||||||||||||
564 | if (v4->hasException)
| 8-60 | ||||||||||||||||||
565 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
566 | if (f == QLatin1String("NFC"))
| 16-44 | ||||||||||||||||||
567 | form = QString::NormalizationForm_C; executed 16 times by 1 test: form = QString::NormalizationForm_C; Executed by:
| 16 | ||||||||||||||||||
568 | else if (f == QLatin1String("NFD"))
| 16-28 | ||||||||||||||||||
569 | form = QString::NormalizationForm_D; executed 16 times by 1 test: form = QString::NormalizationForm_D; Executed by:
| 16 | ||||||||||||||||||
570 | else if (f == QLatin1String("NFKC"))
| 8-20 | ||||||||||||||||||
571 | form = QString::NormalizationForm_KC; executed 8 times by 1 test: form = QString::NormalizationForm_KC; Executed by:
| 8 | ||||||||||||||||||
572 | else if (f == QLatin1String("NFKD"))
| 8-12 | ||||||||||||||||||
573 | form = QString::NormalizationForm_KD; executed 8 times by 1 test: form = QString::NormalizationForm_KD; Executed by:
| 8 | ||||||||||||||||||
574 | else | - | ||||||||||||||||||
575 | return v4->throwRangeError(QLatin1String("String.prototype.normalize: Invalid normalization form.")); executed 12 times by 1 test: return v4->throwRangeError(QLatin1String("String.prototype.normalize: Invalid normalization form.")); Executed by:
| 12 | ||||||||||||||||||
576 | } | - | ||||||||||||||||||
577 | QString normalized = value.normalized(form); | - | ||||||||||||||||||
578 | return v4->newString(normalized)->asReturnedValue(); executed 56 times by 1 test: return v4->newString(normalized)->asReturnedValue(); Executed by:
| 56 | ||||||||||||||||||
579 | } | - | ||||||||||||||||||
580 | - | |||||||||||||||||||
581 | ReturnedValue StringPrototype::method_padEnd(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
582 | { | - | ||||||||||||||||||
583 | ExecutionEngine *v4 = f->engine(); | - | ||||||||||||||||||
584 | if (thisObject->isNullOrUndefined())
| 8-96 | ||||||||||||||||||
585 | return v4->throwTypeError(); executed 8 times by 1 test: return v4->throwTypeError(); Executed by:
| 8 | ||||||||||||||||||
586 | - | |||||||||||||||||||
587 | Scope scope(v4); | - | ||||||||||||||||||
588 | ScopedString s(scope, thisAsString(v4, thisObject)); | - | ||||||||||||||||||
589 | if (v4->hasException)
| 8-88 | ||||||||||||||||||
590 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
591 | if (!argc)
| 0-88 | ||||||||||||||||||
592 | return s->asReturnedValue(); never executed: return s->asReturnedValue(); | 0 | ||||||||||||||||||
593 | - | |||||||||||||||||||
594 | int maxLen = argv[0].toInteger(); | - | ||||||||||||||||||
595 | if (maxLen <= s->d()->length())
| 32-56 | ||||||||||||||||||
596 | return s->asReturnedValue(); executed 32 times by 1 test: return s->asReturnedValue(); Executed by:
| 32 | ||||||||||||||||||
597 | QString fillString = (argc > 1 && !argv[1].isUndefined()) ? argv[1].toQString() : QString::fromLatin1(" ");
| 4-52 | ||||||||||||||||||
598 | if (v4->hasException)
| 4-52 | ||||||||||||||||||
599 | return Encode::undefined(); executed 4 times by 1 test: return Encode::undefined(); Executed by:
| 4 | ||||||||||||||||||
600 | - | |||||||||||||||||||
601 | if (fillString.isEmpty())
| 4-48 | ||||||||||||||||||
602 | return s->asReturnedValue(); executed 4 times by 1 test: return s->asReturnedValue(); Executed by:
| 4 | ||||||||||||||||||
603 | - | |||||||||||||||||||
604 | QString padded = s->toQString(); | - | ||||||||||||||||||
605 | int oldLength = padded.length(); | - | ||||||||||||||||||
606 | int toFill = maxLen - oldLength; | - | ||||||||||||||||||
607 | padded.resize(maxLen); | - | ||||||||||||||||||
608 | QChar *ch = padded.data() + oldLength; | - | ||||||||||||||||||
609 | while (toFill) {
| 48-144 | ||||||||||||||||||
610 | int copy = qMin(fillString.length(), toFill); | - | ||||||||||||||||||
611 | memcpy(ch, fillString.constData(), copy*sizeof(QChar)); | - | ||||||||||||||||||
612 | toFill -= copy; | - | ||||||||||||||||||
613 | ch += copy; | - | ||||||||||||||||||
614 | } executed 144 times by 1 test: end of block Executed by:
| 144 | ||||||||||||||||||
615 | *ch = 0; | - | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | return v4->newString(padded)->asReturnedValue(); executed 48 times by 1 test: return v4->newString(padded)->asReturnedValue(); Executed by:
| 48 | ||||||||||||||||||
618 | } | - | ||||||||||||||||||
619 | - | |||||||||||||||||||
620 | ReturnedValue StringPrototype::method_padStart(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
621 | { | - | ||||||||||||||||||
622 | ExecutionEngine *v4 = f->engine(); | - | ||||||||||||||||||
623 | if (thisObject->isNullOrUndefined())
| 8-95 | ||||||||||||||||||
624 | return v4->throwTypeError(); executed 8 times by 1 test: return v4->throwTypeError(); Executed by:
| 8 | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | Scope scope(v4); | - | ||||||||||||||||||
627 | ScopedString s(scope, thisAsString(v4, thisObject)); | - | ||||||||||||||||||
628 | if (v4->hasException)
| 8-88 | ||||||||||||||||||
629 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
630 | if (!argc)
| 0-88 | ||||||||||||||||||
631 | return s->asReturnedValue(); never executed: return s->asReturnedValue(); | 0 | ||||||||||||||||||
632 | - | |||||||||||||||||||
633 | int maxLen = argv[0].toInteger(); | - | ||||||||||||||||||
634 | if (maxLen <= s->d()->length())
| 32-56 | ||||||||||||||||||
635 | return s->asReturnedValue(); executed 32 times by 1 test: return s->asReturnedValue(); Executed by:
| 32 | ||||||||||||||||||
636 | QString fillString = (argc > 1 && !argv[1].isUndefined()) ? argv[1].toQString() : QString::fromLatin1(" ");
| 4-52 | ||||||||||||||||||
637 | if (v4->hasException)
| 4-52 | ||||||||||||||||||
638 | return Encode::undefined(); executed 4 times by 1 test: return Encode::undefined(); Executed by:
| 4 | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | if (fillString.isEmpty())
| 4-48 | ||||||||||||||||||
641 | return s->asReturnedValue(); executed 4 times by 1 test: return s->asReturnedValue(); Executed by:
| 4 | ||||||||||||||||||
642 | - | |||||||||||||||||||
643 | QString original = s->toQString(); | - | ||||||||||||||||||
644 | int oldLength = original.length(); | - | ||||||||||||||||||
645 | int toFill = maxLen - oldLength; | - | ||||||||||||||||||
646 | QString padded; | - | ||||||||||||||||||
647 | padded.resize(maxLen); | - | ||||||||||||||||||
648 | QChar *ch = padded.data(); | - | ||||||||||||||||||
649 | while (toFill) {
| 48-144 | ||||||||||||||||||
650 | int copy = qMin(fillString.length(), toFill); | - | ||||||||||||||||||
651 | memcpy(ch, fillString.constData(), copy*sizeof(QChar)); | - | ||||||||||||||||||
652 | toFill -= copy; | - | ||||||||||||||||||
653 | ch += copy; | - | ||||||||||||||||||
654 | } executed 144 times by 1 test: end of block Executed by:
| 144 | ||||||||||||||||||
655 | memcpy(ch, original.constData(), oldLength*sizeof(QChar)); | - | ||||||||||||||||||
656 | ch += oldLength; | - | ||||||||||||||||||
657 | *ch = 0; | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | return v4->newString(padded)->asReturnedValue(); executed 48 times by 1 test: return v4->newString(padded)->asReturnedValue(); Executed by:
| 48 | ||||||||||||||||||
660 | } | - | ||||||||||||||||||
661 | - | |||||||||||||||||||
662 | - | |||||||||||||||||||
663 | ReturnedValue StringPrototype::method_repeat(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
664 | { | - | ||||||||||||||||||
665 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
666 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
667 | if (v4->hasException)
| 16-72 | ||||||||||||||||||
668 | return QV4::Encode::undefined(); executed 16 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 16 | ||||||||||||||||||
669 | - | |||||||||||||||||||
670 | double repeats = (argc ? argv[0] : Primitive::undefinedValue()).toInteger();
| 0-71 | ||||||||||||||||||
671 | - | |||||||||||||||||||
672 | if (repeats < 0 || qIsInf(repeats))
| 4-64 | ||||||||||||||||||
673 | return v4->throwRangeError(QLatin1String("Invalid count value")); executed 12 times by 1 test: return v4->throwRangeError(QLatin1String("Invalid count value")); Executed by:
| 12 | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | return Encode(v4->newString(value.repeated(int(repeats)))); executed 60 times by 1 test: return Encode(v4->newString(value.repeated(int(repeats)))); Executed by:
| 60 | ||||||||||||||||||
676 | } | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | static void appendReplacementString(QString *result, const QString &input, const QString& replaceValue, uint* matchOffsets, int captureCount) | - | ||||||||||||||||||
679 | { | - | ||||||||||||||||||
680 | result->reserve(result->length() + replaceValue.length()); | - | ||||||||||||||||||
681 | for (int i = 0; i < replaceValue.length(); ++i) {
| 603-780 | ||||||||||||||||||
682 | if (replaceValue.at(i) == QLatin1Char('$') && i < replaceValue.length() - 1) {
| 0-532 | ||||||||||||||||||
683 | ushort ch = replaceValue.at(++i).unicode(); | - | ||||||||||||||||||
684 | uint substStart = JSC::Yarr::offsetNoMatch; | - | ||||||||||||||||||
685 | uint substEnd = JSC::Yarr::offsetNoMatch; | - | ||||||||||||||||||
686 | if (ch == '$') {
| 12-60 | ||||||||||||||||||
687 | *result += QChar(ch); | - | ||||||||||||||||||
688 | continue; executed 12 times by 1 test: continue; Executed by:
| 12 | ||||||||||||||||||
689 | } else if (ch == '&') {
| 12-48 | ||||||||||||||||||
690 | substStart = matchOffsets[0]; | - | ||||||||||||||||||
691 | substEnd = matchOffsets[1]; | - | ||||||||||||||||||
692 | } else if (ch == '`') { executed 12 times by 1 test: end of block Executed by:
| 12-36 | ||||||||||||||||||
693 | substStart = 0; | - | ||||||||||||||||||
694 | substEnd = matchOffsets[0]; | - | ||||||||||||||||||
695 | } else if (ch == '\'') { executed 12 times by 1 test: end of block Executed by:
| 12-24 | ||||||||||||||||||
696 | substStart = matchOffsets[1]; | - | ||||||||||||||||||
697 | substEnd = input.length(); | - | ||||||||||||||||||
698 | } else if (ch >= '1' && ch <= '9') { executed 12 times by 1 test: end of block Executed by:
| 0-24 | ||||||||||||||||||
699 | uint capture = ch - '0'; | - | ||||||||||||||||||
700 | Q_ASSERT(capture > 0); | - | ||||||||||||||||||
701 | if (capture < static_cast<uint>(captureCount)) {
| 0-24 | ||||||||||||||||||
702 | substStart = matchOffsets[capture * 2]; | - | ||||||||||||||||||
703 | substEnd = matchOffsets[capture * 2 + 1]; | - | ||||||||||||||||||
704 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
705 | } else if (ch == '0' && i < replaceValue.length() - 1) { executed 24 times by 1 test: end of block Executed by:
| 0-24 | ||||||||||||||||||
706 | int capture = (ch - '0') * 10; | - | ||||||||||||||||||
707 | ch = replaceValue.at(++i).unicode(); | - | ||||||||||||||||||
708 | if (ch >= '0' && ch <= '9') {
| 0 | ||||||||||||||||||
709 | capture += ch - '0'; | - | ||||||||||||||||||
710 | if (capture > 0 && capture < captureCount) {
| 0 | ||||||||||||||||||
711 | substStart = matchOffsets[capture * 2]; | - | ||||||||||||||||||
712 | substEnd = matchOffsets[capture * 2 + 1]; | - | ||||||||||||||||||
713 | } never executed: end of block | 0 | ||||||||||||||||||
714 | } never executed: end of block | 0 | ||||||||||||||||||
715 | } never executed: end of block | 0 | ||||||||||||||||||
716 | if (substStart != JSC::Yarr::offsetNoMatch && substEnd != JSC::Yarr::offsetNoMatch)
| 0-60 | ||||||||||||||||||
717 | *result += input.midRef(substStart, substEnd - substStart); executed 60 times by 1 test: *result += input.midRef(substStart, substEnd - substStart); Executed by:
| 60 | ||||||||||||||||||
718 | } else { executed 59 times by 1 test: end of block Executed by:
| 59 | ||||||||||||||||||
719 | *result += replaceValue.at(i); | - | ||||||||||||||||||
720 | } executed 532 times by 1 test: end of block Executed by:
| 532 | ||||||||||||||||||
721 | } | - | ||||||||||||||||||
722 | } executed 780 times by 1 test: end of block Executed by:
| 780 | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
725 | { | - | ||||||||||||||||||
726 | QString string; | - | ||||||||||||||||||
727 | if (const StringObject *thisString = thisObject->as<StringObject>())
| 12-2267 | ||||||||||||||||||
728 | string = thisString->d()->string->toQString(); executed 12 times by 1 test: string = thisString->d()->string->toQString(); Executed by:
| 12 | ||||||||||||||||||
729 | else | - | ||||||||||||||||||
730 | string = thisObject->toQString(); executed 2267 times by 3 tests: string = thisObject->toQString(); Executed by:
| 2267 | ||||||||||||||||||
731 | - | |||||||||||||||||||
732 | int numCaptures = 0; | - | ||||||||||||||||||
733 | int numStringMatches = 0; | - | ||||||||||||||||||
734 | - | |||||||||||||||||||
735 | uint allocatedMatchOffsets = 64; | - | ||||||||||||||||||
736 | uint _matchOffsets[64]; | - | ||||||||||||||||||
737 | uint *matchOffsets = _matchOffsets; | - | ||||||||||||||||||
738 | - | |||||||||||||||||||
739 | Scope scope(b); | - | ||||||||||||||||||
740 | ScopedValue searchValue(scope, argc ? argv[0] : Primitive::undefinedValue()); | - | ||||||||||||||||||
741 | Scoped<RegExpObject> regExp(scope, searchValue); | - | ||||||||||||||||||
742 | if (regExp) {
| 80-2199 | ||||||||||||||||||
743 | uint offset = 0; | - | ||||||||||||||||||
744 | uint nMatchOffsets = 0; | - | ||||||||||||||||||
745 | - | |||||||||||||||||||
746 | // We extract the pointer here to work around a compiler bug on Android. | - | ||||||||||||||||||
747 | Scoped<RegExp> re(scope, regExp->value()); | - | ||||||||||||||||||
748 | while (true) { | - | ||||||||||||||||||
749 | int oldSize = nMatchOffsets; | - | ||||||||||||||||||
750 | if (allocatedMatchOffsets < nMatchOffsets + re->captureCount() * 2) {
| 0-2937 | ||||||||||||||||||
751 | allocatedMatchOffsets = qMax(allocatedMatchOffsets * 2, nMatchOffsets + re->captureCount() * 2); | - | ||||||||||||||||||
752 | uint *newOffsets = (uint *)malloc(allocatedMatchOffsets*sizeof(uint)); | - | ||||||||||||||||||
753 | memcpy(newOffsets, matchOffsets, nMatchOffsets*sizeof(uint)); | - | ||||||||||||||||||
754 | if (matchOffsets != _matchOffsets)
| 0 | ||||||||||||||||||
755 | free(matchOffsets); never executed: free(matchOffsets); | 0 | ||||||||||||||||||
756 | matchOffsets = newOffsets; | - | ||||||||||||||||||
757 | } never executed: end of block | 0 | ||||||||||||||||||
758 | if (re->match(string, offset, matchOffsets + oldSize) == JSC::Yarr::offsetNoMatch) {
| 794-2144 | ||||||||||||||||||
759 | nMatchOffsets = oldSize; | - | ||||||||||||||||||
760 | break; executed 2144 times by 3 tests: break; Executed by:
| 2144 | ||||||||||||||||||
761 | } | - | ||||||||||||||||||
762 | nMatchOffsets += re->captureCount() * 2; | - | ||||||||||||||||||
763 | if (!regExp->global())
| 56-738 | ||||||||||||||||||
764 | break; executed 56 times by 1 test: break; Executed by:
| 56 | ||||||||||||||||||
765 | offset = qMax(offset + 1, matchOffsets[oldSize + 1]); | - | ||||||||||||||||||
766 | } executed 738 times by 2 tests: end of block Executed by:
| 738 | ||||||||||||||||||
767 | if (regExp->global())
| 55-2144 | ||||||||||||||||||
768 | regExp->setLastIndex(0); executed 2144 times by 3 tests: regExp->setLastIndex(0); Executed by:
| 2144 | ||||||||||||||||||
769 | numStringMatches = nMatchOffsets / (regExp->value()->captureCount() * 2); | - | ||||||||||||||||||
770 | numCaptures = regExp->value()->captureCount(); | - | ||||||||||||||||||
771 | } else { executed 2200 times by 3 tests: end of block Executed by:
| 2200 | ||||||||||||||||||
772 | numCaptures = 1; | - | ||||||||||||||||||
773 | QString searchString = searchValue->toQString(); | - | ||||||||||||||||||
774 | int idx = string.indexOf(searchString); | - | ||||||||||||||||||
775 | if (idx != -1) {
| 20-60 | ||||||||||||||||||
776 | numStringMatches = 1; | - | ||||||||||||||||||
777 | matchOffsets[0] = idx; | - | ||||||||||||||||||
778 | matchOffsets[1] = idx + searchString.length(); | - | ||||||||||||||||||
779 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
780 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||||||||
781 | - | |||||||||||||||||||
782 | QString result; | - | ||||||||||||||||||
783 | ScopedValue replacement(scope); | - | ||||||||||||||||||
784 | ScopedValue replaceValue(scope, argc > 1 ? argv[1] : Primitive::undefinedValue()); | - | ||||||||||||||||||
785 | ScopedFunctionObject searchCallback(scope, replaceValue); | - | ||||||||||||||||||
786 | if (!!searchCallback) {
| 64-2216 | ||||||||||||||||||
787 | result.reserve(string.length() + 10*numStringMatches); | - | ||||||||||||||||||
788 | ScopedValue entry(scope); | - | ||||||||||||||||||
789 | Value *arguments = scope.alloc(numCaptures + 2); | - | ||||||||||||||||||
790 | int lastEnd = 0; | - | ||||||||||||||||||
791 | for (int i = 0; i < numStringMatches; ++i) {
| 64-74 | ||||||||||||||||||
792 | for (int k = 0; k < numCaptures; ++k) {
| 74-128 | ||||||||||||||||||
793 | int idx = (i * numCaptures + k) * 2; | - | ||||||||||||||||||
794 | uint start = matchOffsets[idx]; | - | ||||||||||||||||||
795 | uint end = matchOffsets[idx + 1]; | - | ||||||||||||||||||
796 | entry = Primitive::undefinedValue(); | - | ||||||||||||||||||
797 | if (start != JSC::Yarr::offsetNoMatch && end != JSC::Yarr::offsetNoMatch)
| 0-128 | ||||||||||||||||||
798 | entry = scope.engine->newString(string.mid(start, end - start)); executed 128 times by 2 tests: entry = scope.engine->newString(string.mid(start, end - start)); Executed by:
| 128 | ||||||||||||||||||
799 | arguments[k] = entry; | - | ||||||||||||||||||
800 | } executed 128 times by 2 tests: end of block Executed by:
| 128 | ||||||||||||||||||
801 | uint matchStart = matchOffsets[i * numCaptures * 2]; | - | ||||||||||||||||||
802 | Q_ASSERT(matchStart >= static_cast<uint>(lastEnd)); | - | ||||||||||||||||||
803 | uint matchEnd = matchOffsets[i * numCaptures * 2 + 1]; | - | ||||||||||||||||||
804 | arguments[numCaptures] = Primitive::fromUInt32(matchStart); | - | ||||||||||||||||||
805 | arguments[numCaptures + 1] = scope.engine->newString(string); | - | ||||||||||||||||||
806 | - | |||||||||||||||||||
807 | Value that = Primitive::undefinedValue(); | - | ||||||||||||||||||
808 | replacement = searchCallback->call(&that, arguments, numCaptures + 2); | - | ||||||||||||||||||
809 | result += string.midRef(lastEnd, matchStart - lastEnd); | - | ||||||||||||||||||
810 | result += replacement->toQString(); | - | ||||||||||||||||||
811 | lastEnd = matchEnd; | - | ||||||||||||||||||
812 | } executed 74 times by 2 tests: end of block Executed by:
| 74 | ||||||||||||||||||
813 | result += string.midRef(lastEnd); | - | ||||||||||||||||||
814 | } else { executed 64 times by 2 tests: end of block Executed by:
| 64 | ||||||||||||||||||
815 | QString newString = replaceValue->toQString(); | - | ||||||||||||||||||
816 | result.reserve(string.length() + numStringMatches*newString.size()); | - | ||||||||||||||||||
817 | - | |||||||||||||||||||
818 | int lastEnd = 0; | - | ||||||||||||||||||
819 | for (int i = 0; i < numStringMatches; ++i) {
| 780-2216 | ||||||||||||||||||
820 | int baseIndex = i * numCaptures * 2; | - | ||||||||||||||||||
821 | uint matchStart = matchOffsets[baseIndex]; | - | ||||||||||||||||||
822 | uint matchEnd = matchOffsets[baseIndex + 1]; | - | ||||||||||||||||||
823 | if (matchStart == JSC::Yarr::offsetNoMatch)
| 0-780 | ||||||||||||||||||
824 | continue; never executed: continue; | 0 | ||||||||||||||||||
825 | - | |||||||||||||||||||
826 | result += string.midRef(lastEnd, matchStart - lastEnd); | - | ||||||||||||||||||
827 | appendReplacementString(&result, string, newString, matchOffsets + baseIndex, numCaptures); | - | ||||||||||||||||||
828 | lastEnd = matchEnd; | - | ||||||||||||||||||
829 | } executed 780 times by 1 test: end of block Executed by:
| 780 | ||||||||||||||||||
830 | result += string.midRef(lastEnd); | - | ||||||||||||||||||
831 | } executed 2216 times by 2 tests: end of block Executed by:
| 2216 | ||||||||||||||||||
832 | - | |||||||||||||||||||
833 | if (matchOffsets != _matchOffsets)
| 0-2280 | ||||||||||||||||||
834 | free(matchOffsets); never executed: free(matchOffsets); | 0 | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | return Encode(scope.engine->newString(result)); executed 2280 times by 3 tests: return Encode(scope.engine->newString(result)); Executed by:
| 2280 | ||||||||||||||||||
837 | } | - | ||||||||||||||||||
838 | - | |||||||||||||||||||
839 | ReturnedValue StringPrototype::method_search(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
840 | { | - | ||||||||||||||||||
841 | Scope scope(b); | - | ||||||||||||||||||
842 | QString string = getThisString(scope.engine, thisObject); | - | ||||||||||||||||||
843 | if (scope.engine->hasException)
| 8-112 | ||||||||||||||||||
844 | return QV4::Encode::undefined(); executed 8 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
845 | - | |||||||||||||||||||
846 | Scoped<RegExpObject> regExp(scope, argc ? argv[0] : Primitive::undefinedValue()); | - | ||||||||||||||||||
847 | if (!regExp) {
| 32-80 | ||||||||||||||||||
848 | regExp = scope.engine->regExpCtor()->callAsConstructor(argv, 1); | - | ||||||||||||||||||
849 | if (scope.engine->hasException)
| 7-72 | ||||||||||||||||||
850 | return QV4::Encode::undefined(); executed 7 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 7 | ||||||||||||||||||
851 | - | |||||||||||||||||||
852 | Q_ASSERT(regExp); | - | ||||||||||||||||||
853 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||
854 | Scoped<RegExp> re(scope, regExp->value()); | - | ||||||||||||||||||
855 | Q_ALLOCA_VAR(uint, matchOffsets, regExp->value()->captureCount() * 2 * sizeof(uint)); | - | ||||||||||||||||||
856 | uint result = re->match(string, /*offset*/0, matchOffsets); | - | ||||||||||||||||||
857 | if (result == JSC::Yarr::offsetNoMatch)
| 16-88 | ||||||||||||||||||
858 | return Encode(-1); executed 16 times by 1 test: return Encode(-1); Executed by:
| 16 | ||||||||||||||||||
859 | else | - | ||||||||||||||||||
860 | return Encode(result); executed 88 times by 1 test: return Encode(result); Executed by:
| 88 | ||||||||||||||||||
861 | } | - | ||||||||||||||||||
862 | - | |||||||||||||||||||
863 | ReturnedValue StringPrototype::method_slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
864 | { | - | ||||||||||||||||||
865 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
866 | Scope scope(v4); | - | ||||||||||||||||||
867 | ScopedString s(scope, thisAsString(v4, thisObject)); | - | ||||||||||||||||||
868 | if (v4->hasException)
| 0-280 | ||||||||||||||||||
869 | return QV4::Encode::undefined(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||||||||
870 | Q_ASSERT(s); | - | ||||||||||||||||||
871 | - | |||||||||||||||||||
872 | const double length = s->d()->length(); | - | ||||||||||||||||||
873 | - | |||||||||||||||||||
874 | double start = argc ? argv[0].toInteger() : 0;
| 8-272 | ||||||||||||||||||
875 | double end = (argc < 2 || argv[1].isUndefined())
| 12-264 | ||||||||||||||||||
876 | ? length : argv[1].toInteger(); | - | ||||||||||||||||||
877 | - | |||||||||||||||||||
878 | if (start < 0)
| 12-268 | ||||||||||||||||||
879 | start = qMax(length + start, 0.); executed 12 times by 1 test: start = qMax(length + start, 0.); Executed by:
| 12 | ||||||||||||||||||
880 | else | - | ||||||||||||||||||
881 | start = qMin(start, length); executed 268 times by 1 test: start = qMin(start, length); Executed by:
| 268 | ||||||||||||||||||
882 | - | |||||||||||||||||||
883 | if (end < 0)
| 116-164 | ||||||||||||||||||
884 | end = qMax(length + end, 0.); executed 164 times by 1 test: end = qMax(length + end, 0.); Executed by:
| 164 | ||||||||||||||||||
885 | else | - | ||||||||||||||||||
886 | end = qMin(end, length); executed 116 times by 1 test: end = qMin(end, length); Executed by:
| 116 | ||||||||||||||||||
887 | - | |||||||||||||||||||
888 | const int intStart = int(start); | - | ||||||||||||||||||
889 | const int intEnd = int(end); | - | ||||||||||||||||||
890 | - | |||||||||||||||||||
891 | int count = qMax(0, intEnd - intStart); | - | ||||||||||||||||||
892 | return Encode(v4->memoryManager->alloc<ComplexString>(s->d(), intStart, count)); executed 280 times by 1 test: return Encode(v4->memoryManager->alloc<ComplexString>(s->d(), intStart, count)); Executed by:
| 280 | ||||||||||||||||||
893 | } | - | ||||||||||||||||||
894 | - | |||||||||||||||||||
895 | ReturnedValue StringPrototype::method_split(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
896 | { | - | ||||||||||||||||||
897 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
898 | QString text = getThisString(v4, thisObject); | - | ||||||||||||||||||
899 | if (v4->hasException)
| 8-486 | ||||||||||||||||||
900 | return QV4::Encode::undefined(); executed 8 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
901 | - | |||||||||||||||||||
902 | Scope scope(v4); | - | ||||||||||||||||||
903 | ScopedValue separatorValue(scope, argc ? argv[0] : Primitive::undefinedValue()); | - | ||||||||||||||||||
904 | ScopedValue limitValue(scope, argc > 1 ? argv[1] : Primitive::undefinedValue()); | - | ||||||||||||||||||
905 | - | |||||||||||||||||||
906 | ScopedArrayObject array(scope, scope.engine->newArrayObject()); | - | ||||||||||||||||||
907 | - | |||||||||||||||||||
908 | if (separatorValue->isUndefined()) {
| 71-420 | ||||||||||||||||||
909 | if (limitValue->isUndefined()) {
| 0-72 | ||||||||||||||||||
910 | ScopedString s(scope, scope.engine->newString(text)); | - | ||||||||||||||||||
911 | array->push_back(s); | - | ||||||||||||||||||
912 | return array.asReturnedValue(); executed 70 times by 1 test: return array.asReturnedValue(); Executed by:
| 70 | ||||||||||||||||||
913 | } | - | ||||||||||||||||||
914 | RETURN_RESULT(scope.engine->newString(text.left(limitValue->toInteger()))); never executed: return QV4::Encode(scope.engine->newString(text.left(limitValue->toInteger()))); | 0 | ||||||||||||||||||
915 | } | - | ||||||||||||||||||
916 | - | |||||||||||||||||||
917 | uint limit = limitValue->isUndefined() ? UINT_MAX : limitValue->toUInt32();
| 152-268 | ||||||||||||||||||
918 | - | |||||||||||||||||||
919 | if (limit == 0)
| 60-358 | ||||||||||||||||||
920 | return array.asReturnedValue(); executed 60 times by 1 test: return array.asReturnedValue(); Executed by:
| 60 | ||||||||||||||||||
921 | - | |||||||||||||||||||
922 | Scoped<RegExpObject> re(scope, separatorValue); | - | ||||||||||||||||||
923 | if (re) {
| 104-256 | ||||||||||||||||||
924 | if (re->value()->pattern->isEmpty()) {
| 31-72 | ||||||||||||||||||
925 | re = (RegExpObject *)nullptr; | - | ||||||||||||||||||
926 | separatorValue = scope.engine->newString(); | - | ||||||||||||||||||
927 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||
928 | } executed 104 times by 1 test: end of block Executed by:
| 104 | ||||||||||||||||||
929 | - | |||||||||||||||||||
930 | ScopedString s(scope); | - | ||||||||||||||||||
931 | if (re) {
| 72-286 | ||||||||||||||||||
932 | uint offset = 0; | - | ||||||||||||||||||
933 | Q_ALLOCA_VAR(uint, matchOffsets, re->value()->captureCount() * 2 * sizeof(uint)); | - | ||||||||||||||||||
934 | while (true) { | - | ||||||||||||||||||
935 | Scoped<RegExp> regexp(scope, re->value()); | - | ||||||||||||||||||
936 | uint result = regexp->match(text, offset, matchOffsets); | - | ||||||||||||||||||
937 | if (result == JSC::Yarr::offsetNoMatch)
| 52-160 | ||||||||||||||||||
938 | break; executed 52 times by 1 test: break; Executed by:
| 52 | ||||||||||||||||||
939 | - | |||||||||||||||||||
940 | array->push_back((s = scope.engine->newString(text.mid(offset, matchOffsets[0] - offset)))); | - | ||||||||||||||||||
941 | offset = qMax(offset + 1, matchOffsets[1]); | - | ||||||||||||||||||
942 | - | |||||||||||||||||||
943 | if (array->getLength() >= limit)
| 20-140 | ||||||||||||||||||
944 | break; executed 20 times by 1 test: break; Executed by:
| 20 | ||||||||||||||||||
945 | - | |||||||||||||||||||
946 | for (int i = 1; i < re->value()->captureCount(); ++i) {
| 0-140 | ||||||||||||||||||
947 | uint start = matchOffsets[i * 2]; | - | ||||||||||||||||||
948 | uint end = matchOffsets[i * 2 + 1]; | - | ||||||||||||||||||
949 | array->push_back((s = scope.engine->newString(text.mid(start, end - start)))); | - | ||||||||||||||||||
950 | if (array->getLength() >= limit)
| 0 | ||||||||||||||||||
951 | break; never executed: break; | 0 | ||||||||||||||||||
952 | } never executed: end of block | 0 | ||||||||||||||||||
953 | } executed 140 times by 1 test: end of block Executed by:
| 140 | ||||||||||||||||||
954 | if (array->getLength() < limit)
| 20-52 | ||||||||||||||||||
955 | array->push_back((s = scope.engine->newString(text.mid(offset)))); executed 52 times by 1 test: array->push_back((s = scope.engine->newString(text.mid(offset)))); Executed by:
| 52 | ||||||||||||||||||
956 | } else { executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||
957 | QString separator = separatorValue->toQString(); | - | ||||||||||||||||||
958 | if (separator.isEmpty()) {
| 47-240 | ||||||||||||||||||
959 | for (uint i = 0; i < qMin(limit, uint(text.length())); ++i)
| 48-307 | ||||||||||||||||||
960 | array->push_back((s = scope.engine->newString(text.mid(i, 1)))); executed 307 times by 1 test: array->push_back((s = scope.engine->newString(text.mid(i, 1)))); Executed by:
| 307 | ||||||||||||||||||
961 | return array.asReturnedValue(); executed 48 times by 1 test: return array.asReturnedValue(); Executed by:
| 48 | ||||||||||||||||||
962 | } | - | ||||||||||||||||||
963 | - | |||||||||||||||||||
964 | int start = 0; | - | ||||||||||||||||||
965 | int end; | - | ||||||||||||||||||
966 | while ((end = text.indexOf(separator, start)) != -1) {
| 211-368 | ||||||||||||||||||
967 | array->push_back((s = scope.engine->newString(text.mid(start, end - start)))); | - | ||||||||||||||||||
968 | start = end + separator.size(); | - | ||||||||||||||||||
969 | if (array->getLength() >= limit)
| 28-340 | ||||||||||||||||||
970 | break; executed 28 times by 1 test: break; Executed by:
| 28 | ||||||||||||||||||
971 | } executed 340 times by 3 tests: end of block Executed by:
| 340 | ||||||||||||||||||
972 | if (array->getLength() < limit && start != -1)
| 0-211 | ||||||||||||||||||
973 | array->push_back((s = scope.engine->newString(text.mid(start)))); executed 212 times by 3 tests: array->push_back((s = scope.engine->newString(text.mid(start)))); Executed by:
| 212 | ||||||||||||||||||
974 | } executed 240 times by 3 tests: end of block Executed by:
| 240 | ||||||||||||||||||
975 | return array.asReturnedValue(); executed 312 times by 3 tests: return array.asReturnedValue(); Executed by:
| 312 | ||||||||||||||||||
976 | } | - | ||||||||||||||||||
977 | - | |||||||||||||||||||
978 | ReturnedValue StringPrototype::method_startsWith(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
979 | { | - | ||||||||||||||||||
980 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
981 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
982 | if (v4->hasException)
| 16-148 | ||||||||||||||||||
983 | return QV4::Encode::undefined(); executed 16 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 16 | ||||||||||||||||||
984 | - | |||||||||||||||||||
985 | if (argc && argv[0].as<RegExpObject>())
| 0-148 | ||||||||||||||||||
986 | return v4->throwTypeError(); executed 8 times by 1 test: return v4->throwTypeError(); Executed by:
| 8 | ||||||||||||||||||
987 | QString searchString = (argc ? argv[0] : Primitive::undefinedValue()).toQString();
| 0-140 | ||||||||||||||||||
988 | if (v4->hasException)
| 8-132 | ||||||||||||||||||
989 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
990 | - | |||||||||||||||||||
991 | int pos = 0; | - | ||||||||||||||||||
992 | if (argc > 1)
| 36-96 | ||||||||||||||||||
993 | pos = (int) argv[1].toInteger(); executed 96 times by 1 test: pos = (int) argv[1].toInteger(); Executed by:
| 96 | ||||||||||||||||||
994 | - | |||||||||||||||||||
995 | if (pos == 0)
| 56-76 | ||||||||||||||||||
996 | return Encode(value.startsWith(searchString)); executed 76 times by 1 test: return Encode(value.startsWith(searchString)); Executed by:
| 76 | ||||||||||||||||||
997 | - | |||||||||||||||||||
998 | QStringRef stringToSearch = value.midRef(pos); | - | ||||||||||||||||||
999 | RETURN_RESULT(Encode(stringToSearch.startsWith(searchString))); executed 56 times by 1 test: return QV4::Encode(Encode(stringToSearch.startsWith(searchString))); Executed by:
| 56 | ||||||||||||||||||
1000 | } | - | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | ReturnedValue StringPrototype::method_substr(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
1003 | { | - | ||||||||||||||||||
1004 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
1005 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
1006 | if (v4->hasException)
| 0-40 | ||||||||||||||||||
1007 | return QV4::Encode::undefined(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||||||||
1008 | - | |||||||||||||||||||
1009 | double start = 0; | - | ||||||||||||||||||
1010 | if (argc > 0)
| 0-40 | ||||||||||||||||||
1011 | start = argv[0].toInteger(); executed 40 times by 3 tests: start = argv[0].toInteger(); Executed by:
| 40 | ||||||||||||||||||
1012 | - | |||||||||||||||||||
1013 | double length = +qInf(); | - | ||||||||||||||||||
1014 | if (argc > 1)
| 4-36 | ||||||||||||||||||
1015 | length = argv[1].toInteger(); executed 36 times by 3 tests: length = argv[1].toInteger(); Executed by:
| 36 | ||||||||||||||||||
1016 | - | |||||||||||||||||||
1017 | double count = value.length(); | - | ||||||||||||||||||
1018 | if (start < 0)
| 0-40 | ||||||||||||||||||
1019 | start = qMax(count + start, 0.0); never executed: start = qMax(count + start, 0.0); | 0 | ||||||||||||||||||
1020 | - | |||||||||||||||||||
1021 | length = qMin(qMax(length, 0.0), count - start); | - | ||||||||||||||||||
1022 | - | |||||||||||||||||||
1023 | qint32 x = Primitive::toInt32(start); | - | ||||||||||||||||||
1024 | qint32 y = Primitive::toInt32(length); | - | ||||||||||||||||||
1025 | return Encode(v4->newString(value.mid(x, y))); executed 40 times by 3 tests: return Encode(v4->newString(value.mid(x, y))); Executed by:
| 40 | ||||||||||||||||||
1026 | } | - | ||||||||||||||||||
1027 | - | |||||||||||||||||||
1028 | ReturnedValue StringPrototype::method_substring(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
1029 | { | - | ||||||||||||||||||
1030 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
1031 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
1032 | if (v4->hasException)
| 8-191 | ||||||||||||||||||
1033 | return QV4::Encode::undefined(); executed 8 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
1034 | - | |||||||||||||||||||
1035 | int length = value.length(); | - | ||||||||||||||||||
1036 | - | |||||||||||||||||||
1037 | double start = 0; | - | ||||||||||||||||||
1038 | double end = length; | - | ||||||||||||||||||
1039 | - | |||||||||||||||||||
1040 | if (argc > 0)
| 8-184 | ||||||||||||||||||
1041 | start = argv[0].toInteger(); executed 184 times by 1 test: start = argv[0].toInteger(); Executed by:
| 184 | ||||||||||||||||||
1042 | - | |||||||||||||||||||
1043 | if (argc > 1 && !argv[1].isUndefined())
| 12-179 | ||||||||||||||||||
1044 | end = argv[1].toInteger(); executed 164 times by 1 test: end = argv[1].toInteger(); Executed by:
| 164 | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | if (std::isnan(start) || start < 0)
| 0-192 | ||||||||||||||||||
1047 | start = 0; executed 20 times by 1 test: start = 0; Executed by:
| 20 | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | if (std::isnan(end) || end < 0)
| 0-192 | ||||||||||||||||||
1050 | end = 0; executed 24 times by 1 test: end = 0; Executed by:
| 24 | ||||||||||||||||||
1051 | - | |||||||||||||||||||
1052 | if (start > length)
| 28-164 | ||||||||||||||||||
1053 | start = length; executed 28 times by 1 test: start = length; Executed by:
| 28 | ||||||||||||||||||
1054 | - | |||||||||||||||||||
1055 | if (end > length)
| 20-172 | ||||||||||||||||||
1056 | end = length; executed 20 times by 1 test: end = length; Executed by:
| 20 | ||||||||||||||||||
1057 | - | |||||||||||||||||||
1058 | if (start > end) {
| 36-156 | ||||||||||||||||||
1059 | double was = start; | - | ||||||||||||||||||
1060 | start = end; | - | ||||||||||||||||||
1061 | end = was; | - | ||||||||||||||||||
1062 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
1063 | - | |||||||||||||||||||
1064 | qint32 x = (int)start; | - | ||||||||||||||||||
1065 | qint32 y = (int)(end - start); | - | ||||||||||||||||||
1066 | return Encode(v4->newString(value.mid(x, y))); executed 191 times by 1 test: return Encode(v4->newString(value.mid(x, y))); Executed by:
| 191 | ||||||||||||||||||
1067 | } | - | ||||||||||||||||||
1068 | - | |||||||||||||||||||
1069 | ReturnedValue StringPrototype::method_toLowerCase(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||||||||
1070 | { | - | ||||||||||||||||||
1071 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
1072 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
1073 | if (v4->hasException)
| 32-1292 | ||||||||||||||||||
1074 | return QV4::Encode::undefined(); executed 32 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 32 | ||||||||||||||||||
1075 | - | |||||||||||||||||||
1076 | return Encode(v4->newString(value.toLower())); executed 1292 times by 1 test: return Encode(v4->newString(value.toLower())); Executed by:
| 1292 | ||||||||||||||||||
1077 | } | - | ||||||||||||||||||
1078 | - | |||||||||||||||||||
1079 | ReturnedValue StringPrototype::method_toLocaleLowerCase(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
1080 | { | - | ||||||||||||||||||
1081 | return method_toLowerCase(b, thisObject, argv, argc); executed 658 times by 1 test: return method_toLowerCase(b, thisObject, argv, argc); Executed by:
| 658 | ||||||||||||||||||
1082 | } | - | ||||||||||||||||||
1083 | - | |||||||||||||||||||
1084 | ReturnedValue StringPrototype::method_toUpperCase(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||||||||
1085 | { | - | ||||||||||||||||||
1086 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
1087 | const QString value = getThisString(v4, thisObject); | - | ||||||||||||||||||
1088 | if (v4->hasException)
| 32-557416 | ||||||||||||||||||
1089 | return QV4::Encode::undefined(); executed 32 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 32 | ||||||||||||||||||
1090 | - | |||||||||||||||||||
1091 | return Encode(v4->newString(value.toUpper())); executed 557416 times by 2 tests: return Encode(v4->newString(value.toUpper())); Executed by:
| 557416 | ||||||||||||||||||
1092 | } | - | ||||||||||||||||||
1093 | - | |||||||||||||||||||
1094 | ReturnedValue StringPrototype::method_toLocaleUpperCase(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
1095 | { | - | ||||||||||||||||||
1096 | return method_toUpperCase(b, thisObject, argv, argc); executed 652 times by 1 test: return method_toUpperCase(b, thisObject, argv, argc); Executed by:
| 652 | ||||||||||||||||||
1097 | } | - | ||||||||||||||||||
1098 | - | |||||||||||||||||||
1099 | ReturnedValue StringPrototype::method_trim(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||||||||
1100 | { | - | ||||||||||||||||||
1101 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||||||||
1102 | QString s = getThisString(v4, thisObject); | - | ||||||||||||||||||
1103 | if (v4->hasException)
| 11-500 | ||||||||||||||||||
1104 | return QV4::Encode::undefined(); executed 11 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 11 | ||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | const QChar *chars = s.constData(); | - | ||||||||||||||||||
1107 | int start, end; | - | ||||||||||||||||||
1108 | for (start = 0; start < s.length(); ++start) {
| 63-1163 | ||||||||||||||||||
1109 | if (!chars[start].isSpace() && chars[start].unicode() != 0xfeff)
| 28-703 | ||||||||||||||||||
1110 | break; executed 435 times by 1 test: break; Executed by:
| 435 | ||||||||||||||||||
1111 | } executed 731 times by 1 test: end of block Executed by:
| 731 | ||||||||||||||||||
1112 | for (end = s.length() - 1; end >= start; --end) {
| 63-776 | ||||||||||||||||||
1113 | if (!chars[end].isSpace() && chars[end].unicode() != 0xfeff)
| 12-448 | ||||||||||||||||||
1114 | break; executed 436 times by 1 test: break; Executed by:
| 436 | ||||||||||||||||||
1115 | } executed 343 times by 1 test: end of block Executed by:
| 343 | ||||||||||||||||||
1116 | - | |||||||||||||||||||
1117 | return Encode(v4->newString(QString(chars + start, end - start + 1))); executed 498 times by 1 test: return Encode(v4->newString(QString(chars + start, end - start + 1))); Executed by:
| 498 | ||||||||||||||||||
1118 | } | - | ||||||||||||||||||
1119 | - | |||||||||||||||||||
1120 | - | |||||||||||||||||||
1121 | - | |||||||||||||||||||
1122 | ReturnedValue StringPrototype::method_iterator(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||||||||
1123 | { | - | ||||||||||||||||||
1124 | Scope scope(b); | - | ||||||||||||||||||
1125 | ScopedString s(scope, thisObject->toString(scope.engine)); | - | ||||||||||||||||||
1126 | if (!s || thisObject->isNullOrUndefined())
| 0-94 | ||||||||||||||||||
1127 | return scope.engine->throwTypeError(); executed 8 times by 1 test: return scope.engine->throwTypeError(); Executed by:
| 8 | ||||||||||||||||||
1128 | - | |||||||||||||||||||
1129 | Scoped<StringIteratorObject> si(scope, scope.engine->memoryManager->allocate<StringIteratorObject>(s->d(), scope.engine)); | - | ||||||||||||||||||
1130 | return si->asReturnedValue(); executed 86 times by 1 test: return si->asReturnedValue(); Executed by:
| 86 | ||||||||||||||||||
1131 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |