aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsengine
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-02-01 16:26:42 +0100
committerUlf Hermann <ulf.hermann@qt.io>2022-02-02 09:27:21 +0100
commiteeec9f03e9cf57e8cde311897f7e3e62a217da15 (patch)
tree50b4067f7c11759a98981ca6d9624ee59458ac9d /tests/auto/qml/qjsengine
parent9052e09a21fd77c44127f9c75dc8aff8ae60184d (diff)
JavaScript: Make "this" available in blocks inside arrow functions
Fixes: QTBUG-98039 Pick-to: 6.2 6.3 Change-Id: I51ff36994fa0f3f3568c8114cb6841f677f64bc4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qjsengine')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index b08a638fd7..a92141a1e5 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -279,6 +279,7 @@ private slots:
void uiLanguage();
void urlObject();
+ void thisInConstructor();
public:
Q_INVOKABLE QJSValue throwingCppMethod1();
@@ -5473,6 +5474,27 @@ void tst_QJSEngine::urlObject()
QCOMPARE(result2, url);
}
+void tst_QJSEngine::thisInConstructor()
+{
+ QJSEngine engine;
+ const QJSValue result = engine.evaluate(R"((function() {
+ let a = undefined;
+ class Bugtest {
+ constructor() {
+ (() => {
+ if (true) {
+ a = this;
+ }
+ })();
+ }
+ };
+ new Bugtest();
+ return a;
+ })())");
+ QVERIFY(!result.isUndefined());
+ QVERIFY(result.isObject());
+}
+
QTEST_MAIN(tst_QJSEngine)
#include "tst_qjsengine.moc"