From bf47d66216e649fe947956e02edd0a4b24ddb0fe Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 26 Feb 2014 10:26:51 +0100 Subject: [new compiler] Fix evaluateEnum for custom parsers When storing the string for a script binding - next to to the AST node - then for expression statements skip the (potentially synthetically inserted) semicolon. Its omission is required for the use of QQmlCustomParser::evaluateEnum. Change-Id: I3b556fd6a884f5c9c290d7d793eeab4dd135343e Reviewed-by: Lars Knoll --- tests/auto/qml/qqmllanguage/testtypes.cpp | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'tests/auto/qml/qqmllanguage/testtypes.cpp') diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp index 98a803a594..b18e6133cb 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.cpp +++ b/tests/auto/qml/qqmllanguage/testtypes.cpp @@ -68,6 +68,7 @@ void registerTypes() qmlRegisterType("Test",1,0,"MySubclass"); qmlRegisterCustomType("Test", 1, 0, "MyCustomParserType", new MyCustomParserTypeParser); + qmlRegisterCustomType("Test", 1, 0, "MyCustomParserWithEnumType", new EnumSupportingCustomParser); qmlRegisterTypeNotAvailable("Test",1,0,"UnavailableType", "UnavailableType is unavailable for testing"); @@ -177,3 +178,80 @@ void CustomBinding::componentComplete() QQmlPropertyPrivate::setBinding(property, binding); } } + + +QByteArray EnumSupportingCustomParser::compile(const QList &props) +{ + if (props.count() != 1) { + error(QStringLiteral("Custom parser invoked incorrectly for unit test")); + return QByteArray(); + } + QQmlCustomParserProperty prop = props.first(); + if (prop.name() != QStringLiteral("foo")) { + error(QStringLiteral("Custom parser invoked with the wrong property name")); + return QByteArray(); + } + + if (prop.assignedValues().count() != 1) { + error(QStringLiteral("Custom parser invoked with the wrong property values. Expected only one.")); + return QByteArray(); + } + + QVariant firstValue = prop.assignedValues().first(); + if (firstValue.userType() != qMetaTypeId()) { + error(QStringLiteral("Custom parser invoked with the wrong property value. Expected value instead of object or so")); + return QByteArray(); + } + QQmlScript::Variant value = qvariant_cast(firstValue); + if (!value.isScript()) { + error(QStringLiteral("Custom parser invoked with the wrong property value. Expected script that evaluates to enum")); + return QByteArray(); + } + QByteArray script = value.asScript().toUtf8(); + bool ok; + int v = evaluateEnum(script, &ok); + if (!ok) { + error(QStringLiteral("Custom parser invoked with the wrong property value. Script did not evaluate to enum")); + return QByteArray(); + } + if (v != MyEnum1Class::A_13) { + error(QStringLiteral("Custom parser invoked with the wrong property value. Enum value is not the expected value.")); + return QByteArray(); + } + + return QByteArray(); +} + +QByteArray EnumSupportingCustomParser::compile(const QV4::CompiledData::QmlUnit *qmlUnit, const QList &bindings) +{ + Q_UNUSED(qmlUnit) + + if (bindings.count() != 1) { + error(bindings.first(), QStringLiteral("Custom parser invoked incorrectly for unit test")); + return QByteArray(); + } + + const QV4::CompiledData::Binding *binding = bindings.first(); + if (qmlUnit->header.stringAt(binding->propertyNameIndex) != QStringLiteral("foo")) { + error(binding, QStringLiteral("Custom parser invoked with the wrong property name")); + return QByteArray(); + } + + if (binding->type != QV4::CompiledData::Binding::Type_Script) { + error(binding, QStringLiteral("Custom parser invoked with the wrong property value. Expected script that evaluates to enum")); + return QByteArray(); + } + QByteArray script = qmlUnit->header.stringAt(binding->stringIndex).toUtf8(); + bool ok; + int v = evaluateEnum(script, &ok); + if (!ok) { + error(binding, QStringLiteral("Custom parser invoked with the wrong property value. Script did not evaluate to enum")); + return QByteArray(); + } + if (v != MyEnum1Class::A_13) { + error(binding, QStringLiteral("Custom parser invoked with the wrong property value. Enum value is not the expected value.")); + return QByteArray(); + } + + return QByteArray(); +} -- cgit v1.2.3