diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-08-13 09:47:43 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-14 08:29:21 +0200 |
commit | b0c4e816e6da2c09593cf8de2f563093947ebdaf (patch) | |
tree | 50659e7b5e8689af5d4a6cf4dd55ff75e54ce36b /src/script | |
parent | d1cf1cc364463c196dfc99f04328755a67476569 (diff) | |
download | qtscript-b0c4e816e6da2c09593cf8de2f563093947ebdaf.tar.gz |
Add default conversion for types long and ulong
Such conversion is not guaranteed to be lossless on all platforms,
but it's still reasonable to support these types by default.
JSC::JSValue already had constructors for them.
The type matching / overload resolution in the QObject binding
already handled long and ulong, but the value conversion itself
was missing, for some reason.
Task-number: QTBUG-2124
Change-Id: I14ff29a8e949403234b7659c0aca8b48bcdbda0e
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 22 | ||||
-rw-r--r-- | src/script/doc/src/scripting.qdoc | 8 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index d8eaf3f..5dc4e2d 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -3046,6 +3046,10 @@ JSC::JSValue QScriptEnginePrivate::create(JSC::ExecState *exec, int type, const return JSC::jsNumber(exec, *reinterpret_cast<const int*>(ptr)); case QMetaType::UInt: return JSC::jsNumber(exec, *reinterpret_cast<const uint*>(ptr)); + case QMetaType::Long: + return JSC::jsNumber(exec, *reinterpret_cast<const long*>(ptr)); + case QMetaType::ULong: + return JSC::jsNumber(exec, *reinterpret_cast<const ulong*>(ptr)); case QMetaType::LongLong: return JSC::jsNumber(exec, qsreal(*reinterpret_cast<const qlonglong*>(ptr))); case QMetaType::ULongLong: @@ -3153,6 +3157,12 @@ bool QScriptEnginePrivate::convertValue(JSC::ExecState *exec, JSC::JSValue value case QMetaType::UInt: *reinterpret_cast<uint*>(ptr) = toUInt32(exec, value); return true; + case QMetaType::Long: + *reinterpret_cast<long*>(ptr) = long(toInteger(exec, value)); + return true; + case QMetaType::ULong: + *reinterpret_cast<ulong*>(ptr) = ulong(toInteger(exec, value)); + return true; case QMetaType::LongLong: *reinterpret_cast<qlonglong*>(ptr) = qlonglong(toInteger(exec, value)); return true; @@ -3330,6 +3340,12 @@ bool QScriptEnginePrivate::convertNumber(qsreal value, int type, void *ptr) case QMetaType::UInt: *reinterpret_cast<uint*>(ptr) = QScript::ToUInt32(value); return true; + case QMetaType::Long: + *reinterpret_cast<long*>(ptr) = long(QScript::ToInteger(value)); + return true; + case QMetaType::ULong: + *reinterpret_cast<ulong*>(ptr) = ulong(QScript::ToInteger(value)); + return true; case QMetaType::LongLong: *reinterpret_cast<qlonglong*>(ptr) = qlonglong(QScript::ToInteger(value)); return true; @@ -3378,6 +3394,12 @@ bool QScriptEnginePrivate::convertString(const QString &value, int type, void *p case QMetaType::UInt: *reinterpret_cast<uint*>(ptr) = QScript::ToUInt32(value); return true; + case QMetaType::Long: + *reinterpret_cast<long*>(ptr) = long(QScript::ToInteger(value)); + return true; + case QMetaType::ULong: + *reinterpret_cast<ulong*>(ptr) = ulong(QScript::ToInteger(value)); + return true; case QMetaType::LongLong: *reinterpret_cast<qlonglong*>(ptr) = qlonglong(QScript::ToInteger(value)); return true; diff --git a/src/script/doc/src/scripting.qdoc b/src/script/doc/src/scripting.qdoc index 70e51b1..2e9093e 100644 --- a/src/script/doc/src/scripting.qdoc +++ b/src/script/doc/src/scripting.qdoc @@ -478,6 +478,8 @@ \row \li ushort \li QScriptValue::toUInt16() \row \li char \li char(QScriptValue::toInt32()) \row \li uchar \li unsigned char(QScriptValue::toInt32()) + \row \li long \li long(QScriptValue::toInteger()) + \row \li ulong \li ulong(QScriptValue::toInteger()) \row \li qlonglong \li qlonglong(QScriptValue::toInteger()) \row \li qulonglong \li qulonglong(QScriptValue::toInteger()) \row \li QString \li An empty string if the QScriptValue is null @@ -549,6 +551,12 @@ \row \li char \li QScriptValue(engine, value) \row \li uchar \li QScriptValue(engine, value) \row \li QString \li QScriptValue(engine, value) + \row \li long \li If the input fits in an int, QScriptValue(engine, int(value)); + otherwise, QScriptValue(engine, double(value)). Note that the latter + conversion can be lossy. + \row \li ulong \li If the input fits in a uint, QScriptValue(engine, uint(value)); + otherwise, QScriptValue(engine, double(value)). Note that the latter + conversion can be lossy. \row \li qlonglong \li QScriptValue(engine, qsreal(value)). Note that the conversion may lead to loss of precision, since not all 64-bit integers can be represented using the qsreal type. |