4#include <QtCore/qsequentialiterable.h>
8#include <private/qv4functionobject_p.h>
9#include <private/qv4arrayobject_p.h>
10#include <private/qqmlengine_p.h>
11#include <private/qv4scopedvalue_p.h>
12#include <private/qv4jscall_p.h>
13#include <private/qqmlmetatype_p.h>
14#include <private/qqmltype_p_p.h>
15#include <private/qqmlvaluetypewrapper_p.h>
28 Heap::ReferenceObject::Flags
flags =
29 Heap::ReferenceObject::EnforcesLocation;
30 if (
s->d()->metaSequence().canSetValueAtIndex())
31 flags |= Heap::ReferenceObject::CanWriteBack;
32 if (
s->d()->valueMetaType() == QMetaType::fromType<QVariant>())
33 flags |= Heap::ReferenceObject::IsVariant;
39 ref->d()->setLocation(
frame->v4Function,
frame->statementNumber());
42 return v->asReturnedValue();
45template<
typename Compare>
60 qWarning() <<
"Container has no suitable iterator for sorting";
87 if (
s->d()->isReference() && !
s->loadReference())
103 return o->engine()->id_length()->propertyKey();
114 : m_v4(v4), m_compareFn(&compareFn)
129 return result->toNumber() < 0;
153 o->setArrayType(Heap::ArrayData::Custom);
158 ReferenceObject::init(
nullptr, -1, NoFlag);
159 initTypes(listType, metaSequence);
160 m_container = listType.
create(container);
165 Heap::Object *
object,
int propertyIndex, Heap::ReferenceObject::Flags
flags)
167 ReferenceObject::init(
object, propertyIndex,
flags);
168 initTypes(listType, metaSequence);
171 setLocation(
frame->v4Function,
frame->statementNumber());
173 m_container = listType.
create(container);
174 else if (
flags & EnforcesLocation)
187 listType().
destroy(m_container);
188 ReferenceObject::destroy();
194 m_container = listType().
create();
201 if (variantReferenceType != listType()) {
209 listType().
destroy(m_container);
219 variantReferenceType.
destruct(m_container);
228 return QVariant(listType(), m_container);
235 return p->metaSequence().size(
p->storagePointer());
244 if (
v == QMetaType::fromType<QVariant>()) {
245 p->metaSequence().valueAtIndex(
p->storagePointer(),
index, &
result);
248 p->metaSequence().valueAtIndex(
p->storagePointer(),
index,
result.data());
254template<
typename Action>
257 if (
item.metaType() ==
v) {
258 action(
item.constData());
259 }
else if (
v == QMetaType::fromType<QVariant>()) {
273 p->metaSequence().addValueAtEnd(p->storagePointer(), data);
281 const QMetaSequence m = p->metaSequence();
282 void *container = p->storagePointer();
283 for (qsizetype i = 0; i < num; ++i)
284 m.addValueAtEnd(container, data);
292 p->metaSequence().setValueAtIndex(p->storagePointer(), index, data);
301 if (
m.canEraseRangeAtIterator() &&
m.hasRandomAccessIterator() &&
num > 1) {
302 void *
i =
m.end(
p->storagePointer());
303 m.advanceIterator(
i, -
num);
304 void *
j =
m.end(
p->storagePointer());
305 m.eraseRangeAtIterator(
p->storagePointer(),
i,
j);
306 m.destroyIterator(
i);
307 m.destroyIterator(
j);
309 for (
int i = 0;
i <
num; ++
i)
310 m.removeValueAtEnd(
p->storagePointer());
316 if (
d()->isReference() && !loadReference())
339 if (
d()->isReference() && !loadReference())
343 const QMetaType valueType =
d()->valueMetaType();
352 replace(
index, element);
357 valueType == QMetaType::fromType<QVariant>() ?
QVariant() :
QVariant(valueType));
376 if (
d()->isReference() && !loadReference())
378 if (index < 0 || index >=
size())
398 if (
d()->object() && otherSequence->d()->object()) {
399 return d()->object() == otherSequence->d()->object()
400 &&
d()->property() == otherSequence->d()->property();
401 }
else if (!
d()->
object() && !otherSequence->d()->object()) {
402 return this == otherSequence;
411 if (
d()->isReference() && !loadReference())
414 if (argc == 1 && argv[0].as<FunctionObject>())
426{
return d()->storagePointer(); }
443 if (
id.isArrayIndex()) {
458 if (
s->d()->isReference() && !
s->loadReference())
465 if (
id.isArrayIndex()) {
478 if (
id.isArrayIndex()) {
491 return static_cast<Sequence *
>(that)->containerIsEqualTo(
other);
506 const QMetaType valueType = sequence->d()->valueMetaType();
542 if (This->d()->isReference() && !This->loadReference())
566 if (This->d()->isReadOnly())
572 if (This->d()->isReference() && !This->loadReference())
577 if (newCount ==
count) {
579 }
else if (newCount >
count) {
580 const QMetaType valueMetaType = This->d()->valueMetaType();
589 This->removeLast(
count - newCount);
593 if (This->d()->object())
594 This->storeReference();
602 defineDefaultProperty(
engine()->id_valueOf(), method_valueOf, 0);
615 if (!
o || !
o->isV4SequenceType())
619 return o.asReturnedValue();
622 if (!
s->sort(
b, thisObject, argv, argc))
626 return o.asReturnedValue();
631 Heap::Object *
object,
int propertyIndex, Heap::ReferenceObject::Flags
flags)
651 type,
v.constData(), QMetaType::fromType<QSequentialIterable>(), &iterable)) {
672 const auto *
p =
object->d();
678 if (
p->isReference())
679 object->loadReference();
683 return QVariant(
p->listType(),
p->storagePointer());
695 if (
type.isSequentialContainer()) {
708 if (valueMetaType == QMetaType::fromType<QVariant>()) {
712 if (originalType != valueMetaType) {
720 "at position %1 from %2 to %3")
738 if (
object->d()->listType() == typeHint)
739 return object->getRawContainerPtr();
745 return object->d()->listType();
752#include "moc_qv4sequenceobject_p.cpp"
bool canRandomAccessIterate() const
Returns whether it is possible to efficiently skip over multiple values using and iterator.
Container metaContainer() const
bool canReverseIterate() const
Returns whether it is possible to iterate over the container in reverse.
QString arg(Args &&...args) const
void warning(const QQmlError &)
The QQmlEngine class provides an environment for instantiating QML components.
The QQmlError class encapsulates a QML error.
void setLine(int)
Sets the error line number.
void setDescription(const QString &)
Sets the error description.
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
bool isSequentialContainer() const
QMetaSequence listMetaSequence() const
QMetaType qListTypeId() const
static QVariant createValueType(const QJSValue &, QMetaType)
The QSequentialIterable class is an iterable interface for a container in a QVariant.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QTaggedIterator is a template class that wraps an iterator and exposes standard iterator traits.
ObjectType::Data * allocate(Args &&... args)
bool convert(QMetaType type)
Casts the variant to the requested type, targetType.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
QMetaType metaType() const
const void * constData() const
list append(new Employee("Blackpool", "Stephen"))
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
static void generateWarning(QV4::ExecutionEngine *v4, const QString &description)
static QV4::ReturnedValue method_set_length(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static QV4::ReturnedValue method_get_length(const FunctionObject *b, const Value *thisObject, const Value *, int)
static ReturnedValue doGetIndexed(const Sequence *s, qsizetype index)
void sortSequence(Sequence *sequence, const Compare &compare)
void convertAndDo(const QVariant &item, const QMetaType v, Action action)
SequenceOwnPropertyKeyIterator * containerOwnPropertyKeys(const Object *m, Value *target)
static struct AttrInfo attrs[]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static int compare(quint64 a, quint64 b)
QT_BEGIN_NAMESPACE bool qIsAtMostUintLimit(qsizetype length, uint limit=std::numeric_limits< uint >::max())
bool qIsAtMostSizetypeLimit(uint length, qsizetype limit=std::numeric_limits< qsizetype >::max())
#define THROW_TYPE_ERROR()
#define RETURN_UNDEFINED()
#define DEFINE_OBJECT_VTABLE(classname)
static constexpr ReturnedValue undefined()
MemoryManager * memoryManager
CppStackFrame * currentStackFrame
ReturnedValue throwRangeError(const Value &value)
QV4::ReturnedValue fromVariant(const QVariant &)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols=true)
QQmlEngine * qmlEngine() const
ReturnedValue throwTypeError()
Sequence * detached() const
void init(QMetaType listType, QMetaSequence metaSequence, const void *container)
QVariant toVariant() const
QMetaType listType() const
bool setVariant(const QVariant &variant)
QMetaSequence metaSequence() const
Heap::InternalClass * internalClass() const
ExecutionEngine * engine() const
bool hasProperty(PropertyKey id) const
static PropertyKey invalid()
static PropertyKey fromArrayIndex(uint idx)
static bool writeBack(HeapObject *ref, int internalIndex=AllProperties)
static bool readReference(HeapObject *ref)
Value * alloc(qint64 nValues) const =delete
bool hasException() const
SequenceCompareFunctor(QV4::ExecutionEngine *v4, const QV4::Value &compareFn)
bool operator()(const QVariant &lhs, const QVariant &rhs)
bool operator()(const QVariant &lhs, const QVariant &rhs)
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override
~SequenceOwnPropertyKeyIterator() override=default
static ReturnedValue newSequence(QV4::ExecutionEngine *engine, QMetaType type, QMetaSequence metaSequence, const void *data, Heap::Object *object, int propertyIndex, Heap::ReferenceObject::Flags flags)
static ReturnedValue method_sort(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static QVariant toVariant(const Sequence *object)
static QMetaType metaTypeForSequence(const Sequence *object)
static void * getRawContainerPtr(const Sequence *object, QMetaType typeHint)
static ReturnedValue fromVariant(QV4::ExecutionEngine *engine, const QVariant &vd)
static ReturnedValue fromData(QV4::ExecutionEngine *engine, QMetaType type, QMetaSequence metaSequence, const void *data)
static ReturnedValue method_valueOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
QV4::ReturnedValue containerGetIndexed(qsizetype index, bool *hasProperty) const
bool sort(const FunctionObject *f, const Value *, const Value *argv, int argc)
bool containerPutIndexed(qsizetype index, const QV4::Value &value)
bool containerDeleteIndexedProperty(qsizetype index)
bool containerIsEqualTo(Managed *other)
void * getRawContainerPtr() const
bool loadReference() const
void removeLast(qsizetype num)
void append(const QVariant &item)
QVariant at(qsizetype index) const
void replace(qsizetype index, const QVariant &item)
QV4_NEARLY_ALWAYS_INLINE constexpr quint32 value() const
static constexpr VTable::OwnPropertyKeys virtualOwnPropertyKeys
static constexpr VTable::DeleteProperty virtualDeleteProperty
static constexpr VTable::Get virtualGet
static constexpr VTable::Metacall virtualMetacall
static constexpr VTable::GetLength virtualGetLength
static constexpr VTable::Put virtualPut
static constexpr VTable::IsEqualTo virtualIsEqualTo
Heap::String * toString(ExecutionEngine *e) const
uint asArrayLength(bool *ok) const