diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-08-02 16:54:59 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-08-02 20:25:55 +0000 |
commit | a88f01364e147d9ea093bf0fdc639b45feef1788 (patch) | |
tree | cf1c49dee57f1c691eeecd633bffd0601256f236 /src/qml/jsruntime/qv4objectiterator.cpp | |
parent | 0d63c22eee293fe59d7691608deaaf3468045eb3 (diff) |
Implement ObjectIterator using the new iteration mechanism
And with that get rid of the old advanceIterator methods.
Change-Id: I969fa89d25df8992a4b08c8c081b91c92ffdfddd
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4objectiterator.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4objectiterator.cpp | 58 |
1 files changed, 13 insertions, 45 deletions
diff --git a/src/qml/jsruntime/qv4objectiterator.cpp b/src/qml/jsruntime/qv4objectiterator.cpp index a6af3ecf9b..8c5830315c 100644 --- a/src/qml/jsruntime/qv4objectiterator.cpp +++ b/src/qml/jsruntime/qv4objectiterator.cpp @@ -52,64 +52,32 @@ void ForInIteratorPrototype::init(ExecutionEngine *) defineDefaultProperty(QStringLiteral("next"), method_next, 0); } -void ObjectIterator::init(const Object *o) -{ - object->setM(o ? o->m() : nullptr); - current->setM(o ? o->m() : nullptr); - - if (object->as<ArgumentsObject>()) { - Scope scope(engine); - Scoped<ArgumentsObject> (scope, object->asReturnedValue())->fullyCreate(); - } -} - void ObjectIterator::next(Value *name, uint *index, Property *pd, PropertyAttributes *attrs) { - name->setM(nullptr); - *index = UINT_MAX; - - if (!object->as<Object>()) { + if (!object) { + *name = Encode::undefined(); *attrs = PropertyAttributes(); return; } Scope scope(engine); ScopedObject o(scope); ScopedString n(scope); + ScopedPropertyKey key(scope); while (1) { - Object *co = current->objectValue(); - if (!co) - break; - - while (1) { - co->advanceIterator(this, name, index, pd, attrs); - if (attrs->isEmpty()) - break; - // check the property is not already defined earlier in the proto chain - if (co->heapObject() != object->heapObject()) { - o = object->as<Object>(); - n = *name; - bool shadowed = false; - while (o->d() != current->heapObject()) { - PropertyKey id = n ? (n->toPropertyKey()) : PropertyKey::fromArrayIndex(*index); - if (id.isValid() && o->getOwnProperty(id) != Attr_Invalid) { - shadowed = true; - break; - } - o = o->getPrototypeOf(); - } - if (shadowed) - continue; - } + key = iterator->next(object, pd, attrs); + if (!key->isValid()) { + object = nullptr; + *name = Encode::undefined(); + *attrs = PropertyAttributes(); return; } - - current->setM(nullptr); - - arrayIndex = 0; - memberIndex = 0; + if (key->isSymbol() || ((flags & EnumerableOnly) && !attrs->isEnumerable())) + continue; + *name = key->asStringOrSymbol(); + *index = key->asArrayIndex(); + return; } - *attrs = PropertyAttributes(); } ReturnedValue ObjectIterator::nextPropertyName(Value *value) |