aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/compiler/qqmlcodegenerator.cpp6
-rw-r--r--src/qml/compiler/qv4codegen_p.h3
-rw-r--r--tests/auto/qml/qqmlecmascript/data/qtbug_34493.qml19
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp14
4 files changed, 41 insertions, 1 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp
index c2f2feb6bf..19264493be 100644
--- a/src/qml/compiler/qqmlcodegenerator.cpp
+++ b/src/qml/compiler/qqmlcodegenerator.cpp
@@ -1236,7 +1236,11 @@ QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QList<AST::N
Q_ASSERT(node != qmlRoot);
AST::FunctionDeclaration *function = AST::cast<AST::FunctionDeclaration*>(node);
- scan.enterEnvironment(node, function ? FunctionCode : QmlBinding);
+ if (function)
+ scan.enterQmlFunction(function);
+ else
+ scan.enterEnvironment(node, QmlBinding);
+
scan(function ? function->body : node);
scan.leaveEnvironment();
}
diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h
index b20db26467..0bac996349 100644
--- a/src/qml/compiler/qv4codegen_p.h
+++ b/src/qml/compiler/qv4codegen_p.h
@@ -476,6 +476,9 @@ protected:
void enterQmlScope(AST::Node *ast, const QString &name)
{ enterFunction(ast, name, /*formals*/0, /*body*/0, /*expr*/0, /*isExpression*/false); }
+ void enterQmlFunction(AST::FunctionDeclaration *ast)
+ { enterFunction(ast, false, false); }
+
protected:
using Visitor::visit;
using Visitor::endVisit;
diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_34493.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_34493.qml
new file mode 100644
index 0000000000..7e7d350aae
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/qtbug_34493.qml
@@ -0,0 +1,19 @@
+import Qt.test 1.0
+import QtQuick 2.0
+
+MyQmlObject {
+ function doIt() {
+ d.hello("World")
+ }
+
+ property QtObject subobject: QtObject {
+ id: d
+ function hello(input) {
+ var temp = "Hello " + input;
+ var input = temp + "!";
+ prop = input
+ }
+ }
+
+ property string prop
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 478611546e..defa708de5 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -309,6 +309,7 @@ private slots:
void qtbug_32801();
void thisObject();
void qtbug_33754();
+ void qtbug_34493();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -7330,6 +7331,19 @@ void tst_qqmlecmascript::qtbug_33754()
QVERIFY(obj != 0);
}
+void tst_qqmlecmascript::qtbug_34493()
+{
+ QQmlComponent component(&engine, testFileUrl("qtbug_34493.qml"));
+
+ QScopedPointer<QObject> obj(component.create());
+ if (component.errors().size())
+ qDebug() << component.errors();
+ QVERIFY(component.errors().isEmpty());
+ QVERIFY(obj != 0);
+ QVERIFY(QMetaObject::invokeMethod(obj.data(), "doIt"));
+ QTRY_VERIFY(obj->property("prop").toString() == QLatin1String("Hello World!"));
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"