aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-02 23:02:08 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-04 09:16:06 +0000
commit60eab28305e7b51fe8efcb828628001674919408 (patch)
tree88179fc79d4a5f9461115ede41671126ec4ffc54 /src/qml/jsruntime
parentab3d0c0ace581500797ec1d4c0b9042ddfe64df3 (diff)
Simplify ObjectIterator::next
Use PropertyKey instead of two out pointers Change-Id: I4f57bcb36fd412f19f0ed116042f7b094b5785dc Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4objectiterator.cpp69
-rw-r--r--src/qml/jsruntime/qv4objectiterator_p.h2
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp13
3 files changed, 28 insertions, 56 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();
}
diff --git a/src/qml/jsruntime/qv4objectiterator_p.h b/src/qml/jsruntime/qv4objectiterator_p.h
index d6160b9dd0..8d7b5512d4 100644
--- a/src/qml/jsruntime/qv4objectiterator_p.h
+++ b/src/qml/jsruntime/qv4objectiterator_p.h
@@ -82,7 +82,7 @@ struct Q_QML_EXPORT ObjectIterator
delete iterator;
}
- void next(Value *name, uint *index, Property *pd, PropertyAttributes *attributes = nullptr);
+ PropertyKey next(Property *pd = nullptr, PropertyAttributes *attributes = nullptr);
ReturnedValue nextPropertyName(Value *value);
ReturnedValue nextPropertyNameAsString(Value *value);
ReturnedValue nextPropertyNameAsString();
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index 45d9a1219d..dbbd59abc9 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -317,25 +317,20 @@ ReturnedValue ObjectPrototype::method_defineProperties(const FunctionObject *b,
ScopedValue val(scope);
ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly);
- ScopedStringOrSymbol name(scope);
ScopedProperty pd(scope);
ScopedProperty n(scope);
+ ScopedPropertyKey key(scope);
while (1) {
- uint index;
PropertyAttributes attrs;
- it.next(name.getRef(), &index, pd, &attrs);
- if (attrs.isEmpty())
+ key = it.next(pd, &attrs);
+ if (!key->isValid())
break;
PropertyAttributes nattrs;
val = o->getValue(pd->value, attrs);
toPropertyDescriptor(scope.engine, val, n, &nattrs);
if (scope.engine->hasException)
return QV4::Encode::undefined();
- bool ok;
- if (name)
- ok = O->defineOwnProperty(name->toPropertyKey(), n, nattrs);
- else
- ok = O->defineOwnProperty(PropertyKey::fromArrayIndex(index), n, nattrs);
+ bool ok = O->defineOwnProperty(key, n, nattrs);
if (!ok)
THROW_TYPE_ERROR();
}