History

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.

Ryan Huffman committed 11 years ago

Commit b8357111 parent 4b684c01 file · +5 −0Browse 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+5−0
@@ -901,14 +901,19 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 900 unmodified lines
901901 BatchLoader* loader = new BatchLoader(urls);
902902
903903 auto evaluateScripts = [=](const QMap<QUrl, QString>& data) {
904+ auto parentURL = _parentURL;
904905 for (QUrl url : urls) {
905906 QString contents = data[url];
906907 if (contents.isNull()) {
907908 qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__;
908909 } else {
910+ // Set the parent url so that path resolution will be relative
911+ // to this script's url during its initial evaluation
912+ _parentURL = url.toString();
909913 QScriptValue result = evaluate(contents, url.toString());
910914 }
911915 }
916+ _parentURL = parentURL;
912917
913918 if (callback.isFunction()) {
914919 QScriptValue(callback).call();