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
qjsvalueiterator.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
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 "qjsvalueiterator.h"
6#include "qjsvalue_p.h"
7#include "private/qv4string_p.h"
8#include "private/qv4object_p.h"
9#include "private/qv4context_p.h"
10
12
17
19{
20 engine = nullptr;
21
23 if (!e)
24 return;
25 const QV4::Object *o = QJSValuePrivate::asManagedType<QV4::Object>(&v);
26 if (!o)
27 return;
28
29 engine = e;
30 object.set(e, o->asReturnedValue());
31 iterator.reset(o->ownPropertyKeys(object.valueRef()));
32 next();
33}
34
36{
37 QV4::Object *o = object.as<QV4::Object>();
38 if (!o || !iterator)
39 return;
40
42 while (1) {
43 key = iterator->next(o);
44 if (!key.isSymbol())
45 break;
46 }
48 nextKey.set(engine, key.id());
49}
50
52{
53 if (!engine || !iterator)
54 return false;
55 QV4::Value *val = object.valueRef();
56 return (val && val->isObject());
57}
58
97
104
113{
114 if (!d_ptr->isValid())
115 return false;
116 return QV4::PropertyKey::fromId(d_ptr->nextKey.value()).isValid();
117}
118
128{
129 if (!d_ptr->isValid())
130 return false;
131 d_ptr->next();
132 return QV4::PropertyKey::fromId(d_ptr->currentKey.value()).isValid();
133}
134
142{
143 if (!d_ptr->isValid())
144 return QString();
145 QV4::Scope scope(d_ptr->engine);
147 if (!key->isValid())
148 return QString();
149 Q_ASSERT(!key->isSymbol());
150 return key->toStringOrSymbol(d_ptr->engine)->toQString();
151}
152
153
161{
162 if (!d_ptr->isValid())
163 return QJSValue();
164 QV4::Scope scope(d_ptr->engine);
166 if (!key->isValid())
167 return QJSValue();
168
169 QV4::ScopedObject obj(scope, d_ptr->object.asManaged());
170 QV4::ScopedValue val(scope, obj->get(key));
171
172 if (scope.hasException()) {
173 scope.engine->catchException();
174 return QJSValue();
175 }
176 return QJSValuePrivate::fromReturnedValue(val->asReturnedValue());
177}
178
179
186{
187 d_ptr->init(object);
188 return *this;
189}
190
QScopedPointer< QV4::OwnPropertyKeyIterator > iterator
QV4::PersistentValue currentKey
QV4::PersistentValue nextKey
void init(const QJSValue &v)
QV4::PersistentValue object
QJSValueIteratorPrivate(const QJSValue &v)
QV4::ExecutionEngine * engine
The QJSValueIterator class provides a Java-style iterator for QJSValue.
QJSValueIterator & operator=(QJSValue &value)
Makes the iterator operate on object.
bool hasNext() const
Returns true if there is at least one item ahead of the iterator (i.e.
~QJSValueIterator()
Destroys the iterator.
QJSValueIterator(const QJSValue &value)
Constructs an iterator for traversing object.
QJSValue value() const
Returns the value of the last property that was jumped over using next().
QString name() const
Returns the name of the last property that was jumped over using next().
bool next()
Advances the iterator by one position.
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
Definition qjsvalue_p.h:197
static QV4::ExecutionEngine * engine(const QJSValue *jsval)
Definition qjsvalue_p.h:321
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Managed * asManaged() const
ReturnedValue value() const
void set(ExecutionEngine *engine, const Value &value)
Combined button and popup list for selecting options.
GLsizei const GLfloat * v
[13]
GLuint64 key
GLuint object
[3]
GLhandleARB obj
[2]
GLuint GLfloat * val
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
ReturnedValue catchException(StackTrace *trace=nullptr)
virtual PropertyKey next(const Object *o, Property *p=nullptr, PropertyAttributes *attrs=nullptr)=0
static PropertyKey fromId(quint64 id)
bool hasException() const
ExecutionEngine * engine