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
qv4arrayiterator.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 Crimson AS <info@crimson.no>
2// Copyright (C) 2018 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <private/qv4iterator_p.h>
6#include <private/qv4arrayiterator_p.h>
7#include <private/qv4typedarray_p.h>
8#include <private/qv4symbol_p.h>
9
10using namespace QV4;
11
13
22
24{
25 Scope scope(b);
26 const ArrayIteratorObject *thisObject = that->as<ArrayIteratorObject>();
27 if (!thisObject)
28 return scope.engine->throwTypeError(QLatin1String("Not an Array Iterator instance"));
29
30 ScopedObject a(scope, thisObject->d()->iteratedObject);
31 if (!a) {
33 return IteratorPrototype::createIterResultObject(scope.engine, undefined, true);
34 }
35
36 quint32 index = thisObject->d()->nextIndex;
37 IteratorKind itemKind = thisObject->d()->iterationKind;
38
40
41 if (index >= len) {
42 thisObject->d()->iteratedObject.set(scope.engine, nullptr);
44 return IteratorPrototype::createIterResultObject(scope.engine, undefined, true);
45 }
46
47 thisObject->d()->nextIndex = index + 1;
48 if (itemKind == KeyIteratorKind) {
50 }
51
52 QV4::ScopedValue elementValue(scope, a->get(index));
54
55 if (itemKind == ValueIteratorKind) {
56 return IteratorPrototype::createIterResultObject(scope.engine, elementValue, false);
57 } else {
58 Q_ASSERT(itemKind == KeyValueIteratorKind);
59
60 ScopedArrayObject resultArray(scope, scope.engine->newArrayObject());
61 resultArray->arrayReserve(2);
62 resultArray->arrayPut(0, Value::fromInt32(index));
63 resultArray->arrayPut(1, elementValue);
64 resultArray->setArrayLengthUnchecked(2);
65
66 return IteratorPrototype::createIterResultObject(scope.engine, resultArray, false);
67 }
68}
69
quint64 ReturnedValue
@ KeyValueIteratorKind
@ ValueIteratorKind
@ KeyIteratorKind
Scoped< String > ScopedString
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLuint GLfloat * val
GLenum GLsizei len
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
unsigned int quint32
Definition qtypes.h:50
#define CHECK_EXCEPTION()
#define DEFINE_OBJECT_VTABLE(classname)
static ReturnedValue method_next(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine)
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)
qint64 getLength() const
bool set(StringOrSymbol *name, const Value &v, ThrowOnFailure shouldThrow)
void defineReadonlyConfigurableProperty(const QString &name, const Value &value)
ExecutionEngine * engine
static constexpr Value fromInt32(int i)
Definition qv4value_p.h:187
static constexpr Value undefinedValue()
Definition qv4value_p.h:191
const T * as() const
Definition qv4value_p.h:132