History

block until follow-on includes are finished but still avoid multiple evaluation of included urls

Seth Alves committed 10 years ago

Commit aef39ce1 parent 5b91c8f1 file · +11 −14Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+11−14
@@ -1187,20 +1187,15 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 1186 unmodified lines
11871187 thisURL = resolvePath(file);
11881188 }
11891189
1190− if (!_includedURLs.contains(thisURL)) {
1191− if (!isStandardLibrary && !currentSandboxURL.isEmpty() && (thisURL.scheme() == "file") &&
1192− (currentSandboxURL.scheme() != "file" ||
1193− !thisURL.toString(strippingFlags).startsWith(currentSandboxURL.toString(strippingFlags), getSensitivity()))) {
1194− qCWarning(scriptengine) << "Script.include() ignoring file path"
1195− << thisURL << "outside of original entity script" << currentSandboxURL;
1196− } else {
1197− // We could also check here for CORS, but we don't yet.
1198− // It turns out that QUrl.resolve will not change hosts and copy authority, so we don't need to check that here.
1199− urls.append(thisURL);
1200− _includedURLs << thisURL;
1201− }
1190+ if (!isStandardLibrary && !currentSandboxURL.isEmpty() && (thisURL.scheme() == "file") &&
1191+ (currentSandboxURL.scheme() != "file" ||
1192+ !thisURL.toString(strippingFlags).startsWith(currentSandboxURL.toString(strippingFlags), getSensitivity()))) {
1193+ qCWarning(scriptengine) << "Script.include() ignoring file path"
1194+ << thisURL << "outside of original entity script" << currentSandboxURL;
12021195 } else {
1203− qCDebug(scriptengine) << "Script.include() ignoring previously included url:" << thisURL;
1196+ // We could also check here for CORS, but we don't yet.
1197+ // It turns out that QUrl.resolve will not change hosts and copy authority, so we don't need to check that here.
1198+ urls.append(thisURL);
12041199 }
12051200 }
12061201
@@ -1219,13 +1214,15 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 12 unmodified lines
12191214 QString contents = data[url];
12201215 if (contents.isNull()) {
12211216 qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__;
1222− } else {
1217+ } else if (!_includedURLs.contains(url)) {
1218+ _includedURLs << url;
12231219 // Set the parent url so that path resolution will be relative
12241220 // to this script's url during its initial evaluation
12251221 _parentURL = url.toString();
12261222 auto operation = [&]() {
12271223 evaluate(contents, url.toString());
12281224 };
1225+
12291226 doWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, operation);
12301227 }
12311228 }