From 32b7e01558e0d3c50dd10f846182fe5dc09686e9 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 6 Dec 2013 11:29:43 +0100 Subject: Clean up handling of illegal names and enable in new compiler Access to the identifier hash may not be thread-safe from the loader thread, so use a QSet copy instead (which is cheap because we don't detach). This also enables the checking for illegal types again. Change-Id: I8c3ec1fd0fc01cce3269e206f479a90bdbbc89dd Reviewed-by: Lars Knoll --- src/qml/compiler/qqmlcodegenerator.cpp | 35 +++++++++++++--------------------- src/qml/compiler/qqmlcodegenerator_p.h | 4 +++- 2 files changed, 16 insertions(+), 23 deletions(-) (limited to 'src/qml/compiler') diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index 13b23fde68..9d8f16da8e 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -82,8 +82,9 @@ QStringList Signal::parameterStringList(const QStringList &stringPool) const return result; } -QQmlCodeGenerator::QQmlCodeGenerator() - : _object(0) +QQmlCodeGenerator::QQmlCodeGenerator(const QSet &illegalNames) + : illegalNames(illegalNames) + , _object(0) , jsGenerator(0) { } @@ -292,10 +293,8 @@ bool QQmlCodeGenerator::sanityCheckFunctionNames() if (name.at(0).isUpper()) COMPILE_EXCEPTION(function->identifierToken, tr("Method names cannot begin with an upper case letter")); -#if 0 // ### - if (enginePrivate->v8engine()->illegalNames().contains(currSlot.name.toString())) - COMPILE_EXCEPTION(&currSlot, tr("Illegal method name")); -#endif + if (illegalNames.contains(name)) + COMPILE_EXCEPTION(function->identifierToken, tr("Illegal method name")); } return true; } @@ -589,10 +588,8 @@ bool QQmlCodeGenerator::visit(AST::UiPublicMember *node) if (signalName.at(0).isUpper()) COMPILE_EXCEPTION(node->identifierToken, tr("Signal names cannot begin with an upper case letter")); -#if 0 // ### cannot access identifier table from separate thread - if (enginePrivate->v8engine()->illegalNames().contains(currSig.name.toString())) - COMPILE_EXCEPTION(&currSig, tr("Illegal signal name")); -#endif + if (illegalNames.contains(signalName)) + COMPILE_EXCEPTION(node->identifierToken, tr("Illegal signal name")); _object->qmlSignals->append(signal); } else { @@ -926,12 +923,11 @@ bool QQmlCodeGenerator::setId(AST::Statement *value) COMPILE_EXCEPTION(loc, tr( "IDs must contain only letters, numbers, and underscores")); } -#if 0 // ### - if (enginePrivate->v8engine()->illegalNames().contains(str)) - COMPILE_EXCEPTION(v, tr( "ID illegally masks global JavaScript property")); -#endif + QString idQString(str.toString()); + if (illegalNames.contains(idQString)) + COMPILE_EXCEPTION(loc, tr( "ID illegally masks global JavaScript property")); - _object->idIndex = registerString(str.toString()); + _object->idIndex = registerString(idQString); _object->locationOfIdProperty.line = loc.startLine; _object->locationOfIdProperty.column = loc.startColumn; @@ -987,13 +983,8 @@ bool QQmlCodeGenerator::sanityCheckPropertyName(const AST::SourceLocation &nameL if (name.at(0).isUpper()) COMPILE_EXCEPTION(nameLocation, tr("Property names cannot begin with an upper case letter")); -#if 0 // ### how to check against illegalNames when in separate thread? - if (enginePrivate->v8engine()->illegalNames().contains(prop.name.toString())) { - COMPILE_EXCEPTION_LOCATION(prop.nameLocation.line, - prop.nameLocation.column, - tr("Illegal property name")); - } -#endif + if (illegalNames.contains(name)) + COMPILE_EXCEPTION(nameLocation, tr("Illegal property name")); return true; } diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 0a0e4f2d5b..83ff716176 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -207,7 +207,7 @@ struct Q_QML_EXPORT QQmlCodeGenerator : public AST::Visitor { Q_DECLARE_TR_FUNCTIONS(QQmlCodeGenerator) public: - QQmlCodeGenerator(); + QQmlCodeGenerator(const QSet &illegalNames); bool generateFromQml(const QString &code, const QUrl &url, const QString &urlString, ParsedQML *output); static bool isSignalPropertyName(const QString &name); @@ -280,6 +280,8 @@ public: QList errors; + QSet illegalNames; + QList _imports; QList _pragmas; QList _objects; -- cgit v1.2.3