1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39#ifndef QV4OBJECTITERATOR_H
40#define QV4OBJECTITERATOR_H
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists purely as an
47// implementation detail. This header file may change from version to
48// version without notice, or even be removed.
49//
50// We mean it.
51//
52
53#include "qv4global_p.h"
54#include "qv4object_p.h"
55
56QT_BEGIN_NAMESPACE
57
58namespace QV4 {
59
60struct Q_QML_EXPORT ObjectIterator
61{
62 enum Flags {
63 NoFlags = 0,
64 EnumerableOnly = 0x1,
65 WithSymbols = 0x2
66 };
67
68 ExecutionEngine *engine;
69 Object *object;
70 OwnPropertyKeyIterator *iterator = nullptr;
71 uint flags;
72
73 ObjectIterator(Scope &scope, const Object *o, uint flags)
74 {
75 engine = scope.engine;
76 object = static_cast<Object *>(scope.alloc());
77 this->flags = flags;
78 object->setM(o ? o->m() : nullptr);
79 if (o)
80 iterator = object->ownPropertyKeys(target: object);
81 }
82 ~ObjectIterator()
83 {
84 delete iterator;
85 }
86
87 PropertyKey next(Property *pd = nullptr, PropertyAttributes *attributes = nullptr);
88 ReturnedValue nextPropertyName(Value *value);
89 ReturnedValue nextPropertyNameAsString(Value *value);
90 ReturnedValue nextPropertyNameAsString();
91};
92
93namespace Heap {
94
95#define ForInIteratorObjectMembers(class, Member) \
96 Member(class, Pointer, Object *, object) \
97 Member(class, Pointer, Object *, current) \
98 Member(class, Pointer, Object *, target) \
99 Member(class, NoMark, OwnPropertyKeyIterator *, iterator)
100
101DECLARE_HEAP_OBJECT(ForInIteratorObject, Object) {
102 void init(QV4::Object *o);
103 Value workArea[2];
104
105 static void markObjects(Heap::Base *that, MarkStack *markStack);
106 void destroy();
107};
108
109}
110
111struct ForInIteratorPrototype : Object
112{
113 V4_PROTOTYPE(iteratorPrototype)
114 void init(ExecutionEngine *engine);
115
116 static ReturnedValue method_next(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
117};
118
119struct ForInIteratorObject: Object {
120 V4_OBJECT2(ForInIteratorObject, Object)
121 Q_MANAGED_TYPE(ForInIterator)
122 V4_PROTOTYPE(forInIteratorPrototype)
123 V4_NEEDS_DESTROY
124
125 PropertyKey nextProperty() const;
126};
127
128inline
129void Heap::ForInIteratorObject::init(QV4::Object *o)
130{
131 Object::init();
132 if (!o)
133 return;
134 object.set(e: o->engine(), newVal: o->d());
135 current.set(e: o->engine(), newVal: o->d());
136 Scope scope(o);
137 ScopedObject obj(scope);
138 iterator = o->ownPropertyKeys(target: obj.getRef());
139 target.set(e: o->engine(), newVal: obj->d());
140}
141
142
143}
144
145QT_END_NAMESPACE
146
147#endif
148

source code of qtdeclarative/src/qml/jsruntime/qv4objectiterator_p.h