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
qv4mapiterator.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/qv4mapiterator_p.h>
7#include <private/qv4mapobject_p.h>
8#include <private/qv4symbol_p.h>
9
10using namespace QV4;
11
13
22
24{
25 Scope scope(b);
26 const MapIteratorObject *thisObject = that->as<MapIteratorObject>();
27 if (!thisObject)
28 return scope.engine->throwTypeError(QLatin1String("Not a Map Iterator instance"));
29
30 Scoped<MapObject> s(scope, thisObject->d()->iteratedMap);
31 uint index = thisObject->d()->mapNextIndex;
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()->mapNextIndex = index + 1;
44
45 ScopedValue result(scope);
46
47 if (itemKind == KeyIteratorKind) {
48 result = arguments[0];
49 } else if (itemKind == ValueIteratorKind) {
50 result = arguments[1];
51 } else {
52 Q_ASSERT(itemKind == KeyValueIteratorKind);
53
54 result = scope.engine->newArrayObject();
55
56 Scoped<ArrayObject> resultArray(scope, result);
57 resultArray->arrayReserve(2);
58 resultArray->arrayPut(0, arguments[0]);
59 resultArray->arrayPut(1, arguments[1]);
60 resultArray->setArrayLengthUnchecked(2);
61 }
62
64 }
65
66 thisObject->d()->iteratedMap.set(scope.engine, nullptr);
68 return IteratorPrototype::createIterResultObject(scope.engine, undefined, true);
69}
70
71
QList< QVariant > arguments
quint64 ReturnedValue
@ KeyValueIteratorKind
@ ValueIteratorKind
@ KeyIteratorKind
Scoped< String > ScopedString
GLboolean GLboolean GLboolean b
GLuint index
[2]
GLdouble s
[6]
Definition qopenglext.h:235
GLuint GLfloat * val
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
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 init(ExecutionEngine *engine)
static ReturnedValue method_next(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
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 constexpr Value undefinedValue()
Definition qv4value_p.h:191
const T * as() const
Definition qv4value_p.h:132