diff options
author | Lars Knoll <[email protected]> | 2018-08-02 23:02:08 +0200 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2018-08-04 09:16:06 +0000 |
commit | 60eab28305e7b51fe8efcb828628001674919408 (patch) | |
tree | 88179fc79d4a5f9461115ede41671126ec4ffc54 /src/qml/jsruntime/qv4objectiterator.cpp | |
parent | ab3d0c0ace581500797ec1d4c0b9042ddfe64df3 (diff) |
Simplify ObjectIterator::next
Use PropertyKey instead of two out pointers
Change-Id: I4f57bcb36fd412f19f0ed116042f7b094b5785dc
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4objectiterator.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4objectiterator.cpp | 69 |
1 files changed, 23 insertions, 46 deletions
diff --git a/src/qml/jsruntime/qv4objectiterator.cpp b/src/qml/jsruntime/qv4objectiterator.cpp index 8c5830315c..89880d86dd 100644 --- a/src/qml/jsruntime/qv4objectiterator.cpp +++ b/src/qml/jsruntime/qv4objectiterator.cpp @@ -52,98 +52,75 @@ void ForInIteratorPrototype::init(ExecutionEngine *) defineDefaultProperty(QStringLiteral("next"), method_next, 0); } -void ObjectIterator::next(Value *name, uint *index, Property *pd, PropertyAttributes *attrs) +PropertyKey ObjectIterator::next(Property *pd, PropertyAttributes *attrs) { - if (!object) { - *name = Encode::undefined(); - *attrs = PropertyAttributes(); - return; - } + if (!object) + return PropertyKey::invalid(); + Scope scope(engine); - ScopedObject o(scope); - ScopedString n(scope); ScopedPropertyKey key(scope); while (1) { key = iterator->next(object, pd, attrs); if (!key->isValid()) { object = nullptr; - *name = Encode::undefined(); - *attrs = PropertyAttributes(); - return; + return key; } if (key->isSymbol() || ((flags & EnumerableOnly) && !attrs->isEnumerable())) continue; - *name = key->asStringOrSymbol(); - *index = key->asArrayIndex(); - return; + return key; } } ReturnedValue ObjectIterator::nextPropertyName(Value *value) { - Object *o = object->objectValue(); - if (!o) + if (!object) return Encode::null(); PropertyAttributes attrs; - uint index; Scope scope(engine); ScopedProperty p(scope); - ScopedString name(scope); - next(name.getRef(), &index, p, &attrs); - if (attrs.isEmpty()) + ScopedPropertyKey key(scope, next(p, &attrs)); + if (!key->isValid()) return Encode::null(); - *value = o->getValue(p->value, attrs); - - if (!!name) - return name->asReturnedValue(); - Q_ASSERT(index < UINT_MAX); - return Encode(index); + *value = object->getValue(p->value, attrs); + if (key->isArrayIndex()) + return Encode(key->asArrayIndex()); + Q_ASSERT(key->isStringOrSymbol()); + return key->asStringOrSymbol()->asReturnedValue(); } ReturnedValue ObjectIterator::nextPropertyNameAsString(Value *value) { - Object *o = object->objectValue(); - if (!o) + if (!object) return Encode::null(); PropertyAttributes attrs; - uint index; Scope scope(engine); ScopedProperty p(scope); - ScopedString name(scope); - next(name.getRef(), &index, p, &attrs); - if (attrs.isEmpty()) + ScopedPropertyKey key(scope, next(p, &attrs)); + if (!key->isValid()) return Encode::null(); - *value = o->getValue(p->value, attrs); + *value = object->getValue(p->value, attrs); - if (!!name) - return name->asReturnedValue(); - Q_ASSERT(index < UINT_MAX); - return Encode(engine->newString(QString::number(index))); + return key->toStringOrSymbol(engine)->asReturnedValue(); } ReturnedValue ObjectIterator::nextPropertyNameAsString() { - if (!object->as<Object>()) + if (!object) return Encode::null(); PropertyAttributes attrs; - uint index; Scope scope(engine); ScopedProperty p(scope); - ScopedString name(scope); - next(name.getRef(), &index, p, &attrs); - if (attrs.isEmpty()) + ScopedPropertyKey key(scope, next(p, &attrs)); + if (!key->isValid()) return Encode::null(); - if (!!name) - return name->asReturnedValue(); - Q_ASSERT(index < UINT_MAX); - return Encode(engine->newString(QString::number(index))); + return key->toStringOrSymbol(engine)->asReturnedValue(); } |