summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2010-03-04 09:47:36 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2010-03-04 09:47:36 (GMT)
commita99fe8624a25f8a09fe9b3234306a4d8b3a3f38e (patch)
tree574351218cdd58a3bae7995ff7b1c5e92698b119 /src
parentc7fec28e7b2f7192c6589c37f3db3e0b4ee85460 (diff)
downloadQt-a99fe8624a25f8a09fe9b3234306a4d8b3a3f38e.zip
Qt-a99fe8624a25f8a09fe9b3234306a4d8b3a3f38e.tar.gz
Qt-a99fe8624a25f8a09fe9b3234306a4d8b3a3f38e.tar.bz2
QScript: Test against QMetaType::QVariant instead of against the string
now that QVariant is known to QMetaType, we can test for the metatype id instead of doing string comparison Reviewed-by: Kent Hansen
Diffstat (limited to 'src')
-rw-r--r--src/script/api/qscriptengine.cpp11
-rw-r--r--src/script/bridge/qscriptqobject.cpp37
2 files changed, 20 insertions, 28 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 9cd5c63..47c5262 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -2901,6 +2901,9 @@ JSC::JSValue QScriptEnginePrivate::create(JSC::ExecState *exec, int type, const
result = eng->newQObject(*reinterpret_cast<QObject* const *>(ptr));
break;
#endif
+ case QMetaType::QVariant:
+ result = jscValueFromVariant(exec, *reinterpret_cast<const QVariant*>(ptr));
+ break;
default:
if (type == qMetaTypeId<QScriptValue>()) {
result = eng->scriptValueToJSCValue(*reinterpret_cast<const QScriptValue*>(ptr));
@@ -2922,8 +2925,6 @@ JSC::JSValue QScriptEnginePrivate::create(JSC::ExecState *exec, int type, const
else {
QByteArray typeName = QMetaType::typeName(type);
- if (typeName == "QVariant")
- result = jscValueFromVariant(exec, *reinterpret_cast<const QVariant*>(ptr));
if (typeName.endsWith('*') && !*reinterpret_cast<void* const *>(ptr))
return JSC::jsNull();
else
@@ -3046,6 +3047,9 @@ bool QScriptEnginePrivate::convertValue(JSC::ExecState *exec, JSC::JSValue value
*reinterpret_cast<QVariantMap *>(ptr) = variantMapFromObject(exec, value);
return true;
} break;
+ case QMetaType::QVariant:
+ *reinterpret_cast<QVariant*>(ptr) = toVariant(exec, value);
+ return true;
default:
;
}
@@ -3096,9 +3100,6 @@ bool QScriptEnginePrivate::convertValue(JSC::ExecState *exec, JSC::JSValue value
return false;
*reinterpret_cast<QScriptValue*>(ptr) = eng->scriptValueFromJSCValue(value);
return true;
- } else if (name == "QVariant") {
- *reinterpret_cast<QVariant*>(ptr) = toVariant(exec, value);
- return true;
}
// lazy registration of some common list types
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp
index 39ba935..91636da 100644
--- a/src/script/bridge/qscriptqobject.cpp
+++ b/src/script/bridge/qscriptqobject.cpp
@@ -523,19 +523,15 @@ static JSC::JSValue callQtMethod(JSC::ExecState *exec, QMetaMethod::MethodType c
QByteArray returnTypeName = method.typeName();
int rtype = QMetaType::type(returnTypeName);
if ((rtype == 0) && !returnTypeName.isEmpty()) {
- if (returnTypeName == "QVariant") {
- types.append(QScriptMetaType::variant());
- } else {
- int enumIndex = indexOfMetaEnum(meta, returnTypeName);
- if (enumIndex != -1)
- types.append(QScriptMetaType::metaEnum(enumIndex, returnTypeName));
- else
- types.append(QScriptMetaType::unresolved(returnTypeName));
- }
+ int enumIndex = indexOfMetaEnum(meta, returnTypeName);
+ if (enumIndex != -1)
+ types.append(QScriptMetaType::metaEnum(enumIndex, returnTypeName));
+ else
+ types.append(QScriptMetaType::unresolved(returnTypeName));
} else {
if (callType == QMetaMethod::Constructor)
types.append(QScriptMetaType::metaType(QMetaType::QObjectStar, "QObject*"));
- else if (returnTypeName == "QVariant")
+ else if (rtype == QMetaType::QVariant)
types.append(QScriptMetaType::variant());
else
types.append(QScriptMetaType::metaType(rtype, returnTypeName));
@@ -547,20 +543,15 @@ static JSC::JSValue callQtMethod(JSC::ExecState *exec, QMetaMethod::MethodType c
QByteArray argTypeName = parameterTypeNames.at(i);
int atype = QMetaType::type(argTypeName);
if (atype == 0) {
- if (argTypeName == "QVariant") {
- types.append(QScriptMetaType::variant());
- } else {
- int enumIndex = indexOfMetaEnum(meta, argTypeName);
- if (enumIndex != -1)
- types.append(QScriptMetaType::metaEnum(enumIndex, argTypeName));
- else
- types.append(QScriptMetaType::unresolved(argTypeName));
- }
- } else {
- if (argTypeName == "QVariant")
- types.append(QScriptMetaType::variant());
+ int enumIndex = indexOfMetaEnum(meta, argTypeName);
+ if (enumIndex != -1)
+ types.append(QScriptMetaType::metaEnum(enumIndex, argTypeName));
else
- types.append(QScriptMetaType::metaType(atype, argTypeName));
+ types.append(QScriptMetaType::unresolved(argTypeName));
+ } else if (atype == QMetaType::QVariant) {
+ types.append(QScriptMetaType::variant());
+ } else {
+ types.append(QScriptMetaType::metaType(atype, argTypeName));
}
}