Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4dataview.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
24 | ** | - | ||||||||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
35 | ** | - | ||||||||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
37 | ** | - | ||||||||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #include "qv4dataview_p.h" | - | ||||||||||||||||||
41 | #include "qv4arraybuffer_p.h" | - | ||||||||||||||||||
42 | #include "qv4string_p.h" | - | ||||||||||||||||||
43 | #include "qv4symbol_p.h" | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | #include <QtCore/private/qnumeric_p.h> | - | ||||||||||||||||||
46 | #include "qendian.h" | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | using namespace QV4; | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | DEFINE_OBJECT_VTABLE(DataViewCtor); | - | ||||||||||||||||||
51 | DEFINE_OBJECT_VTABLE(DataView); | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | void Heap::DataViewCtor::init(QV4::ExecutionContext *scope) | - | ||||||||||||||||||
54 | { | - | ||||||||||||||||||
55 | Heap::FunctionObject::init(scope, QStringLiteral("DataView")); executed 98102 times by 153 tests: return qstring_literal_temp; Executed by:
| 98102 | ||||||||||||||||||
56 | } executed 99083 times by 153 tests: end of block Executed by:
| 99083 | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | ReturnedValue DataViewCtor::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *) | - | ||||||||||||||||||
59 | { | - | ||||||||||||||||||
60 | Scope scope(f->engine()); | - | ||||||||||||||||||
61 | Scoped<ArrayBuffer> buffer(scope, argc ? argv[0] : Primitive::undefinedValue()); | - | ||||||||||||||||||
62 | if (!buffer)
| 52-1415 | ||||||||||||||||||
63 | return scope.engine->throwTypeError(); executed 52 times by 1 test: return scope.engine->throwTypeError(); Executed by:
| 52 | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | double bo = argc > 1 ? argv[1].toNumber() : 0;
| 8-1407 | ||||||||||||||||||
66 | uint byteOffset = (uint)bo; | - | ||||||||||||||||||
67 | uint bufferLength = buffer->d()->data->size; | - | ||||||||||||||||||
68 | double bl = argc < 3 || argv[2].isUndefined() ? (bufferLength - bo) : argv[2].toNumber();
| 20-1149 | ||||||||||||||||||
69 | uint byteLength = (uint)bl; | - | ||||||||||||||||||
70 | if (bo != byteOffset || bl != byteLength || byteOffset + byteLength > bufferLength)
| 20-1392 | ||||||||||||||||||
71 | return scope.engine->throwRangeError(QStringLiteral("DataView: constructor arguments out of range")); executed 80 times by 1 test: return scope.engine->throwRangeError(([]() noexcept -> QString { enum { Size = sizeof(u"" "DataView: constructor arguments out of range")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "DataView: constructor arguments out of range" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); Executed by:
executed 80 times by 1 test: return qstring_literal_temp; Executed by:
| 80 | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | Scoped<DataView> a(scope, scope.engine->memoryManager->allocate<DataView>()); | - | ||||||||||||||||||
74 | a->d()->buffer.set(scope.engine, buffer->d()); | - | ||||||||||||||||||
75 | a->d()->byteLength = byteLength; | - | ||||||||||||||||||
76 | a->d()->byteOffset = byteOffset; | - | ||||||||||||||||||
77 | return a.asReturnedValue(); executed 1335 times by 1 test: return a.asReturnedValue(); Executed by:
| 1335 | ||||||||||||||||||
78 | } | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | ReturnedValue DataViewCtor::virtualCall(const FunctionObject *f, const Value *, const Value *argv, int argc) | - | ||||||||||||||||||
81 | { | - | ||||||||||||||||||
82 | return virtualCallAsConstructor(f, argv, argc, f); executed 4 times by 1 test: return virtualCallAsConstructor(f, argv, argc, f); Executed by:
| 4 | ||||||||||||||||||
83 | } | - | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | void DataViewPrototype::init(ExecutionEngine *engine, Object *ctor) | - | ||||||||||||||||||
86 | { | - | ||||||||||||||||||
87 | Scope scope(engine); | - | ||||||||||||||||||
88 | ScopedObject o(scope); | - | ||||||||||||||||||
89 | ctor->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(3)); | - | ||||||||||||||||||
90 | ctor->defineReadonlyProperty(engine->id_prototype(), (o = this)); | - | ||||||||||||||||||
91 | defineDefaultProperty(engine->id_constructor(), (o = ctor)); | - | ||||||||||||||||||
92 | defineAccessorProperty(QStringLiteral("buffer"), method_get_buffer, nullptr); executed 98856 times by 153 tests: return qstring_literal_temp; Executed by:
| 98856 | ||||||||||||||||||
93 | defineAccessorProperty(QStringLiteral("byteLength"), method_get_byteLength, nullptr); executed 98759 times by 153 tests: return qstring_literal_temp; Executed by:
| 98759 | ||||||||||||||||||
94 | defineAccessorProperty(QStringLiteral("byteOffset"), method_get_byteOffset, nullptr); executed 98413 times by 153 tests: return qstring_literal_temp; Executed by:
| 98413 | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | defineDefaultProperty(QStringLiteral("getInt8"), method_getChar<signed char>, 1); executed 98555 times by 153 tests: return qstring_literal_temp; Executed by:
| 98555 | ||||||||||||||||||
97 | defineDefaultProperty(QStringLiteral("getUint8"), method_getChar<unsigned char>, 1); executed 98430 times by 153 tests: return qstring_literal_temp; Executed by:
| 98430 | ||||||||||||||||||
98 | defineDefaultProperty(QStringLiteral("getInt16"), method_get<short>, 1); executed 98750 times by 153 tests: return qstring_literal_temp; Executed by:
| 98750 | ||||||||||||||||||
99 | defineDefaultProperty(QStringLiteral("getUint16"), method_get<unsigned short>, 1); executed 98771 times by 153 tests: return qstring_literal_temp; Executed by:
| 98771 | ||||||||||||||||||
100 | defineDefaultProperty(QStringLiteral("getInt32"), method_get<int>, 1); executed 98898 times by 153 tests: return qstring_literal_temp; Executed by:
| 98898 | ||||||||||||||||||
101 | defineDefaultProperty(QStringLiteral("getUint32"), method_get<unsigned int>, 1); executed 98555 times by 153 tests: return qstring_literal_temp; Executed by:
| 98555 | ||||||||||||||||||
102 | defineDefaultProperty(QStringLiteral("getFloat32"), method_getFloat<float>, 1); executed 98823 times by 153 tests: return qstring_literal_temp; Executed by:
| 98823 | ||||||||||||||||||
103 | defineDefaultProperty(QStringLiteral("getFloat64"), method_getFloat<double>, 1); executed 98762 times by 153 tests: return qstring_literal_temp; Executed by:
| 98762 | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | defineDefaultProperty(QStringLiteral("setInt8"), method_setChar<signed char>, 2); executed 98889 times by 153 tests: return qstring_literal_temp; Executed by:
| 98889 | ||||||||||||||||||
106 | defineDefaultProperty(QStringLiteral("setUint8"), method_setChar<unsigned char>, 2); executed 98892 times by 153 tests: return qstring_literal_temp; Executed by:
| 98892 | ||||||||||||||||||
107 | defineDefaultProperty(QStringLiteral("setInt16"), method_set<short>, 2); executed 98890 times by 153 tests: return qstring_literal_temp; Executed by:
| 98890 | ||||||||||||||||||
108 | defineDefaultProperty(QStringLiteral("setUint16"), method_set<unsigned short>, 2); executed 98826 times by 153 tests: return qstring_literal_temp; Executed by:
| 98826 | ||||||||||||||||||
109 | defineDefaultProperty(QStringLiteral("setInt32"), method_set<int>, 2); executed 98426 times by 153 tests: return qstring_literal_temp; Executed by:
| 98426 | ||||||||||||||||||
110 | defineDefaultProperty(QStringLiteral("setUint32"), method_set<unsigned int>, 2); executed 98589 times by 153 tests: return qstring_literal_temp; Executed by:
| 98589 | ||||||||||||||||||
111 | defineDefaultProperty(QStringLiteral("setFloat32"), method_setFloat<float>, 2); executed 98790 times by 153 tests: return qstring_literal_temp; Executed by:
| 98790 | ||||||||||||||||||
112 | defineDefaultProperty(QStringLiteral("setFloat64"), method_setFloat<double>, 2); executed 98798 times by 153 tests: return qstring_literal_temp; Executed by:
| 98798 | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | ScopedString name(scope, engine->newString(QStringLiteral("DataView"))); executed 98922 times by 153 tests: return qstring_literal_temp; Executed by:
| 98922 | ||||||||||||||||||
115 | defineReadonlyConfigurableProperty(scope.engine->symbol_toStringTag(), name); | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | // For backword compatibility | - | ||||||||||||||||||
118 | defineDefaultProperty(QStringLiteral("getUInt8"), method_getChar<unsigned char>, 1); executed 98920 times by 153 tests: return qstring_literal_temp; Executed by:
| 98920 | ||||||||||||||||||
119 | defineDefaultProperty(QStringLiteral("getUInt16"), method_get<unsigned short>, 1); executed 98972 times by 153 tests: return qstring_literal_temp; Executed by:
| 98972 | ||||||||||||||||||
120 | defineDefaultProperty(QStringLiteral("getUInt32"), method_get<unsigned int>, 1); executed 99042 times by 153 tests: return qstring_literal_temp; Executed by:
| 99042 | ||||||||||||||||||
121 | defineDefaultProperty(QStringLiteral("setUInt8"), method_setChar<unsigned char>, 1); executed 98917 times by 153 tests: return qstring_literal_temp; Executed by:
| 98917 | ||||||||||||||||||
122 | defineDefaultProperty(QStringLiteral("setUInt16"), method_set<unsigned short>, 1); executed 98629 times by 153 tests: return qstring_literal_temp; Executed by:
| 98629 | ||||||||||||||||||
123 | defineDefaultProperty(QStringLiteral("setUInt32"), method_set<unsigned int>, 1); executed 98984 times by 153 tests: return qstring_literal_temp; Executed by:
| 98984 | ||||||||||||||||||
124 | } executed 98717 times by 153 tests: end of block Executed by:
| 98717 | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | ReturnedValue DataViewPrototype::method_get_buffer(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||||||||
127 | { | - | ||||||||||||||||||
128 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
129 | if (!v)
| 52-87 | ||||||||||||||||||
130 | return b->engine()->throwTypeError(); executed 52 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 52 | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | return v->d()->buffer->asReturnedValue(); executed 87 times by 1 test: return v->d()->buffer->asReturnedValue(); Executed by:
| 87 | ||||||||||||||||||
133 | } | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | ReturnedValue DataViewPrototype::method_get_byteLength(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||||||||
136 | { | - | ||||||||||||||||||
137 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
138 | if (!v)
| 52-112 | ||||||||||||||||||
139 | return b->engine()->throwTypeError(); executed 52 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 52 | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | return Encode(v->d()->byteLength); executed 112 times by 1 test: return Encode(v->d()->byteLength); Executed by:
| 112 | ||||||||||||||||||
142 | } | - | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | ReturnedValue DataViewPrototype::method_get_byteOffset(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||||||||
145 | { | - | ||||||||||||||||||
146 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
147 | if (!v)
| 52-115 | ||||||||||||||||||
148 | return b->engine()->throwTypeError(); executed 52 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 52 | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | return Encode(v->d()->byteOffset); executed 116 times by 1 test: return Encode(v->d()->byteOffset); Executed by:
| 116 | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | template <typename T> | - | ||||||||||||||||||
154 | ReturnedValue DataViewPrototype::method_getChar(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
155 | { | - | ||||||||||||||||||
156 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
157 | if (!v || argc < 1)
| 0-444 | ||||||||||||||||||
158 | return b->engine()->throwTypeError(); executed 88 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 88 | ||||||||||||||||||
159 | double l = argv[0].toNumber(); | - | ||||||||||||||||||
160 | uint idx = (uint)l; | - | ||||||||||||||||||
161 | if (l != idx || idx + sizeof(T) > v->d()->byteLength)
| 0-420 | ||||||||||||||||||
162 | return b->engine()->throwTypeError(); executed 24 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 24 | ||||||||||||||||||
163 | idx += v->d()->byteOffset; | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | T t = T(v->d()->buffer->data->data()[idx]); | - | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | return Encode((int)t); executed 420 times by 1 test: return Encode((int)t); Executed by:
| 420 | ||||||||||||||||||
168 | } | - | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | template <typename T> | - | ||||||||||||||||||
171 | ReturnedValue DataViewPrototype::method_get(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
172 | { | - | ||||||||||||||||||
173 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
174 | if (!v || argc < 1)
| 0-1936 | ||||||||||||||||||
175 | return b->engine()->throwTypeError(); executed 176 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 176 | ||||||||||||||||||
176 | double l = argv[0].toNumber(); | - | ||||||||||||||||||
177 | uint idx = (uint)l; | - | ||||||||||||||||||
178 | if (l != idx || idx + sizeof(T) > v->d()->byteLength)
| 48-1888 | ||||||||||||||||||
179 | return b->engine()->throwTypeError(); executed 96 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 96 | ||||||||||||||||||
180 | idx += v->d()->byteOffset; | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | bool littleEndian = argc < 2 ? false : argv[1].toBoolean();
| 656-1184 | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | T t = littleEndian
| 328-1512 | ||||||||||||||||||
185 | ? qFromLittleEndian<T>((uchar *)v->d()->buffer->data->data() + idx) | - | ||||||||||||||||||
186 | : qFromBigEndian<T>((uchar *)v->d()->buffer->data->data() + idx); | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | return Encode(t); executed 1840 times by 1 test: return Encode(t); Executed by:
| 1840 | ||||||||||||||||||
189 | } | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | template <typename T> | - | ||||||||||||||||||
192 | ReturnedValue DataViewPrototype::method_getFloat(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
193 | { | - | ||||||||||||||||||
194 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
195 | if (!v || argc < 1)
| 0-1032 | ||||||||||||||||||
196 | return b->engine()->throwTypeError(); executed 88 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 88 | ||||||||||||||||||
197 | double l = argv[0].toNumber(); | - | ||||||||||||||||||
198 | uint idx = (uint)l; | - | ||||||||||||||||||
199 | if (l != idx || idx + sizeof(T) > v->d()->byteLength)
| 24-1008 | ||||||||||||||||||
200 | return b->engine()->throwTypeError(); executed 48 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 48 | ||||||||||||||||||
201 | idx += v->d()->byteOffset; | - | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | bool littleEndian = argc < 2 ? false : argv[1].toBoolean();
| 376-608 | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | if (sizeof(T) == 4) {
| 492 | ||||||||||||||||||
206 | // float | - | ||||||||||||||||||
207 | union { | - | ||||||||||||||||||
208 | uint i; | - | ||||||||||||||||||
209 | float f; | - | ||||||||||||||||||
210 | } u; | - | ||||||||||||||||||
211 | u.i = littleEndian
| 96-396 | ||||||||||||||||||
212 | ? qFromLittleEndian<uint>((uchar *)v->d()->buffer->data->data() + idx) | - | ||||||||||||||||||
213 | : qFromBigEndian<uint>((uchar *)v->d()->buffer->data->data() + idx); | - | ||||||||||||||||||
214 | return Encode(u.f); executed 492 times by 1 test: return Encode(u.f); Executed by:
| 492 | ||||||||||||||||||
215 | } else { | - | ||||||||||||||||||
216 | Q_ASSERT(sizeof(T) == 8); | - | ||||||||||||||||||
217 | union { | - | ||||||||||||||||||
218 | quint64 i; | - | ||||||||||||||||||
219 | double d; | - | ||||||||||||||||||
220 | } u; | - | ||||||||||||||||||
221 | u.i = littleEndian
| 92-400 | ||||||||||||||||||
222 | ? qFromLittleEndian<quint64>((uchar *)v->d()->buffer->data->data() + idx) | - | ||||||||||||||||||
223 | : qFromBigEndian<quint64>((uchar *)v->d()->buffer->data->data() + idx); | - | ||||||||||||||||||
224 | return Encode(u.d); executed 492 times by 1 test: return Encode(u.d); Executed by:
| 492 | ||||||||||||||||||
225 | } | - | ||||||||||||||||||
226 | } | - | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | template <typename T> | - | ||||||||||||||||||
229 | ReturnedValue DataViewPrototype::method_setChar(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
230 | { | - | ||||||||||||||||||
231 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
232 | if (!v || argc < 1)
| 0-1808 | ||||||||||||||||||
233 | return b->engine()->throwTypeError(); executed 88 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 88 | ||||||||||||||||||
234 | double l = argv[0].toNumber(); | - | ||||||||||||||||||
235 | uint idx = (uint)l; | - | ||||||||||||||||||
236 | if (l != idx || idx + sizeof(T) > v->d()->byteLength)
| 8-1776 | ||||||||||||||||||
237 | return b->engine()->throwTypeError(); executed 40 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 40 | ||||||||||||||||||
238 | idx += v->d()->byteOffset; | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | int val = argc >= 2 ? argv[1].toInt32() : 0;
| 8-1760 | ||||||||||||||||||
241 | v->d()->buffer->data->data()[idx] = (char)val; | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | RETURN_UNDEFINED(); executed 1768 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 1768 | ||||||||||||||||||
244 | } | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | template <typename T> | - | ||||||||||||||||||
247 | ReturnedValue DataViewPrototype::method_set(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
248 | { | - | ||||||||||||||||||
249 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
250 | if (!v || argc < 1)
| 0-1374 | ||||||||||||||||||
251 | return b->engine()->throwTypeError(); executed 176 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 176 | ||||||||||||||||||
252 | double l = argv[0].toNumber(); | - | ||||||||||||||||||
253 | uint idx = (uint)l; | - | ||||||||||||||||||
254 | if (l != idx || idx + sizeof(T) > v->d()->byteLength)
| 64-1312 | ||||||||||||||||||
255 | return b->engine()->throwTypeError(); executed 128 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 128 | ||||||||||||||||||
256 | idx += v->d()->byteOffset; | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | int val = argc >= 2 ? argv[1].toInt32() : 0;
| 16-1232 | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | bool littleEndian = argc < 3 ? false : argv[2].toBoolean();
| 368-880 | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | if (littleEndian)
| 160-1088 | ||||||||||||||||||
263 | qToLittleEndian<T>(val, (uchar *)v->d()->buffer->data->data() + idx); executed 160 times by 1 test: qToLittleEndian<T>(val, (uchar *)v->d()->buffer->data->data() + idx); Executed by:
| 160 | ||||||||||||||||||
264 | else | - | ||||||||||||||||||
265 | qToBigEndian<T>(val, (uchar *)v->d()->buffer->data->data() + idx); executed 1088 times by 1 test: qToBigEndian<T>(val, (uchar *)v->d()->buffer->data->data() + idx); Executed by:
| 1088 | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | RETURN_UNDEFINED(); executed 1248 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 1248 | ||||||||||||||||||
268 | } | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | template <typename T> | - | ||||||||||||||||||
271 | ReturnedValue DataViewPrototype::method_setFloat(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||||||||
272 | { | - | ||||||||||||||||||
273 | const DataView *v = thisObject->as<DataView>(); | - | ||||||||||||||||||
274 | if (!v || argc < 1)
| 0-648 | ||||||||||||||||||
275 | return b->engine()->throwTypeError(); executed 88 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 88 | ||||||||||||||||||
276 | double l = argv[0].toNumber(); | - | ||||||||||||||||||
277 | uint idx = (uint)l; | - | ||||||||||||||||||
278 | if (l != idx || idx + sizeof(T) > v->d()->byteLength)
| 32-616 | ||||||||||||||||||
279 | return b->engine()->throwTypeError(); executed 64 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 64 | ||||||||||||||||||
280 | idx += v->d()->byteOffset; | - | ||||||||||||||||||
281 | - | |||||||||||||||||||
282 | double val = argc >= 2 ? argv[1].toNumber() : qt_qnan();
| 8-576 | ||||||||||||||||||
283 | bool littleEndian = argc < 3 ? false : argv[2].toBoolean();
| 176-408 | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | if (sizeof(T) == 4) {
| 292 | ||||||||||||||||||
286 | // float | - | ||||||||||||||||||
287 | union { | - | ||||||||||||||||||
288 | uint i; | - | ||||||||||||||||||
289 | float f; | - | ||||||||||||||||||
290 | } u; | - | ||||||||||||||||||
291 | u.f = val; | - | ||||||||||||||||||
292 | if (littleEndian)
| 24-268 | ||||||||||||||||||
293 | qToLittleEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx); executed 24 times by 1 test: qToLittleEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx); Executed by:
| 24 | ||||||||||||||||||
294 | else | - | ||||||||||||||||||
295 | qToBigEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx); executed 268 times by 1 test: qToBigEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx); Executed by:
| 268 | ||||||||||||||||||
296 | } else { | - | ||||||||||||||||||
297 | Q_ASSERT(sizeof(T) == 8); | - | ||||||||||||||||||
298 | union { | - | ||||||||||||||||||
299 | quint64 i; | - | ||||||||||||||||||
300 | double d; | - | ||||||||||||||||||
301 | } u; | - | ||||||||||||||||||
302 | u.d = val; | - | ||||||||||||||||||
303 | if (littleEndian)
| 24-268 | ||||||||||||||||||
304 | qToLittleEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx); executed 24 times by 1 test: qToLittleEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx); Executed by:
| 24 | ||||||||||||||||||
305 | else | - | ||||||||||||||||||
306 | qToBigEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx); executed 268 times by 1 test: qToBigEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx); Executed by:
| 268 | ||||||||||||||||||
307 | } | - | ||||||||||||||||||
308 | RETURN_UNDEFINED(); executed 584 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 584 | ||||||||||||||||||
309 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |