diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2012-01-06 12:16:24 +0000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-06 15:27:10 +0100 |
commit | 0888e4397e95c08d67814eb860d24d1791b876bd (patch) | |
tree | 818b3c97c9cc19e3318682f2236511d3827dc53e /src/declarative/qml/qdeclarativecompiler.cpp | |
parent | afbcb4fd4e3f22eac1b68fb9f44b8492c265d9f0 (diff) |
Improve QML error messages
Point at the actual property and method name when raising errors about
them.
Change-Id: Id36df4850b91ae0d225fcda4d101f4b2a073a72e
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Diffstat (limited to 'src/declarative/qml/qdeclarativecompiler.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativecompiler.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 1bd714bd17..3a7a6013e6 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -185,18 +185,20 @@ bool QDeclarativeCompiler::isSignalPropertyName(const QHashedStringRef &name) COMPILE_EXCEPTION(property, tr("Error for property \"%1\"").arg(property->name)); \endcode */ -#define COMPILE_EXCEPTION(token, desc) \ +#define COMPILE_EXCEPTION_LOCATION(line, column, desc) \ { \ - QString exceptionDescription; \ QDeclarativeError error; \ error.setUrl(output->url); \ - error.setLine((token)->location.start.line); \ - error.setColumn((token)->location.start.column); \ + error.setLine(line); \ + error.setColumn(column); \ error.setDescription(desc.trimmed()); \ exceptions << error; \ return false; \ } +#define COMPILE_EXCEPTION(token, desc) \ + COMPILE_EXCEPTION_LOCATION((token)->location.start.line, (token)->location.start.column, desc) + /*! \macro COMPILE_CHECK \internal @@ -2641,16 +2643,25 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeScript::Object *obj) if (propNames.testAndSet(prop.name.hash())) { for (Object::DynamicProperty *p2 = obj->dynamicProperties.first(); p2 != p; p2 = obj->dynamicProperties.next(p2)) { - if (p2->name == prop.name) - COMPILE_EXCEPTION(&prop, tr("Duplicate property name")); + if (p2->name == prop.name) { + COMPILE_EXCEPTION_LOCATION(prop.nameLocation.line, + prop.nameLocation.column, + tr("Duplicate property name")); + } } } - if (prop.name.at(0).isUpper()) - COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter")); + if (prop.name.at(0).isUpper()) { + COMPILE_EXCEPTION_LOCATION(prop.nameLocation.line, + prop.nameLocation.column, + tr("Property names cannot begin with an upper case letter")); + } - if (enginePrivate->v8engine()->illegalNames().contains(prop.name)) - COMPILE_EXCEPTION(&prop, tr("Illegal property name")); + if (enginePrivate->v8engine()->illegalNames().contains(prop.name)) { + COMPILE_EXCEPTION_LOCATION(prop.nameLocation.line, + prop.nameLocation.column, + tr("Illegal property name")); + } } for (Object::DynamicSignal *s = obj->dynamicSignals.first(); s; s = obj->dynamicSignals.next(s)) { |