mirror of
https://github.com/overte-org/overte.git
synced 2025-07-06 15:49:54 +02:00
Merge pull request #9051 from sethalves/fix-include-race
block scripts until follow-on includes are finished but still avoid multiple evaluation of included urls
This commit is contained in:
commit
fe9e97346f
2 changed files with 23 additions and 20 deletions
|
@ -1188,7 +1188,6 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
||||||
thisURL = resolvePath(file);
|
thisURL = resolvePath(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_includedURLs.contains(thisURL)) {
|
|
||||||
if (!isStandardLibrary && !currentSandboxURL.isEmpty() && (thisURL.scheme() == "file") &&
|
if (!isStandardLibrary && !currentSandboxURL.isEmpty() && (thisURL.scheme() == "file") &&
|
||||||
(currentSandboxURL.scheme() != "file" ||
|
(currentSandboxURL.scheme() != "file" ||
|
||||||
!thisURL.toString(strippingFlags).startsWith(currentSandboxURL.toString(strippingFlags), getSensitivity()))) {
|
!thisURL.toString(strippingFlags).startsWith(currentSandboxURL.toString(strippingFlags), getSensitivity()))) {
|
||||||
|
@ -1198,10 +1197,6 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
||||||
// We could also check here for CORS, but we don't yet.
|
// We could also check here for CORS, but we don't yet.
|
||||||
// It turns out that QUrl.resolve will not change hosts and copy authority, so we don't need to check that here.
|
// It turns out that QUrl.resolve will not change hosts and copy authority, so we don't need to check that here.
|
||||||
urls.append(thisURL);
|
urls.append(thisURL);
|
||||||
_includedURLs << thisURL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qCDebug(scriptengine) << "Script.include() ignoring previously included url:" << thisURL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1221,13 +1216,20 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
||||||
if (contents.isNull()) {
|
if (contents.isNull()) {
|
||||||
qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__;
|
qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__;
|
||||||
} else {
|
} else {
|
||||||
|
std::lock_guard<std::recursive_mutex> lock(_lock);
|
||||||
|
if (!_includedURLs.contains(url)) {
|
||||||
|
_includedURLs << url;
|
||||||
// Set the parent url so that path resolution will be relative
|
// Set the parent url so that path resolution will be relative
|
||||||
// to this script's url during its initial evaluation
|
// to this script's url during its initial evaluation
|
||||||
_parentURL = url.toString();
|
_parentURL = url.toString();
|
||||||
auto operation = [&]() {
|
auto operation = [&]() {
|
||||||
evaluate(contents, url.toString());
|
evaluate(contents, url.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
doWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, operation);
|
doWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, operation);
|
||||||
|
} else {
|
||||||
|
qCDebug(scriptengine) << "Script.include() skipping evaluation of previously included url:" << url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_parentURL = parentURL;
|
_parentURL = parentURL;
|
||||||
|
|
|
@ -245,6 +245,7 @@ protected:
|
||||||
|
|
||||||
std::function<bool()> _emitScriptUpdates{ [](){ return true; } };
|
std::function<bool()> _emitScriptUpdates{ [](){ return true; } };
|
||||||
|
|
||||||
|
std::recursive_mutex _lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ScriptEngine_h
|
#endif // hifi_ScriptEngine_h
|
||||||
|
|
Loading…
Reference in a new issue