aboutsummaryrefslogtreecommitdiffstats
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
parentab3d0c0ace581500797ec1d4c0b9042ddfe64df3 (diff)
Simplify ObjectIterator::next
Use PropertyKey instead of two out pointers Change-Id: I4f57bcb36fd412f19f0ed116042f7b094b5785dc Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp10
-rw-r--r--src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp15
-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
5 files changed, 38 insertions, 71 deletions
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp
index 876bb6bb60..5bfeca13e3 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp
@@ -154,15 +154,13 @@ const QV4::Object *collectProperty(const QV4::ScopedValue &value, QV4::Execution
int numProperties = 0;
QV4::ObjectIterator it(scope, o, QV4::ObjectIterator::EnumerableOnly);
QV4::PropertyAttributes attrs;
- uint index;
QV4::ScopedProperty p(scope);
- QV4::ScopedString name(scope);
+ QV4::ScopedPropertyKey name(scope);
while (true) {
- it.next(name.getRef(), &index, p, &attrs);
- if (attrs.isEmpty())
+ name = it.next(p, &attrs);
+ if (!name->isValid())
break;
- else
- ++numProperties;
+ ++numProperties;
}
dict.insert(valueKey, numProperties);
return o;
diff --git a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp
index b98cfffb6e..3b47f73949 100644
--- a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp
@@ -427,20 +427,17 @@ void Collector::collect(QJsonArray *out, const QString &parentIName, const QStri
qint64 numProperties = 0;
QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::EnumerableOnly);
QV4::ScopedProperty p(scope);
- QV4::ScopedString name(scope);
+ QV4::ScopedPropertyKey name(scope);
while (true) {
QV4::PropertyAttributes attrs;
- uint index;
- it.next(name.getRef(), &index, p, &attrs);
- if (attrs.isEmpty())
+ name = it.next(p, &attrs);
+ if (!name->isValid())
break;
- if (name.getPointer()) {
+ if (name->isStringOrSymbol()) {
++numProperties;
if (expanded) {
- if (name.getPointer()) {
- QV4::Value v = p.property->value;
- collect(&children, iname, name->toQStringNoThrow(), v);
- }
+ QV4::Value v = p.property->value;
+ collect(&children, iname, name->toQString(), v);
}
}
}
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();
}