Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -1096,7 +1096,7 @@ QUrl ScriptEngine::resolvePath(const QString& include) const { · 1095 unmodified lines | ||
| 1096 | 1096 | |
| 1097 | 1097 | // we apparently weren't a fully qualified url, so, let's assume we're relative |
| 1098 | 1098 | // to the original URL of our script |
| 1099 | − QUrl parentURL = contextInfo.fileName(); | |
| 1099 | + QUrl parentURL = extractUrlFromEntityUrl(contextInfo.fileName()); | |
| 1100 | 1100 | if (parentURL.isEmpty()) { |
| 1101 | 1101 | if (_parentURL.isEmpty()) { |
| 1102 | 1102 | parentURL = QUrl(_fileNameString); |
| @@ -1303,6 +1303,25 @@ void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const · 200 unmodified lines | ||
| 1303 | 1303 | }, forceRedownload); |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | +// The purpose of the following two function is to embed entity ids into entity script filenames | |
| 1307 | +// so that they show up in stacktraces | |
| 1308 | +// | |
| 1309 | +// Extract the url portion of a url that has been encoded with encodeEntityIdIntoEntityUrl(...) | |
| 1310 | +QString extractUrlFromEntityUrl(QString url) { | |
| 1311 | + auto parts = url.split(' ', QString::SkipEmptyParts); | |
| 1312 | + if (parts.length() > 0) { | |
| 1313 | + return parts[0]; | |
| 1314 | + } else { | |
| 1315 | + return ""; | |
| 1316 | + } | |
| 1317 | +} | |
| 1318 | + | |
| 1319 | +// Encode an entity id into an entity url | |
| 1320 | +// Example: http://www.example.com/some/path.js [EntityID:{9fdd355f-d226-4887-9484-44432d29520e}] | |
| 1321 | +QString encodeEntityIdIntoEntityUrl(QString url, QString entityID) { | |
| 1322 | + return url + " [EntityID:" + entityID + "]"; | |
| 1323 | +} | |
| 1324 | + | |
| 1306 | 1325 | // since all of these operations can be asynch we will always do the actual work in the response handler |
| 1307 | 1326 | // for the download |
| 1308 | 1327 | void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success) { |
| @@ -1329,7 +1348,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 20 unmodified lines | ||
| 1329 | 1348 | |
| 1330 | 1349 | auto scriptCache = DependencyManager::get<ScriptCache>(); |
| 1331 | 1350 | bool isFileUrl = isURL && scriptOrURL.startsWith("file://"); |
| 1332 | − auto fileName = isURL ? scriptOrURL : "EmbeddedEntityScript"; | |
| 1351 | + auto fileName = isURL ? encodeEntityIdIntoEntityUrl(scriptOrURL, entityID) : "EmbeddedEntityScript"; | |
| 1333 | 1352 | |
| 1334 | 1353 | QScriptProgram program(contents, fileName); |
| 1335 | 1354 | if (!hasCorrectSyntax(program)) { |