Update script engine path resolution behavior to behave consistently
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 16 files). Show all
Unified · Split
| @@ -902,14 +902,19 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 901 unmodified lines | ||
| 902 | 902 | BatchLoader* loader = new BatchLoader(urls); |
| 903 | 903 | |
| 904 | 904 | auto evaluateScripts = [=](const QMap<QUrl, QString>& data) { |
| 905 | + auto parentURL = _parentURL; | |
| 905 | 906 | for (QUrl url : urls) { |
| 906 | 907 | QString contents = data[url]; |
| 907 | 908 | if (contents.isNull()) { |
| 908 | 909 | qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__; |
| 909 | 910 | } else { |
| 911 | + // Set the parent url so that path resolution will be relative | |
| 912 | + // to this script's url during its initial evaluation | |
| 913 | + _parentURL = url.toString(); | |
| 910 | 914 | QScriptValue result = evaluate(contents, url.toString()); |
| 911 | 915 | } |
| 912 | 916 | } |
| 917 | + _parentURL = parentURL; | |
| 913 | 918 | |
| 914 | 919 | if (callback.isFunction()) { |
| 915 | 920 | QScriptValue(callback).call(); |