summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2018-02-06 09:33:54 +0100
committerEike Ziller <eike.ziller@qt.io>2018-02-06 09:16:46 +0000
commit3f87c4685e3d93522e8cad11a725dd193156d20d (patch)
treef4a51aefed465993ccff7d7f6382c2cb916aac25
parent6ca1d2bfa4c3880a90b28b96924e49b6f25acb9c (diff)
Fix crash in timeout of JavaScript locator filterv4.6.0-beta1
The timeout code may not access thread local state, because if it fires on the main thread after the thread already finished, that state is gone. Change-Id: I3b9b432515ff6f0c46c46b1904bdd622a19960d2 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/plugins/coreplugin/locator/javascriptfilter.cpp20
-rw-r--r--src/plugins/coreplugin/locator/javascriptfilter.h4
2 files changed, 14 insertions, 10 deletions
diff --git a/src/plugins/coreplugin/locator/javascriptfilter.cpp b/src/plugins/coreplugin/locator/javascriptfilter.cpp
index a4c20e7a7e..6f88a9188a 100644
--- a/src/plugins/coreplugin/locator/javascriptfilter.cpp
+++ b/src/plugins/coreplugin/locator/javascriptfilter.cpp
@@ -28,7 +28,6 @@
#include <QClipboard>
#include <QGuiApplication>
#include <QScriptEngine>
-#include <QTimer>
namespace Core {
namespace Internal {
@@ -45,6 +44,13 @@ JavaScriptFilter::JavaScriptFilter()
setDisplayName(tr("Evaluate JavaScript"));
setIncludedByDefault(false);
setShortcutString("=");
+ m_abortTimer.setSingleShot(true);
+ m_abortTimer.setInterval(1000);
+ connect(&m_abortTimer, &QTimer::timeout, this, [this] {
+ m_aborted = true;
+ if (m_engine && m_engine->isEvaluating())
+ m_engine->abortEvaluation();
+ });
}
JavaScriptFilter::~JavaScriptFilter()
@@ -57,6 +63,8 @@ void JavaScriptFilter::prepareSearch(const QString &entry)
if (!m_engine)
setupEngine();
+ m_aborted = false;
+ m_abortTimer.start();
}
QList<LocatorFilterEntry> JavaScriptFilter::matchesFor(
@@ -68,16 +76,8 @@ QList<LocatorFilterEntry> JavaScriptFilter::matchesFor(
if (entry.trimmed().isEmpty()) {
entries.append({this, tr("Reset Engine"), QVariant(ResetEngine, nullptr)});
} else {
- bool aborted = false;
-
- QTimer::singleShot(1000, this, [this, &aborted]() {
- m_engine->abortEvaluation();
- aborted = true;
- });
-
const QString result = m_engine->evaluate(entry).toString();
-
- if (aborted) {
+ if (m_aborted) {
const QString message = entry + " = " + tr("Engine aborted after timeout.");
entries.append({this, message, QVariant(AbortEngine, nullptr)});
} else {
diff --git a/src/plugins/coreplugin/locator/javascriptfilter.h b/src/plugins/coreplugin/locator/javascriptfilter.h
index 025ce2fa6a..feaf326036 100644
--- a/src/plugins/coreplugin/locator/javascriptfilter.h
+++ b/src/plugins/coreplugin/locator/javascriptfilter.h
@@ -27,6 +27,8 @@
#include <coreplugin/locator/ilocatorfilter.h>
+#include <QTimer>
+
#include <memory>
QT_BEGIN_NAMESPACE
@@ -54,6 +56,8 @@ private:
void setupEngine();
mutable std::unique_ptr<QScriptEngine> m_engine;
+ QTimer m_abortTimer;
+ bool m_aborted = false;
};
} // namespace Internal