diff options
author | kh1 <[email protected]> | 2014-06-04 13:17:30 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2014-06-04 18:52:58 +0200 |
commit | 0f9cf70501fdcf60d87615b3f998c85f134948ac (patch) | |
tree | 880891b10c44647226682c660dd1811ce6722443 /src/qml/jsruntime | |
parent | 297ee9cc2cfbc9e797aee3ce660484f682bb4e61 (diff) |
Fix method overload calling of Qt slots from JavaScript
After commit ac57f185d1a2203cd4b585df7bd7af01c3ec33ed we succeed in selecting
the correct overload based on the supplied arguments. However when calling
slots on objects without a property cache, we end up using the local "dummy"
variable to store the synthetic propert data. We also store the currently best
patch in the "best" variable, which is a _pointer_ to the property data of the
match. Suppose we have 5 overloads to choose from, we find that the 3rd is
the best. Then we try the fourth but find it unsufficient and break out of
the loop. Unfortunately the "dummy" property data at this point contains the
data of the fourth (wrong) overload, and our best match variable points to it.
So then when we finally call the method, we do it based on the wrong property
data.
The easy patch is to simply copy the few bytes of property data, so "best" is
stored by value instead of pointer.
Change-Id: Ie2ebbdb88a117770b6c7b9490e1c634077020e9d
Reviewed-by: Karsten Heimrich <[email protected]>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index b61be913a6..a02424a3dc 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1407,7 +1407,7 @@ static QV4::ReturnedValue CallOverloaded(QObject *object, const QQmlPropertyData { int argumentCount = callArgs->argc; - const QQmlPropertyData *best = 0; + QQmlPropertyData best; int bestParameterScore = INT_MAX; int bestMatchScore = INT_MAX; @@ -1453,7 +1453,7 @@ static QV4::ReturnedValue CallOverloaded(QObject *object, const QQmlPropertyData methodMatchScore += MatchScore((v = callArgs->args[ii]), methodArgTypes[ii]); if (bestParameterScore > methodParameterScore || bestMatchScore > methodMatchScore) { - best = attempt; + best = *attempt; bestParameterScore = methodParameterScore; bestMatchScore = methodMatchScore; } @@ -1463,10 +1463,10 @@ static QV4::ReturnedValue CallOverloaded(QObject *object, const QQmlPropertyData } while((attempt = RelatedMethod(object, attempt, dummy)) != 0); - if (best) { + if (best.isValid()) { if (valueTypeObject) valueTypeObject->setValue(valueTypeValue); - return CallPrecise(object, *best, engine, callArgs); + return CallPrecise(object, best, engine, callArgs); } else { QString error = QLatin1String("Unable to determine callable overload. Candidates are:"); const QQmlPropertyData *candidate = &data; |