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
qv4objectiterator.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
4#include "qv4object_p.h"
5#include "qv4iterator_p.h"
6#include "qv4propertykey_p.h"
7#include <QtQml/private/qv4functionobject_p.h>
8
9using namespace QV4;
10
15
17{
18 if (!object || !iterator)
19 return PropertyKey::invalid();
20
21 Scope scope(engine);
23
24 while (1) {
25 key = iterator->next(object, pd, attrs);
26 if (!key->isValid()) {
27 object = nullptr;
28 return key;
29 }
30 if ((!(flags & WithSymbols) && key->isSymbol()) ||
31 ((flags & EnumerableOnly) && !attrs->isEnumerable()))
32 continue;
33 return key;
34 }
35}
36
38{
39 if (!object)
40 return Encode::null();
41
43 Scope scope(engine);
44 ScopedProperty p(scope);
45 ScopedPropertyKey key(scope, next(p, &attrs));
46 if (!key->isValid())
47 return Encode::null();
48
49 *value = object->getValue(p->value, attrs);
50 if (key->isArrayIndex())
51 return Encode(key->asArrayIndex());
52 Q_ASSERT(key->isStringOrSymbol());
53 return key->asStringOrSymbol()->asReturnedValue();
54}
55
57{
58 if (!object)
59 return Encode::null();
60
62 Scope scope(engine);
63 ScopedProperty p(scope);
64 ScopedPropertyKey key(scope, next(p, &attrs));
65 if (!key->isValid())
66 return Encode::null();
67
68 *value = object->getValue(p->value, attrs);
69
70 return key->toStringOrSymbol(engine)->asReturnedValue();
71}
72
74{
75 if (!object)
76 return Encode::null();
77
79 Scope scope(engine);
80 ScopedPropertyKey key(scope, next(nullptr, &attrs));
81 if (!key->isValid())
82 return Encode::null();
83
84 return key->toStringOrSymbol(engine)->asReturnedValue();
85}
86
87
89
90void Heap::ForInIteratorObject::markObjects(Heap::Base *that, MarkStack *markStack)
91{
92 ForInIteratorObject *o = static_cast<ForInIteratorObject *>(that);
93 if (o->object)
94 o->object->mark(markStack);
95 if (o->current)
96 o->current->mark(markStack);
97 o->workArea[0].mark(markStack);
98 o->workArea[1].mark(markStack);
99 Object::markObjects(that, markStack);
100}
101
102void Heap::ForInIteratorObject::destroy()
103{
104 delete iterator;
105}
106
108{
109 const ForInIteratorObject *forIn = static_cast<const ForInIteratorObject *>(thisObject);
110 Q_ASSERT(forIn);
111 Scope scope(b);
112
113 ScopedPropertyKey key(scope, forIn->nextProperty());
114 bool done = false;
115 if (!key->isValid())
116 done = true;
117 ScopedStringOrSymbol s(scope, key->toStringOrSymbol(scope.engine));
119}
120
121
123{
124 if (!d()->current)
125 return PropertyKey::invalid();
126
127 Scope scope(this);
128 ScopedObject c(scope, d()->current);
129 ScopedObject t(scope, d()->target);
130 ScopedObject o(scope);
131 ScopedProperty p(scope);
132 ScopedPropertyKey key(scope);
134
135 while (1) {
136 while (1) {
137 key = d()->iterator->next(t, p, &attrs);
138 if (!key->isValid())
139 break;
140 if (!attrs.isEnumerable() || key->isSymbol())
141 continue;
142 // check the property is not already defined earlier in the proto chain
143 if (d()->current != d()->object) {
144 o = d()->object;
145 bool shadowed = false;
146 while (o && o->d() != c->heapObject()) {
147 if (o->getOwnProperty(key) != Attr_Invalid) {
148 shadowed = true;
149 break;
150 }
151 o = o->getPrototypeOf();
152 }
153 if (shadowed)
154 continue;
155 }
156 return key;
157 }
158
159 c = c->getPrototypeOf();
160 d()->current.set(scope.engine, c->d());
161 if (!c)
162 break;
163 delete d()->iterator;
164 d()->iterator = c->ownPropertyKeys(t.getRef());
165 d()->target.set(scope.engine, t->d());
166 if (!d()->iterator) {
167 scope.engine->throwTypeError();
168 return PropertyKey::invalid();
169 }
170 }
171 return PropertyKey::invalid();
172}
short next
Definition keywords.cpp:445
typename C::iterator iterator
quint64 ReturnedValue
Scoped< StringOrSymbol > ScopedStringOrSymbol
@ Attr_Invalid
static struct AttrInfo attrs[]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean GLboolean GLboolean b
GLuint64 key
GLenum target
GLbitfield flags
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLdouble GLdouble t
Definition qopenglext.h:243
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
#define DEFINE_OBJECT_VTABLE(classname)
static constexpr ReturnedValue null()
ReturnedValue throwTypeError()
V4_NEEDS_DESTROY PropertyKey nextProperty() const
void init(ExecutionEngine *engine)
static ReturnedValue method_next(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue createIterResultObject(ExecutionEngine *engine, const Value &value, bool done)
OwnPropertyKeyIterator * iterator
ExecutionEngine * engine
PropertyKey next(Property *pd=nullptr, PropertyAttributes *attributes=nullptr)
ReturnedValue nextPropertyName(Value *value)
ReturnedValue nextPropertyNameAsString()
void defineDefaultProperty(StringOrSymbol *name, const Value &value, PropertyAttributes attributes=Attr_Data|Attr_NotEnumerable)
virtual PropertyKey next(const Object *o, Property *p=nullptr, PropertyAttributes *attrs=nullptr)=0
static PropertyKey invalid()
ExecutionEngine * engine