diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-04-09 13:32:39 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-09 16:49:05 +0200 |
commit | 7b3eb5373a0d3611c5a83379c5eb59505cc5c074 (patch) | |
tree | b2f9f5e7beb86b065ef206f5d45025975ef49905 /src/qml | |
parent | 60730cbb5e5475b5db6a15641211aa6958a93197 (diff) |
Fix unreliable behavior of array methods on qml list properties
Array methods such as forEach rely on the hasProperty boolean of getIndexed to
be set appropriately. Some getIndexed implementation - such as the
QQmlListProperty one - didn't initialize it correctly and therefore the
behavior was undefined.
Task-number: QTBUG-38088
Change-Id: I34bc3136d8cc2bc280397d0c4d5051e7d72269e8
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/jsruntime/qv4argumentsobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper.cpp | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmllistwrapper.cpp | 12 | ||||
-rw-r--r-- | src/qml/qml/qqmlxmlhttprequest.cpp | 10 |
4 files changed, 23 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp index 1c210b53b6..987b228209 100644 --- a/src/qml/jsruntime/qv4argumentsobject.cpp +++ b/src/qml/jsruntime/qv4argumentsobject.cpp @@ -160,6 +160,8 @@ ReturnedValue ArgumentsObject::getIndexed(Managed *m, uint index, bool *hasPrope *hasProperty = true; return args->context->callData->args[index].asReturnedValue(); } + if (hasProperty) + *hasProperty = false; return Encode::undefined(); } diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 54bf986b8e..a5574b706a 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -461,6 +461,9 @@ ReturnedValue QQmlIdObjectsArray::getIndexed(Managed *m, uint index, bool *hasPr return Encode::undefined(); } + if (hasProperty) + *hasProperty = true; + ExecutionEngine *v4 = m->engine(); QQmlEnginePrivate *ep = v4->v8Engine->engine() ? QQmlEnginePrivate::get(v4->v8Engine->engine()) : 0; if (ep) diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index 0d60fee5d0..fd50e2dbbc 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -129,13 +129,21 @@ ReturnedValue QmlListWrapper::getIndexed(Managed *m, uint index, bool *hasProper QV4::ExecutionEngine *e = m->engine(); QmlListWrapper *w = m->as<QmlListWrapper>(); - if (!w) + if (!w) { + if (hasProperty) + *hasProperty = false; return e->currentContext()->throwTypeError(); + } quint32 count = w->property.count ? w->property.count(&w->property) : 0; - if (index < count && w->property.at) + if (index < count && w->property.at) { + if (hasProperty) + *hasProperty = true; return QV4::QObjectWrapper::wrap(e, w->property.at(&w->property, index)); + } + if (hasProperty) + *hasProperty = false; return Primitive::undefinedValue().asReturnedValue(); } diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 184a9fe51f..d89dc92b68 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -905,8 +905,11 @@ ReturnedValue NamedNodeMap::getIndexed(Managed *m, uint index, bool *hasProperty { QV4::ExecutionEngine *v4 = m->engine(); NamedNodeMap *r = m->as<NamedNodeMap>(); - if (!r) + if (!r) { + if (hasProperty) + *hasProperty = false; return v4->currentContext()->throwTypeError(); + } QV8Engine *engine = v4->v8Engine; @@ -960,8 +963,11 @@ ReturnedValue NodeList::getIndexed(Managed *m, uint index, bool *hasProperty) { QV4::ExecutionEngine *v4 = m->engine(); NodeList *r = m->as<NodeList>(); - if (!r) + if (!r) { + if (hasProperty) + *hasProperty = false; return v4->currentContext()->throwTypeError(); + } QV8Engine *engine = v4->v8Engine; |