diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-23 10:51:25 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-24 12:11:39 +0200 |
commit | 31be482e740a6aec1243eb7ba3d865b9d4050641 (patch) | |
tree | c33076717672c9418ba18a26f7ebd3ca15289311 | |
parent | fbc463e84d5cc6012953140c93f6b18f78e66bf8 (diff) |
QML: Consistently check for debugger before loading cache files
In debug mode we don't want to load cache files.
Fixes: QTBUG-79443
Change-Id: Ie3e2c70d54e66f24846070aee952a86934099695
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qml/qml/qqmlscriptblob.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmltypedata.cpp | 8 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 9 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 4 | ||||
-rw-r--r-- | tests/auto/qml/debugger/qqmldebugjs/data/quit.js | 4 | ||||
-rw-r--r-- | tests/auto/qml/debugger/qqmldebugjs/data/quitInJS.qml | 41 | ||||
-rw-r--r-- | tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp | 48 |
7 files changed, 99 insertions, 19 deletions
diff --git a/src/qml/qml/qqmlscriptblob.cpp b/src/qml/qml/qqmlscriptblob.cpp index 6ac30d3ab5..eb103dc434 100644 --- a/src/qml/qml/qqmlscriptblob.cpp +++ b/src/qml/qml/qqmlscriptblob.cpp @@ -68,7 +68,7 @@ QQmlRefPointer<QQmlScriptData> QQmlScriptBlob::scriptData() const void QQmlScriptBlob::dataReceived(const SourceCodeData &data) { - if (!diskCacheDisabled() || diskCacheForced()) { + if (diskCacheEnabled()) { QQmlRefPointer<QV4::ExecutableCompilationUnit> unit = QV4::ExecutableCompilationUnit::create(); QString error; @@ -132,7 +132,7 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data) auto executableUnit = QV4::ExecutableCompilationUnit::create(std::move(unit)); - if ((!diskCacheDisabled() || diskCacheForced()) && !isDebugging()) { + if (diskCacheEnabled()) { QString errorString; if (executableUnit->saveToDisk(url(), &errorString)) { QString error; diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp index cfdcf6aad5..0fd5bc83e6 100644 --- a/src/qml/qml/qqmltypedata.cpp +++ b/src/qml/qml/qqmltypedata.cpp @@ -107,10 +107,7 @@ void QQmlTypeData::unregisterCallback(TypeDataCallback *callback) bool QQmlTypeData::tryLoadFromDiskCache() { - if (diskCacheDisabled() && !diskCacheForced()) - return false; - - if (isDebugging()) + if (!diskCacheEnabled()) return false; QV4::ExecutionEngine *v4 = typeLoader()->engine()->handle(); @@ -621,8 +618,7 @@ void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCach return; } - const bool trySaveToDisk = (!diskCacheDisabled() || diskCacheForced()) - && !m_document->jsModule.debugMode && !typeRecompilation; + const bool trySaveToDisk = diskCacheEnabled() && !typeRecompilation; if (trySaveToDisk) { QString errorString; if (m_compiledData->saveToDisk(url(), &errorString)) { diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 62007effdd..c6c3ee5523 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -703,14 +703,9 @@ bool QQmlTypeLoader::Blob::isDebugging() const return typeLoader()->engine()->handle()->debugger() != nullptr; } -bool QQmlTypeLoader::Blob::diskCacheDisabled() +bool QQmlTypeLoader::Blob::diskCacheEnabled() const { - return disableDiskCache(); -} - -bool QQmlTypeLoader::Blob::diskCacheForced() -{ - return forceDiskCache(); + return (!disableDiskCache() || forceDiskCache()) && !isDebugging(); } bool QQmlTypeLoader::Blob::qmldirDataAvailable(const QQmlRefPointer<QQmlQmldirData> &data, QList<QQmlError> *errors) diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 612d6777ed..38a7e05961 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -128,9 +128,7 @@ public: virtual QString stringAt(int) const { return QString(); } bool isDebugging() const; - - static bool diskCacheDisabled(); - static bool diskCacheForced(); + bool diskCacheEnabled() const; QQmlImports m_importCache; QVector<PendingImportPtr> m_unresolvedImports; diff --git a/tests/auto/qml/debugger/qqmldebugjs/data/quit.js b/tests/auto/qml/debugger/qqmldebugjs/data/quit.js new file mode 100644 index 0000000000..1a45fd5538 --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebugjs/data/quit.js @@ -0,0 +1,4 @@ +function quit() { + console.log("hit"); + Qt.quit(); +} diff --git a/tests/auto/qml/debugger/qqmldebugjs/data/quitInJS.qml b/tests/auto/qml/debugger/qqmldebugjs/data/quitInJS.qml new file mode 100644 index 0000000000..6e4183100b --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebugjs/data/quitInJS.qml @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "quit.js" as Quit; + +//DO NOT CHANGE + +Item { + Timer { + running: true + triggeredOnStart: true + onTriggered: Quit.quit(); + } +} + diff --git a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp index 255d679b1b..5b6c43bc0c 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp +++ b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp @@ -58,6 +58,8 @@ const char *ONCOMPLETED_QMLFILE = "oncompleted.qml"; const char *CREATECOMPONENT_QMLFILE = "createComponent.qml"; const char *CONDITION_QMLFILE = "condition.qml"; const char *QUIT_QMLFILE = "quit.qml"; +const char *QUITINJS_QMLFILE = "quitInJS.qml"; +const char *QUIT_JSFILE = "quit.js"; const char *CHANGEBREAKPOINT_QMLFILE = "changeBreakpoint.qml"; const char *STEPACTION_QMLFILE = "stepAction.qml"; const char *BREAKPOINTRELOCATION_QMLFILE = "breakpointRelocation.qml"; @@ -109,8 +111,10 @@ private slots: void setBreakpointInScriptOnOptimizedBinding(); void setBreakpointInScriptWithCondition_data() { targetData(); } void setBreakpointInScriptWithCondition(); - void setBreakpointInScriptThatQuits_data() { targetData(); } + void setBreakpointInScriptThatQuits_data() { targetData(); }; void setBreakpointInScriptThatQuits(); + void setBreakpointInJavaScript_data(); + void setBreakpointInJavaScript(); void setBreakpointWhenAttaching(); void clearBreakpoint_data() { targetData(); } @@ -450,6 +454,48 @@ void tst_QQmlDebugJS::setBreakpointInScriptThatQuits() QCOMPARE(m_process->exitStatus(), QProcess::NormalExit); } +void tst_QQmlDebugJS::setBreakpointInJavaScript_data() +{ + QTest::addColumn<bool>("qmlscene"); + QTest::addColumn<bool>("seedCache"); + QTest::newRow("custom / immediate") << false << false; + QTest::newRow("qmlscene / immediate") << true << false; + QTest::newRow("custom / seeded") << false << true; + QTest::newRow("qmlscene / seeded") << true << true; +} + +void tst_QQmlDebugJS::setBreakpointInJavaScript() +{ + QFETCH(bool, qmlscene); + QFETCH(bool, seedCache); + + if (seedCache) { // Make sure there is a qmlc file that the engine should _not_ laod. + QProcess process; + process.start(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", + { testFile(QUITINJS_QMLFILE) }); + QTRY_COMPARE(process.state(), QProcess::NotRunning); + } + + QCOMPARE(init(qmlscene, QUITINJS_QMLFILE), ConnectSuccess); + + const int sourceLine = 2; + + m_client->setBreakpoint(QLatin1String(QUIT_JSFILE), sourceLine, -1, true); + m_client->connect(); + QVERIFY(waitForClientSignal(SIGNAL(stopped()))); + + const QJsonObject body = m_client->response().body.toObject(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine); + QCOMPARE(QFileInfo(body.value("script").toObject().value("name").toString()).fileName(), + QLatin1String(QUIT_JSFILE)); + + m_client->continueDebugging(QV4DebugClient::Continue); + + QVERIFY(m_process->waitForFinished()); + QCOMPARE(m_process->exitStatus(), QProcess::NormalExit); +} + void tst_QQmlDebugJS::setBreakpointWhenAttaching() { int sourceLine = 35; |