Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4arraybuffer.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | using namespace QV4; | - | ||||||||||||
4 | - | |||||||||||||
5 | const QV4::VTable ArrayBufferCtor::static_vtbl = { (std::is_same<ArrayBufferCtor::SuperClass, Object>::value) ? nullptr : &ArrayBufferCtor::SuperClass::static_vtbl, (sizeof(ArrayBufferCtor::Data) + sizeof(QV4::Value) - 1)/sizeof(QV4::Value), (sizeof(ArrayBufferCtor::Data) + (ArrayBufferCtor::NInlineProperties*sizeof(QV4::Value)) + QV4::Chunk::SlotSize - 1)/QV4::Chunk::SlotSize*QV4::Chunk::SlotSize/sizeof(QV4::Value) - (sizeof(ArrayBufferCtor::Data) + sizeof(QV4::Value) - 1)/sizeof(QV4::Value), ArrayBufferCtor::IsExecutionContext, ArrayBufferCtor::IsString, ArrayBufferCtor::IsObject, ArrayBufferCtor::IsFunctionObject, ArrayBufferCtor::IsErrorObject, ArrayBufferCtor::IsArrayData, ArrayBufferCtor::IsStringOrSymbol, ArrayBufferCtor::MyType, { 0, 0, 0, 0 }, "ArrayBufferCtor", ArrayBufferCtor::virtualDestroy, ArrayBufferCtor::Data::markObjects, ArrayBufferCtor::virtualIsEqualTo, ArrayBufferCtor::virtualGet, ArrayBufferCtor::virtualPut, ArrayBufferCtor::virtualDeleteProperty, ArrayBufferCtor::virtualHasProperty, ArrayBufferCtor::virtualGetOwnProperty, ArrayBufferCtor::virtualDefineOwnProperty, ArrayBufferCtor::virtualIsExtensible, ArrayBufferCtor::virtualPreventExtensions, ArrayBufferCtor::virtualGetPrototypeOf, ArrayBufferCtor::virtualSetPrototypeOf, ArrayBufferCtor::virtualGetLength, ArrayBufferCtor::virtualAdvanceIterator, ArrayBufferCtor::virtualInstanceOf, ArrayBufferCtor::virtualCall, ArrayBufferCtor::virtualCallAsConstructor, }; | - | ||||||||||||
6 | const QV4::VTable ArrayBuffer::static_vtbl = { (std::is_same<ArrayBuffer::SuperClass, Object>::value) ? nullptr : &ArrayBuffer::SuperClass::static_vtbl, (sizeof(ArrayBuffer::Data) + sizeof(QV4::Value) - 1)/sizeof(QV4::Value), (sizeof(ArrayBuffer::Data) + (ArrayBuffer::NInlineProperties*sizeof(QV4::Value)) + QV4::Chunk::SlotSize - 1)/QV4::Chunk::SlotSize*QV4::Chunk::SlotSize/sizeof(QV4::Value) - (sizeof(ArrayBuffer::Data) + sizeof(QV4::Value) - 1)/sizeof(QV4::Value), ArrayBuffer::IsExecutionContext, ArrayBuffer::IsString, ArrayBuffer::IsObject, ArrayBuffer::IsFunctionObject, ArrayBuffer::IsErrorObject, ArrayBuffer::IsArrayData, ArrayBuffer::IsStringOrSymbol, ArrayBuffer::MyType, { 0, 0, 0, 0 }, "ArrayBuffer", ArrayBuffer::virtualDestroy, ArrayBuffer::Data::markObjects, ArrayBuffer::virtualIsEqualTo, ArrayBuffer::virtualGet, ArrayBuffer::virtualPut, ArrayBuffer::virtualDeleteProperty, ArrayBuffer::virtualHasProperty, ArrayBuffer::virtualGetOwnProperty, ArrayBuffer::virtualDefineOwnProperty, ArrayBuffer::virtualIsExtensible, ArrayBuffer::virtualPreventExtensions, ArrayBuffer::virtualGetPrototypeOf, ArrayBuffer::virtualSetPrototypeOf, ArrayBuffer::virtualGetLength, ArrayBuffer::virtualAdvanceIterator, ArrayBuffer::virtualInstanceOf, ArrayBuffer::virtualCall, ArrayBuffer::virtualCallAsConstructor, }; | - | ||||||||||||
7 | - | |||||||||||||
8 | void Heap::ArrayBufferCtor::init(QV4::ExecutionContext *scope) | - | ||||||||||||
9 | { | - | ||||||||||||
10 | Heap::FunctionObject::init(scope, ([]() noexcept -> QString { enum { Size = sizeof(u"" "ArrayBuffer")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "ArrayBuffer" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 98116 times by 153 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 98116 times by 153 tests: }()));return qstring_literal_temp; Executed by:
| 98116 | ||||||||||||
11 | } executed 98418 times by 153 tests: end of block Executed by:
| 98418 | ||||||||||||
12 | - | |||||||||||||
13 | ReturnedValue ArrayBufferCtor::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *) | - | ||||||||||||
14 | { | - | ||||||||||||
15 | ExecutionEngine *v4 = f->engine(); | - | ||||||||||||
16 | Scope scope(v4); | - | ||||||||||||
17 | - | |||||||||||||
18 | ScopedValue l(scope, argc ? argv[0] : Primitive::undefinedValue()); | - | ||||||||||||
19 | double dl = l->toInteger(); | - | ||||||||||||
20 | if (v4->hasException
| 8-2308 | ||||||||||||
21 | return executed 8 times by 1 test: Encode::undefined();return Encode::undefined(); Executed by:
executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||
22 | uint len = (uint)qBound(0., dl, (double) | - | ||||||||||||
23 | (0x7fffffff * 2U + 1U) | - | ||||||||||||
24 | ); | - | ||||||||||||
25 | if (len != dl
| 28-2290 | ||||||||||||
26 | return executed 28 times by 1 test: v4->throwRangeError(QLatin1String("ArrayBuffer constructor: invalid length"));return v4->throwRangeError(QLatin1String("ArrayBuffer constructor: invalid length")); Executed by:
executed 28 times by 1 test: return v4->throwRangeError(QLatin1String("ArrayBuffer constructor: invalid length")); Executed by:
| 28 | ||||||||||||
27 | - | |||||||||||||
28 | Scoped<ArrayBuffer> a(scope, v4->newArrayBuffer(len)); | - | ||||||||||||
29 | if (scope.engine->hasException
| 0-2287 | ||||||||||||
30 | return never executed: Encode::undefined();return Encode::undefined(); never executed: return Encode::undefined(); | 0 | ||||||||||||
31 | - | |||||||||||||
32 | return executed 2280 times by 1 test: a->asReturnedValue();return a->asReturnedValue(); Executed by:
executed 2280 times by 1 test: return a->asReturnedValue(); Executed by:
| 2280 | ||||||||||||
33 | } | - | ||||||||||||
34 | - | |||||||||||||
35 | - | |||||||||||||
36 | ReturnedValue ArrayBufferCtor::virtualCall(const FunctionObject *f, const Value *, const Value *argv, int argc) | - | ||||||||||||
37 | { | - | ||||||||||||
38 | return executed 4 times by 1 test: virtualCallAsConstructor(f, argv, argc, f);return virtualCallAsConstructor(f, argv, argc, f); Executed by:
executed 4 times by 1 test: return virtualCallAsConstructor(f, argv, argc, f); Executed by:
| 4 | ||||||||||||
39 | } | - | ||||||||||||
40 | - | |||||||||||||
41 | ReturnedValue ArrayBufferCtor::method_isView(const FunctionObject *, const Value *, const Value *argv, int argc) | - | ||||||||||||
42 | { | - | ||||||||||||
43 | if (argc < 1
| 8-232 | ||||||||||||
44 | return executed 8 times by 1 test: Encode(false);return Encode(false); Executed by:
executed 8 times by 1 test: return Encode(false); Executed by:
| 8 | ||||||||||||
45 | - | |||||||||||||
46 | if (argv[0].as<TypedArray>()
| 108-124 | ||||||||||||
47 | argv[0].as<DataView>()
| 12-112 | ||||||||||||
48 | return executed 120 times by 1 test: Encode(true);return Encode(true); Executed by:
executed 120 times by 1 test: return Encode(true); Executed by:
| 120 | ||||||||||||
49 | - | |||||||||||||
50 | return executed 112 times by 1 test: Encode(false);return Encode(false); Executed by:
executed 112 times by 1 test: return Encode(false); Executed by:
| 112 | ||||||||||||
51 | } | - | ||||||||||||
52 | - | |||||||||||||
53 | - | |||||||||||||
54 | void Heap::ArrayBuffer::init(size_t length) | - | ||||||||||||
55 | { | - | ||||||||||||
56 | Object::init(); | - | ||||||||||||
57 | if (length <
| 36-21446 | ||||||||||||
58 | (0x7fffffff * 2U + 1U)
| 36-21446 | ||||||||||||
59 | ) | - | ||||||||||||
60 | data = QTypedArrayData<char>::allocate(length + 1); executed 21432 times by 2 tests: data = QTypedArrayData<char>::allocate(length + 1); Executed by:
| 21432 | ||||||||||||
61 | if (!data
| 36-21444 | ||||||||||||
62 | internalClass->engine->throwRangeError(([]() noexcept -> QString { enum { Size = sizeof(u"" "ArrayBuffer: out of memory")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "ArrayBuffer: out of memory" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 36 times by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 36 times by 1 test: }()));return qstring_literal_temp; Executed by:
| 36 | ||||||||||||
63 | return; executed 36 times by 1 test: return; Executed by:
| 36 | ||||||||||||
64 | } | - | ||||||||||||
65 | data->size = int(length); | - | ||||||||||||
66 | memset(data->data(), 0, length + 1); | - | ||||||||||||
67 | } executed 21443 times by 2 tests: end of block Executed by:
| 21443 | ||||||||||||
68 | - | |||||||||||||
69 | void Heap::ArrayBuffer::init(const QByteArray& array) | - | ||||||||||||
70 | { | - | ||||||||||||
71 | Object::init(); | - | ||||||||||||
72 | data = const_cast<QByteArray&>(array).data_ptr(); | - | ||||||||||||
73 | data->ref.ref(); | - | ||||||||||||
74 | } executed 6 times by 3 tests: end of block Executed by:
| 6 | ||||||||||||
75 | - | |||||||||||||
76 | void Heap::ArrayBuffer::destroy() | - | ||||||||||||
77 | { | - | ||||||||||||
78 | if (data
| 2-21489 | ||||||||||||
79 | QTypedArrayData<char>::deallocate(data); executed 21487 times by 3 tests: QTypedArrayData<char>::deallocate(data); Executed by:
| 21487 | ||||||||||||
80 | Object::destroy(); | - | ||||||||||||
81 | } executed 21526 times by 4 tests: end of block Executed by:
| 21526 | ||||||||||||
82 | - | |||||||||||||
83 | QByteArray ArrayBuffer::asByteArray() const | - | ||||||||||||
84 | { | - | ||||||||||||
85 | QByteArrayDataPtr ba = { d()->data }; | - | ||||||||||||
86 | ba.ptr->ref.ref(); | - | ||||||||||||
87 | return executed 6 times by 3 tests: QByteArray(ba);return QByteArray(ba); Executed by:
executed 6 times by 3 tests: return QByteArray(ba); Executed by:
| 6 | ||||||||||||
88 | } | - | ||||||||||||
89 | - | |||||||||||||
90 | void ArrayBuffer::detach() { | - | ||||||||||||
91 | if (!d()->data->ref.isShared()
| 0 | ||||||||||||
92 | return; never executed: return; | 0 | ||||||||||||
93 | - | |||||||||||||
94 | QTypedArrayData<char> *oldData = d()->data; | - | ||||||||||||
95 | - | |||||||||||||
96 | d()->data = QTypedArrayData<char>::allocate(oldData->size + 1); | - | ||||||||||||
97 | if (!d()->data
| 0 | ||||||||||||
98 | engine()->throwRangeError(([]() noexcept -> QString { enum { Size = sizeof(u"" "ArrayBuffer: out of memory")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "ArrayBuffer: out of memory" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp; never executed: }()));return qstring_literal_temp; | 0 | ||||||||||||
99 | return; never executed: return; | 0 | ||||||||||||
100 | } | - | ||||||||||||
101 | - | |||||||||||||
102 | memcpy(d()->data->data(), oldData->data(), oldData->size + 1); | - | ||||||||||||
103 | - | |||||||||||||
104 | if (!oldData->ref.deref()
| 0 | ||||||||||||
105 | QTypedArrayData<char>::deallocate(oldData); never executed: QTypedArrayData<char>::deallocate(oldData); | 0 | ||||||||||||
106 | } never executed: end of block | 0 | ||||||||||||
107 | - | |||||||||||||
108 | - | |||||||||||||
109 | void ArrayBufferPrototype::init(ExecutionEngine *engine, Object *ctor) | - | ||||||||||||
110 | { | - | ||||||||||||
111 | Scope scope(engine); | - | ||||||||||||
112 | ScopedObject o(scope); | - | ||||||||||||
113 | ctor->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(1)); | - | ||||||||||||
114 | ctor->defineReadonlyProperty(engine->id_prototype(), (o = this)); | - | ||||||||||||
115 | ctor->defineDefaultProperty(([]() noexcept -> QString { enum { Size = sizeof(u"" "isView")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "isView" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 98432 times by 153 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 98432 times by 153 tests: }()), ArrayBufferCtor::method_isView, 1);return qstring_literal_temp; Executed by:
| 98432 | ||||||||||||
116 | ctor->addSymbolSpecies(); | - | ||||||||||||
117 | - | |||||||||||||
118 | defineDefaultProperty(engine->id_constructor(), (o = ctor)); | - | ||||||||||||
119 | defineAccessorProperty(([]() noexcept -> QString { enum { Size = sizeof(u"" "byteLength")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "byteLength" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 99005 times by 153 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 99005 times by 153 tests: }()), method_get_byteLength, nullptr);return qstring_literal_temp; Executed by:
| 99005 | ||||||||||||
120 | defineDefaultProperty(([]() noexcept -> QString { enum { Size = sizeof(u"" "slice")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "slice" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 98764 times by 153 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 98764 times by 153 tests: }()), method_slice, 2);return qstring_literal_temp; Executed by:
| 98764 | ||||||||||||
121 | defineDefaultProperty(([]() noexcept -> QString { enum { Size = sizeof(u"" "toString")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "toString" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 98980 times by 153 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 98980 times by 153 tests: }()), method_toString, 0);return qstring_literal_temp; Executed by:
| 98980 | ||||||||||||
122 | ScopedString name(scope, engine->newString(([]() noexcept -> QString { enum { Size = sizeof(u"" "ArrayBuffer")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "ArrayBuffer" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 98785 times by 153 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 98785 times by 153 tests: }())));return qstring_literal_temp; Executed by:
| 98785 | ||||||||||||
123 | defineReadonlyConfigurableProperty(scope.engine->symbol_toStringTag(), name); | - | ||||||||||||
124 | } executed 99039 times by 153 tests: end of block Executed by:
| 99039 | ||||||||||||
125 | - | |||||||||||||
126 | ReturnedValue ArrayBufferPrototype::method_get_byteLength(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
127 | { | - | ||||||||||||
128 | const ArrayBuffer *a = thisObject->as<ArrayBuffer>(); | - | ||||||||||||
129 | if (!a
| 52-86 | ||||||||||||
130 | return executed 52 times by 1 test: b->engine()->throwTypeError();return b->engine()->throwTypeError(); Executed by:
executed 52 times by 1 test: return b->engine()->throwTypeError(); Executed by:
| 52 | ||||||||||||
131 | - | |||||||||||||
132 | return executed 86 times by 2 tests: Encode(a->d()->data->size);return Encode(a->d()->data->size); Executed by:
executed 86 times by 2 tests: return Encode(a->d()->data->size); Executed by:
| 86 | ||||||||||||
133 | } | - | ||||||||||||
134 | - | |||||||||||||
135 | ReturnedValue ArrayBufferPrototype::method_slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||
136 | { | - | ||||||||||||
137 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||
138 | const ArrayBuffer *a = thisObject->as<ArrayBuffer>(); | - | ||||||||||||
139 | if (!a
| 32-121 | ||||||||||||
140 | return executed 32 times by 1 test: v4->throwTypeError();return v4->throwTypeError(); Executed by:
executed 32 times by 1 test: return v4->throwTypeError(); Executed by:
| 32 | ||||||||||||
141 | - | |||||||||||||
142 | double start = argc > 0
| 45-77 | ||||||||||||
143 | double end = (argc < 2
| 4-79 | ||||||||||||
144 | a->d()->data->size : argv[1].toInteger(); | - | ||||||||||||
145 | if (v4->hasException
| 0-124 | ||||||||||||
146 | return never executed: QV4::Encode::undefined();return QV4::Encode::undefined(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||
147 | - | |||||||||||||
148 | double first = (
| 4-121 | ||||||||||||
149 | double final = (
| 4-123 | ||||||||||||
150 | - | |||||||||||||
151 | Scope scope(v4); | - | ||||||||||||
152 | ScopedFunctionObject constructor(scope, a->get(scope.engine->id_constructor())); | - | ||||||||||||
153 | if (!constructor
| 52-74 | ||||||||||||
154 | return executed 73 times by 1 test: v4->throwTypeError();return v4->throwTypeError(); Executed by:
executed 73 times by 1 test: return v4->throwTypeError(); Executed by:
| 73 | ||||||||||||
155 | - | |||||||||||||
156 | double newLen = qMax(final - first, 0.); | - | ||||||||||||
157 | ScopedValue argument(scope, QV4::Encode(newLen)); | - | ||||||||||||
158 | QV4::Scoped<ArrayBuffer> newBuffer(scope, constructor->callAsConstructor(argument, 1)); | - | ||||||||||||
159 | if (!newBuffer
| 0-51 | ||||||||||||
160 | return never executed: v4->throwTypeError();return v4->throwTypeError(); never executed: return v4->throwTypeError(); | 0 | ||||||||||||
161 | - | |||||||||||||
162 | memcpy(newBuffer->d()->data->data(), a->d()->data->data() + (uint)first, newLen); | - | ||||||||||||
163 | return executed 52 times by 1 test: Encode::undefined();return Encode::undefined(); Executed by:
executed 52 times by 1 test: return Encode::undefined(); Executed by:
| 52 | ||||||||||||
164 | } | - | ||||||||||||
165 | - | |||||||||||||
166 | ReturnedValue ArrayBufferPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
167 | { | - | ||||||||||||
168 | ExecutionEngine *v4 = b->engine(); | - | ||||||||||||
169 | const ArrayBuffer *a = thisObject->as<ArrayBuffer>(); | - | ||||||||||||
170 | if (!a
| 2-12 | ||||||||||||
171 | return executed 12 times by 1 test: QV4::Encode::undefined();return QV4::Encode::undefined(); Executed by:
executed 12 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 12 | ||||||||||||
172 | return executed 2 times by 1 test: Encode(v4->newString(QString::fromUtf8(a->asByteArray())));return Encode(v4->newString(QString::fromUtf8(a->asByteArray()))); Executed by:
executed 2 times by 1 test: return Encode(v4->newString(QString::fromUtf8(a->asByteArray()))); Executed by:
| 2 | ||||||||||||
173 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |