qmltc: Do not crash on import namespaces
Pick-to: 6.3 Change-Id: I9767857076ea6ae565c7efd75d64cb47a82b7be7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
52f1e2070f
commit
790d257ef0
|
@ -21,6 +21,7 @@ set(qml_sources
|
|||
data/properties.qml
|
||||
data/ObjectWithId.qml
|
||||
data/documentWithIds.qml
|
||||
data/importNamespace.qml
|
||||
|
||||
data/signalHandlers.qml
|
||||
data/javaScriptFunctions.qml
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
import QtQuick as QQ
|
||||
QQ.Text {
|
||||
text: "hello, world"
|
||||
}
|
|
@ -37,6 +37,7 @@
|
|||
#include "properties.h"
|
||||
#include "objectwithid.h"
|
||||
#include "documentwithids.h"
|
||||
#include "importnamespace.h"
|
||||
|
||||
#include "signalhandlers.h"
|
||||
#include "javascriptfunctions.h"
|
||||
|
@ -133,6 +134,7 @@ void tst_qmltc::initTestCase()
|
|||
QUrl("qrc:/QmltcTests/data/properties.qml"),
|
||||
QUrl("qrc:/QmltcTests/data/ObjectWithId.qml"),
|
||||
QUrl("qrc:/QmltcTests/data/documentWithIds.qml"),
|
||||
QUrl("qrc:/QmltcTests/data/importNamespace.qml"),
|
||||
|
||||
QUrl("qrc:/QmltcTests/data/signalHandlers.qml"),
|
||||
QUrl("qrc:/QmltcTests/data/javaScriptFunctions.qml"),
|
||||
|
@ -529,6 +531,13 @@ void tst_qmltc::ids()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_qmltc::importNamespace()
|
||||
{
|
||||
QQmlEngine e;
|
||||
PREPEND_NAMESPACE(importNamespace) created(&e); // compilation of this type shouldn't crash
|
||||
QCOMPARE(created.text(), u"hello, world"_qs);
|
||||
}
|
||||
|
||||
void tst_qmltc::signalHandlers()
|
||||
{
|
||||
QQmlEngine e;
|
||||
|
|
|
@ -51,6 +51,7 @@ private slots:
|
|||
void methods();
|
||||
void properties();
|
||||
void ids();
|
||||
void importNamespace();
|
||||
|
||||
void signalHandlers();
|
||||
void jsFunctions();
|
||||
|
|
|
@ -49,10 +49,18 @@ public:
|
|||
QHash<QString, QQmlJSScope::ConstPtr> builtins = m_importer->builtinInternalNames();
|
||||
cppNames.reserve(builtins.size() + m_imports.size());
|
||||
const auto getInternalName = [](const QQmlJSScope::ConstPtr &t) {
|
||||
if (!t)
|
||||
return QString();
|
||||
return t->internalName();
|
||||
};
|
||||
std::transform(builtins.cbegin(), builtins.cend(), std::back_inserter(cppNames),
|
||||
getInternalName);
|
||||
|
||||
// builtins must be valid: all QQmlJSScopes are not nullptr and have
|
||||
// non-empty internal names. m_imports may have nullptrs, due to import
|
||||
// namespaces
|
||||
Q_ASSERT(std::find(cppNames.cbegin(), cppNames.cend(), QString()) == cppNames.cend());
|
||||
|
||||
std::transform(m_imports.cbegin(), m_imports.cend(), std::back_inserter(cppNames),
|
||||
getInternalName);
|
||||
return cppNames;
|
||||
|
|
Loading…
Reference in New Issue