aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4qobjectwrapper.cpp
diff options
context:
space:
mode:
authorSebastian Sauer <[email protected]>2014-08-12 18:52:50 +0700
committerSebastian Sauer <[email protected]>2014-08-22 20:46:08 +0200
commit595340f1622783e97c53b035b78691572537f00a (patch)
treeb3c5d037fd6feaeb5cc63bf6c24545a83c861e4b /src/qml/jsruntime/qv4qobjectwrapper.cpp
parent29efdf1981a60a796e611f3bc8763afdcb6c2497 (diff)
v4: Enable primitive conversation to QQmlScriptString in javascript
This makes following QML-code proper working: ParentChange { x: 0 Component.onCompleted: x = 10 } where x is a QQmlScriptString. Before this patch an error-message would be thrown that the bool/int/string/etc cannot be converted to a QQmlScriptString. With the patch primitive types including null and undefined are proper converted to a QQmlScriptString. The patch ignores (as in not implements) function/binding assignment. Unfortunately since commit aa25ad8d5f4 its not possible any longer to instanciate QQmlScriptString what means there is otherwise no (easy) way to inject a QQmlScriptString from within Javascript. Change-Id: I18aac6a6e9a57f3b7d0a2d66cdab2be6c3c153c5 Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4qobjectwrapper.cpp')
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index e12b8f1756..c5c04c0a56 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -65,6 +65,8 @@
#include <private/qv4regexpobject_p.h>
#include <private/qv4scopedvalue_p.h>
#include <private/qv4mm_p.h>
+#include <private/qqmlscriptstring_p.h>
+#include <private/qv4compileddata_p.h>
#include <QtQml/qjsvalue.h>
#include <QtCore/qjsonarray.h>
@@ -511,7 +513,7 @@ void QObjectWrapper::setProperty(QObject *object, ExecutionContext *ctx, QQmlPro
PROPERTY_STORE(QJsonValue, QJsonValue(QJsonValue::Undefined));
} else if (!newBinding && property->propType == qMetaTypeId<QJSValue>()) {
PROPERTY_STORE(QJSValue, new QJSValuePrivate(ctx->d()->engine, value));
- } else if (value->isUndefined()) {
+ } else if (value->isUndefined() && property->propType != qMetaTypeId<QQmlScriptString>()) {
QString error = QLatin1String("Cannot assign [undefined] to ");
if (!QMetaType::typeName(property->propType))
error += QLatin1String("[unknown property type]");
@@ -535,6 +537,16 @@ void QObjectWrapper::setProperty(QObject *object, ExecutionContext *ctx, QQmlPro
QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(object);
Q_ASSERT(vmemo);
vmemo->setVMEProperty(property->coreIndex, value);
+ } else if (property->propType == qMetaTypeId<QQmlScriptString>() && (value->isUndefined() || value->isPrimitive())) {
+ QQmlScriptString ss(value->toQStringNoThrow(), 0 /* context */, object);
+ if (value->isNumber()) {
+ ss.d->numberValue = value->toNumber();
+ ss.d->isNumberLiteral = true;
+ } else if (value->isString()) {
+ ss.d->script = QV4::CompiledData::Binding::escapedString(ss.d->script);
+ ss.d->isStringLiteral = true;
+ }
+ PROPERTY_STORE(QQmlScriptString, ss);
} else {
QVariant v;
if (property->isQList())