Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4setiterator.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 Crimson AS <info@crimson.no>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <private/qv4iterator_p.h>
5#include <private/qv4estable_p.h>
6#include <private/qv4setiterator_p.h>
7#include <private/qv4setobject_p.h>
8#include <private/qv4symbol_p.h>
9
10using namespace QV4;
11
13
22
24{
25 Scope scope(b);
26 const SetIteratorObject *thisObject = that->as<SetIteratorObject>();
27 if (!thisObject)
28 return scope.engine->throwTypeError(QLatin1String("Not a Set Iterator instance"));
29
30 Scoped<SetObject> s(scope, thisObject->d()->iteratedSet);
31 uint index = thisObject->d()->setNextIndex;
32 IteratorKind itemKind = thisObject->d()->iterationKind;
33
34 if (!s) {
36 return IteratorPrototype::createIterResultObject(scope.engine, undefined, true);
37 }
38
39 Value *arguments = scope.alloc(2);
40
41 while (index < s->d()->esTable->size()) {
42 s->d()->esTable->iterate(index, &arguments[0], &arguments[1]);
43 thisObject->d()->setNextIndex = index + 1;
44
45 if (itemKind == KeyValueIteratorKind) {
46 ScopedArrayObject resultArray(scope, scope.engine->newArrayObject());
47 resultArray->arrayReserve(2);
48 resultArray->arrayPut(0, arguments[0]);
49 resultArray->arrayPut(1, arguments[0]); // yes, the key is repeated.
50 resultArray->setArrayLengthUnchecked(2);
51
52 return IteratorPrototype::createIterResultObject(scope.engine, resultArray, false);
53 }
54
56 }
57
58 thisObject->d()->iteratedSet.set(scope.engine, nullptr);
60 return IteratorPrototype::createIterResultObject(scope.engine, undefined, true);
61}
62
QList< QVariant > arguments
quint64 ReturnedValue
@ KeyValueIteratorKind
Scoped< String > ScopedString
GLboolean GLboolean GLboolean b
GLuint index
[2]
GLdouble s
[6]
Definition qopenglext.h:235
GLuint GLfloat * val
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
unsigned int uint
Definition qtypes.h:34
#define DEFINE_OBJECT_VTABLE(classname)
Symbol * symbol_toStringTag() const
Heap::String * newString(char16_t c)
Heap::ArrayObject * newArrayObject(int count=0)
ReturnedValue throwTypeError()
static ReturnedValue createIterResultObject(ExecutionEngine *engine, const Value &value, bool done)
void defineDefaultProperty(StringOrSymbol *name, const Value &value, PropertyAttributes attributes=Attr_Data|Attr_NotEnumerable)
bool set(StringOrSymbol *name, const Value &v, ThrowOnFailure shouldThrow)
void defineReadonlyConfigurableProperty(const QString &name, const Value &value)
Value * alloc(qint64 nValues) const =delete
ExecutionEngine * engine
static ReturnedValue method_next(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine)
static constexpr Value undefinedValue()
Definition qv4value_p.h:191
const T * as() const
Definition qv4value_p.h:132