From d5f12d1348fa882577d24b47958b03ab9d037b8a Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Wed, 25 May 2011 13:45:25 +1000 Subject: [PATCH] Revert "uses the cached argument info" This reverts commit 68d18d77ebac49c2b863c425969c70c5426864cd. --- .../qml/qdeclarativeobjectscriptclass.cpp | 25 +++++++++++++++++----- .../qml/qdeclarativeobjectscriptclass_p.h | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index f4ca9fe..edc1755 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -672,7 +672,7 @@ struct MetaCallArgument { inline void *dataPtr(); inline void initAsType(int type, QDeclarativeEngine *); - inline void fromScriptValue(int type, QDeclarativeEngine *, const QScriptValue &); + void fromScriptValue(int type, QDeclarativeEngine *, const QScriptValue &); inline QScriptDeclarativeClass::Value toValue(QDeclarativeEngine *); private: @@ -908,9 +908,24 @@ QDeclarativeObjectMethodScriptClass::callPrecise(QObject *object, const QDeclara QScriptContext *ctxt) { if (data.flags & QDeclarativePropertyCache::Data::HasArguments) { - if (data.paramTypes.size() > ctxt->argumentCount()) - return Value(ctxt, ctxt->throwError(QLatin1String("Insufficient arguments"))); - return callMethod(object, data.coreIndex, data.propType, data.paramTypes.size(), data.paramTypes.data(), ctxt); + + QMetaMethod m = object->metaObject()->method(data.coreIndex); + QList argTypeNames = m.parameterTypes(); + QVarLengthArray argTypes(argTypeNames.count()); + + // ### Cache + for (int ii = 0; ii < argTypeNames.count(); ++ii) { + argTypes[ii] = QMetaType::type(argTypeNames.at(ii)); + if (argTypes[ii] == QVariant::Invalid) + argTypes[ii] = enumType(object->metaObject(), QString::fromLatin1(argTypeNames.at(ii))); + if (argTypes[ii] == QVariant::Invalid) + return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii))))); + } + + if (argTypes.count() > ctxt->argumentCount()) + return Value(ctxt, ctxt->throwError(QLatin1String("Insufficient arguments"))); + + return callMethod(object, data.coreIndex, data.propType, argTypes.count(), argTypes.data(), ctxt); } else { @@ -921,7 +936,7 @@ QDeclarativeObjectMethodScriptClass::callPrecise(QObject *object, const QDeclara QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::callMethod(QObject *object, int index, - int returnType, int argCount, const int *argTypes, + int returnType, int argCount, int *argTypes, QScriptContext *ctxt) { if (argCount > 0) { diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h index 24fcbda..850a94f 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h @@ -85,7 +85,7 @@ private: Value callPrecise(QObject *, const QDeclarativePropertyCache::Data &, QScriptContext *); Value callOverloaded(MethodData *, QScriptContext *); - Value callMethod(QObject *, int index, int returnType, int argCount, const int *argTypes, QScriptContext *ctxt); + Value callMethod(QObject *, int index, int returnType, int argCount, int *argTypes, QScriptContext *ctxt); int matchScore(const QScriptValue &, int, const QByteArray &); QDeclarativePropertyCache::Data *relatedMethod(QObject *, QDeclarativePropertyCache::Data *current, -- 2.7.4