#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>
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]");
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())
void onCompleted();
void onDestruction();
void scriptString();
+ void scriptStringJs();
void scriptStringWithoutSourceCode();
void defaultPropertyListOrder();
void declaredPropertyValues();
}
}
+// Check that assignments to QQmlScriptString properties works also from within Javascript
+void tst_qqmllanguage::scriptStringJs()
+{
+ QQmlComponent component(&engine, testFileUrl("scriptStringJs.qml"));
+ VERIFY_ERRORS(0);
+
+ MyTypeObject *object = qobject_cast<MyTypeObject*>(component.create());
+ QVERIFY(object != 0);
+ QQmlContext *context = QQmlEngine::contextForObject(object);
+ QVERIFY(context != 0);
+ bool ok;
+
+ QCOMPARE(QQmlScriptStringPrivate::get(object->scriptProperty())->script, QString("\" hello \\\" world \""));
+ QVERIFY(!object->scriptProperty().isEmpty());
+ QVERIFY(!object->scriptProperty().isUndefinedLiteral());
+ QVERIFY(!object->scriptProperty().isNullLiteral());
+ QCOMPARE(object->scriptProperty().stringLiteral(), QString(" hello \\\" world "));
+ QVERIFY(object->scriptProperty().numberLiteral(&ok) == 0.0 && !ok);
+ QVERIFY(!object->scriptProperty().booleanLiteral(&ok) && !ok);
+
+ QJSValue inst = engine.newQObject(object);
+ QJSValue func = engine.evaluate("function(value) { this.scriptProperty = value }");
+
+ func.callWithInstance(inst, QJSValueList() << "test a \"string ");
+ QCOMPARE(QQmlScriptStringPrivate::get(object->scriptProperty())->script, QString("\"test a \\\"string \""));
+ QVERIFY(!object->scriptProperty().isEmpty());
+ QVERIFY(!object->scriptProperty().isUndefinedLiteral());
+ QVERIFY(!object->scriptProperty().isNullLiteral());
+ QCOMPARE(object->scriptProperty().stringLiteral(), QString("test a \\\"string "));
+ QVERIFY(object->scriptProperty().numberLiteral(&ok) == 0.0 && !ok);
+ QVERIFY(!object->scriptProperty().booleanLiteral(&ok) && !ok);
+
+ func.callWithInstance(inst, QJSValueList() << QJSValue::UndefinedValue);
+ QCOMPARE(QQmlScriptStringPrivate::get(object->scriptProperty())->script, QString("undefined"));
+ QVERIFY(!object->scriptProperty().isEmpty());
+ QVERIFY(object->scriptProperty().isUndefinedLiteral());
+ QVERIFY(!object->scriptProperty().isNullLiteral());
+ QVERIFY(object->scriptProperty().stringLiteral().isEmpty());
+ QVERIFY(object->scriptProperty().numberLiteral(&ok) == 0.0 && !ok);
+ QVERIFY(!object->scriptProperty().booleanLiteral(&ok) && !ok);
+
+ func.callWithInstance(inst, QJSValueList() << true);
+ QCOMPARE(QQmlScriptStringPrivate::get(object->scriptProperty())->script, QString("true"));
+ QVERIFY(!object->scriptProperty().isEmpty());
+ QVERIFY(!object->scriptProperty().isUndefinedLiteral());
+ QVERIFY(!object->scriptProperty().isNullLiteral());
+ QVERIFY(object->scriptProperty().stringLiteral().isEmpty());
+ QVERIFY(object->scriptProperty().numberLiteral(&ok) == 0.0 && !ok);
+ QVERIFY(object->scriptProperty().booleanLiteral(&ok) && ok);
+
+ func.callWithInstance(inst, QJSValueList() << false);
+ QCOMPARE(QQmlScriptStringPrivate::get(object->scriptProperty())->script, QString("false"));
+ QVERIFY(!object->scriptProperty().isEmpty());
+ QVERIFY(!object->scriptProperty().isUndefinedLiteral());
+ QVERIFY(!object->scriptProperty().isNullLiteral());
+ QVERIFY(object->scriptProperty().stringLiteral().isEmpty());
+ QVERIFY(object->scriptProperty().numberLiteral(&ok) == 0.0 && !ok);
+ QVERIFY(!object->scriptProperty().booleanLiteral(&ok) && ok);
+
+ func.callWithInstance(inst, QJSValueList() << QJSValue::NullValue);
+ QCOMPARE(QQmlScriptStringPrivate::get(object->scriptProperty())->script, QString("null"));
+ QVERIFY(!object->scriptProperty().isEmpty());
+ QVERIFY(!object->scriptProperty().isUndefinedLiteral());
+ QVERIFY(object->scriptProperty().isNullLiteral());
+ QVERIFY(object->scriptProperty().stringLiteral().isEmpty());
+ QVERIFY(object->scriptProperty().numberLiteral(&ok) == 0.0 && !ok);
+ QVERIFY(!object->scriptProperty().booleanLiteral(&ok) && !ok);
+
+ func.callWithInstance(inst, QJSValueList() << 12.34);
+ QCOMPARE(QQmlScriptStringPrivate::get(object->scriptProperty())->script, QString("12.34"));
+ QVERIFY(!object->scriptProperty().isEmpty());
+ QVERIFY(!object->scriptProperty().isUndefinedLiteral());
+ QVERIFY(!object->scriptProperty().isNullLiteral());
+ QVERIFY(object->scriptProperty().stringLiteral().isEmpty());
+ QVERIFY(object->scriptProperty().numberLiteral(&ok) == 12.34 && ok);
+ QVERIFY(!object->scriptProperty().booleanLiteral(&ok) && !ok);
+}
+
void tst_qqmllanguage::scriptStringWithoutSourceCode()
{
QUrl url = testFileUrl("scriptString7.qml");