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
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10//10//
11 11
12#include "ScriptCache.h"
13
12#include <QCoreApplication>14#include <QCoreApplication>
13#include <QEventLoop>15#include <QEventLoop>
14#include <QNetworkAccessManager>16#include <QNetworkAccessManager>
@@ -20,7 +22,7 @@ · 5 unmodified lines
20#include <assert.h>22#include <assert.h>
21#include <SharedUtil.h>23#include <SharedUtil.h>
22 24
23#include "ScriptCache.h"25#include "ScriptEngines.h"
24#include "ScriptEngineLogging.h"26#include "ScriptEngineLogging.h"
25 27
26ScriptCache::ScriptCache(QObject* parent) {28ScriptCache::ScriptCache(QObject* parent) {
@@ -78,22 +80,25 @@ void ScriptCache::scriptDownloaded() { · 51 unmodified lines
78 QList<ScriptUser*> scriptUsers = _scriptUsers.values(url);80 QList<ScriptUser*> scriptUsers = _scriptUsers.values(url);
79 _scriptUsers.remove(url);81 _scriptUsers.remove(url);
80 82
81 if (req->getResult() == ResourceRequest::Success) {83 if (!DependencyManager::get<ScriptEngines>()->isStopped()) {
82 auto scriptContents = req->getData();84 if (req->getResult() == ResourceRequest::Success) {
83 _scriptCache[url] = scriptContents;85 auto scriptContents = req->getData();
84 lock.unlock();86 _scriptCache[url] = scriptContents;
85 qCDebug(scriptengine) << "Done downloading script at:" << url.toString();87 lock.unlock();
88 qCDebug(scriptengine) << "Done downloading script at:" << url.toString();
86 89
87 foreach(ScriptUser* user, scriptUsers) {90 foreach(ScriptUser* user, scriptUsers) {
88 user->scriptContentsAvailable(url, scriptContents);91 user->scriptContentsAvailable(url, scriptContents);
89 }92 }
90 } else {93 } else {
91 lock.unlock();94 lock.unlock();
92 qCWarning(scriptengine) << "Error loading script from URL " << url;95 qCWarning(scriptengine) << "Error loading script from URL " << url;
93 foreach(ScriptUser* user, scriptUsers) {96 foreach(ScriptUser* user, scriptUsers) {
94 user->errorInLoadingScript(url);97 user->errorInLoadingScript(url);
98 }
95 }99 }
96 }100 }
101
97 req->deleteLater();102 req->deleteLater();
98}103}
99 104
@@ -162,9 +167,11 @@ void ScriptCache::scriptContentAvailable() { · 62 unmodified lines
162 }167 }
163 }168 }
164 169
165 foreach(contentAvailableCallback thisCallback, allCallbacks) {
166 thisCallback(url.toString(), scriptContent, true, success);
167 }
168 req->deleteLater();170 req->deleteLater();
169}
170 171
172 if (!DependencyManager::get<ScriptEngines>()->isStopped()) {
173 foreach(contentAvailableCallback thisCallback, allCallbacks) {
174 thisCallback(url.toString(), scriptContent, true, success);
175 }
176 }
177}