summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-01-09 08:56:34 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-09 10:18:25 +0100
commit0460d63ed03f0de574a06268df2a267d44784cb0 (patch)
treed799a460cea254d8013b02c57f23270124c37a06
parentf19cc0aa577dcb7cf88704c58ad65605af4cd039 (diff)
downloadqtscript-0460d63ed03f0de574a06268df2a267d44784cb0.tar.gz
Fix JS to QVariant type conversion
1) The special case for LastType (QVariant) should be done before the general conversion, to avoid calling convertValue() with targetType == -1 (which is useless and causes a qWarning). 2) moc is about to be changed to use QMetaType::QVariant instead of QVariant::LastType to represent the QVariant type. But to keep the CI happy in the transition period we have to check for both. The LastType check will be removed once qtbase has been updated. 3) Get rid of the variantFromValue function in qscriptqobject. It was identical to QScriptEnginePrivate::jscValueToVariant. Change-Id: Ie418facc06c6c7308bc60a3ff66b9a78b109d3d3 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
-rw-r--r--src/script/api/qscriptengine.cpp4
-rw-r--r--src/script/bridge/qscriptqobject.cpp25
2 files changed, 3 insertions, 26 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 3783602..e3bfc61 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -1041,11 +1041,11 @@ QScriptEnginePrivate::~QScriptEnginePrivate()
QVariant QScriptEnginePrivate::jscValueToVariant(JSC::ExecState *exec, JSC::JSValue value, int targetType)
{
+ if (targetType == QMetaType::QVariant || uint(targetType) == QVariant::LastType)
+ return toVariant(exec, value);
QVariant v(targetType, (void *)0);
if (convertValue(exec, value, targetType, v.data()))
return v;
- if (uint(targetType) == QVariant::LastType)
- return toVariant(exec, value);
if (isVariant(value)) {
v = variantValue(value);
if (v.canConvert(QVariant::Type(targetType))) {
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp
index c2a71b2..126c6ec 100644
--- a/src/script/bridge/qscriptqobject.cpp
+++ b/src/script/bridge/qscriptqobject.cpp
@@ -204,29 +204,6 @@ static inline bool methodNameEquals(const QMetaMethod &method,
&& (otherSignature[nameLength] == '(');
}
-static QVariant variantFromValue(JSC::ExecState *exec, int targetType, JSC::JSValue value)
-{
- QVariant v(targetType, (void *)0);
- if (QScriptEnginePrivate::convertValue(exec, value, targetType, v.data()))
- return v;
- if (uint(targetType) == QVariant::LastType)
- return QScriptEnginePrivate::toVariant(exec, value);
- if (QScriptEnginePrivate::isVariant(value)) {
- v = QScriptEnginePrivate::variantValue(value);
- if (v.canConvert(QVariant::Type(targetType))) {
- v.convert(QVariant::Type(targetType));
- return v;
- }
- QByteArray typeName = v.typeName();
- if (typeName.endsWith('*')
- && (QMetaType::type(typeName.left(typeName.size()-1)) == targetType)) {
- return QVariant(targetType, *reinterpret_cast<void* *>(v.data()));
- }
- }
-
- return QVariant();
-}
-
static const bool GeneratePropertyFunctions = true;
static unsigned flagsForMetaProperty(const QMetaProperty &prop)
@@ -1119,7 +1096,7 @@ JSC::JSValue QtPropertyFunction::execute(JSC::ExecState *exec,
// string to enum value
v = (QString)arg.toString(exec);
} else {
- v = variantFromValue(exec, prop.userType(), arg);
+ v = QScriptEnginePrivate::jscValueToVariant(exec, arg, prop.userType());
}
QScriptable *scriptable = scriptableFromQObject(qobject);