History

Stop ScriptCache callbacks when scripts are stopped

Zach Pomerantz committed 10 years ago

Commit 107b1b81 parent 1c5e1bb2 files · +26 −19Browse files

Showing the changes to libraries/script-engine/src/ScriptCache.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptCache.cpp+25−18
@@ -9,6 +9,8 @@ · 8 unmodified lines
99 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
1010 //
1111
12+#include "ScriptCache.h"
13+
1214 #include <QCoreApplication>
1315 #include <QEventLoop>
1416 #include <QNetworkAccessManager>
@@ -20,7 +22,7 @@ · 5 unmodified lines
2022 #include <assert.h>
2123 #include <SharedUtil.h>
2224
23−#include "ScriptCache.h"
25+#include "ScriptEngines.h"
2426 #include "ScriptEngineLogging.h"
2527
2628 ScriptCache::ScriptCache(QObject* parent) {
@@ -78,22 +80,25 @@ void ScriptCache::scriptDownloaded() { · 51 unmodified lines
7880 QList<ScriptUser*> scriptUsers = _scriptUsers.values(url);
7981 _scriptUsers.remove(url);
8082
81− if (req->getResult() == ResourceRequest::Success) {
82− auto scriptContents = req->getData();
83− _scriptCache[url] = scriptContents;
84− lock.unlock();
85− qCDebug(scriptengine) << "Done downloading script at:" << url.toString();
83+ if (!DependencyManager::get<ScriptEngines>()->isStopped()) {
84+ if (req->getResult() == ResourceRequest::Success) {
85+ auto scriptContents = req->getData();
86+ _scriptCache[url] = scriptContents;
87+ lock.unlock();
88+ qCDebug(scriptengine) << "Done downloading script at:" << url.toString();
8689
87− foreach(ScriptUser* user, scriptUsers) {
88− user->scriptContentsAvailable(url, scriptContents);
89− }
90− } else {
91− lock.unlock();
92− qCWarning(scriptengine) << "Error loading script from URL " << url;
93− foreach(ScriptUser* user, scriptUsers) {
94− user->errorInLoadingScript(url);
90+ foreach(ScriptUser* user, scriptUsers) {
91+ user->scriptContentsAvailable(url, scriptContents);
92+ }
93+ } else {
94+ lock.unlock();
95+ qCWarning(scriptengine) << "Error loading script from URL " << url;
96+ foreach(ScriptUser* user, scriptUsers) {
97+ user->errorInLoadingScript(url);
98+ }
9599 }
96100 }
101+
97102 req->deleteLater();
98103 }
99104
@@ -162,9 +167,11 @@ void ScriptCache::scriptContentAvailable() { · 62 unmodified lines
162167 }
163168 }
164169
165− foreach(contentAvailableCallback thisCallback, allCallbacks) {
166− thisCallback(url.toString(), scriptContent, true, success);
167− }
168170 req->deleteLater();
169−}
170171
172+ if (!DependencyManager::get<ScriptEngines>()->isStopped()) {
173+ foreach(contentAvailableCallback thisCallback, allCallbacks) {
174+ thisCallback(url.toString(), scriptContent, true, success);
175+ }
176+ }
177+}