aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi/qjsengine.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-11-26 10:46:44 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-04 09:45:38 +0100
commit8831e02402fa0b2a3cdfdc017bcbb10bf000995e (patch)
treebc926f06d9df570f02b401ea95ea1a0dd33b1d48 /src/qml/jsapi/qjsengine.cpp
parent9f4597dd7ae333f209c862e40c68a8f84255a63a (diff)
Fixup the implementation mess for QJSValue(QString)
Until now we were using a QV4::String without engine to represent this case. But this leads to lots of quirks, where we ended up trying to access the engine (or the internalclass/vtable) of this string anyway. Now just represent it by using an QString in QJSValuePrivate, and use an empty value to represent it. This adds a little bit of code to QJSValue and QJSEngine, but is more stable and maintainable in the longer term. Change-Id: I3358165ee64e788274225743a95dfb13346225cc Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsapi/qjsengine.cpp')
-rw-r--r--src/qml/jsapi/qjsengine.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index 5d8a0202fa..cb050c2518 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -49,6 +49,7 @@
#include "private/qv4mm_p.h"
#include "private/qv4globalobject_p.h"
#include "private/qv4script_p.h"
+#include "private/qv4runtime_p.h"
#include <QtCore/qdatetime.h>
#include <QtCore/qmetaobject.h>
@@ -376,6 +377,54 @@ bool QJSEngine::convertV2(const QJSValue &value, int type, void *ptr)
QV4::Scope scope(engine->m_v4Engine);
QV4::ScopedValue v(scope, vp->getValue(engine->m_v4Engine));
return engine->metaTypeFromJS(v, type, ptr);
+ } else if (vp->value.isEmpty()) {
+ // have a string based value without engine. Do conversion manually
+ if (type == QMetaType::Bool) {
+ *reinterpret_cast<bool*>(ptr) = vp->string.length() != 0;
+ return true;
+ }
+ if (type == QMetaType::QString) {
+ *reinterpret_cast<QString*>(ptr) = vp->string;
+ return true;
+ }
+ double d = QV4::__qmljs_string_to_number(vp->string);
+ switch (type) {
+ case QMetaType::Int:
+ *reinterpret_cast<int*>(ptr) = QV4::Primitive::toInt32(d);
+ return true;
+ case QMetaType::UInt:
+ *reinterpret_cast<uint*>(ptr) = QV4::Primitive::toUInt32(d);
+ return true;
+ case QMetaType::LongLong:
+ *reinterpret_cast<qlonglong*>(ptr) = QV4::Primitive::toInteger(d);
+ return true;
+ case QMetaType::ULongLong:
+ *reinterpret_cast<qulonglong*>(ptr) = QV4::Primitive::toInteger(d);
+ return true;
+ case QMetaType::Double:
+ *reinterpret_cast<double*>(ptr) = d;
+ return true;
+ case QMetaType::Float:
+ *reinterpret_cast<float*>(ptr) = d;
+ return true;
+ case QMetaType::Short:
+ *reinterpret_cast<short*>(ptr) = QV4::Primitive::toInt32(d);
+ return true;
+ case QMetaType::UShort:
+ *reinterpret_cast<unsigned short*>(ptr) = QV4::Primitive::toUInt32(d);
+ return true;
+ case QMetaType::Char:
+ *reinterpret_cast<char*>(ptr) = QV4::Primitive::toInt32(d);
+ return true;
+ case QMetaType::UChar:
+ *reinterpret_cast<unsigned char*>(ptr) = QV4::Primitive::toUInt32(d);
+ return true;
+ case QMetaType::QChar:
+ *reinterpret_cast<QChar*>(ptr) = QV4::Primitive::toUInt32(d);
+ return true;
+ default:
+ return false;
+ }
} else {
switch (type) {
case QMetaType::Bool: