Update script engine path resolution behavior

The path resolution will now be relative to the script currently
being evaluated *on its initial evaluation.* The previous behavior
was that all paths would be resolved relative to the root script
for client scripts, and inconsistent for entity scripts depending
on the order that scripts were loaded. The entity script situation
was particularly bad because including more than 1 level deep produced
inconsistent results.
This commit is contained in:
Ryan Huffman 2015-11-09 12:04:17 -08:00
parent 4b684c0e63
commit b835711266

View file

@ -901,14 +901,19 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
BatchLoader* loader = new BatchLoader(urls);
auto evaluateScripts = [=](const QMap<QUrl, QString>& data) {
auto parentURL = _parentURL;
for (QUrl url : urls) {
QString contents = data[url];
if (contents.isNull()) {
qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__;
} else {
// Set the parent url so that path resolution will be relative
// to this script's url during its initial evaluation
_parentURL = url.toString();
QScriptValue result = evaluate(contents, url.toString());
}
}
_parentURL = parentURL;
if (callback.isFunction()) {
QScriptValue(callback).call();