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
901 BatchLoader* loader = new BatchLoader(urls);901 BatchLoader* loader = new BatchLoader(urls);
902 902
903 auto evaluateScripts = [=](const QMap<QUrl, QString>& data) {903 auto evaluateScripts = [=](const QMap<QUrl, QString>& data) {
904 auto parentURL = _parentURL;
904 for (QUrl url : urls) {905 for (QUrl url : urls) {
905 QString contents = data[url];906 QString contents = data[url];
906 if (contents.isNull()) {907 if (contents.isNull()) {
907 qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__;908 qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__;
908 } else {909 } 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();
909 QScriptValue result = evaluate(contents, url.toString());913 QScriptValue result = evaluate(contents, url.toString());
910 }914 }
911 }915 }
916 _parentURL = parentURL;
912 917
913 if (callback.isFunction()) {918 if (callback.isFunction()) {
914 QScriptValue(callback).call();919 QScriptValue(callback).call();